up: MULTIDICT     index Zimbu documentation

CLASS T.multiDict<Tkey, Titem> @public

summary

     

The builtin type multiDict.

MultiDicts keep a list of items for each key that is present. It's like a dict where each value is a list.

The key type must support the ToString() method. It is used for error messages.

The item type must support the Equal() method. This is needed for the has(key, item) method.

The item type should support the ToString() method. When missing the string "-object-" is used instead of the actual value.

Example:

 multiDict<string, int> md = NEW()
 md.add("yes", 1)
 md.add("yes", 2)
 IO.WriteLine("multiDict has yes: " .. md.has("yes"))
 IO.WriteLine("multiDict has yes " .. md.get("yes").Size() .. " times")
 md.remove("yes")

Optionally the multiDict can use a list to remember the order in which keys were added. ToString(), keys() and values() will have the keys in the order they were added. This has a small overhead. Without the list the order of keys depends on the hash value, which is rather arbitrary. The values for a key are always kept in the order they were added.

NEW() @public  Create a new empty multiDict.
NEW(ordered) @public  Create a new empty multiDict.
NEW(items) @public  Create a new multiDict from a dictionary.
NEW(items, ordered) @public  Create a new multiDict from a dictionary.
NEW(items) @public  Create a new multiDict from a list of dicts.
NEW(items, ordered) @public  Create a new multiDict from a list of dicts.
$Size() int @public  Return the number of items in the multiDict.
$isOrdered() bool @public  Return whether the order in which keys are added is remembered.
$count(key) int @public  Return the number of items in the multiDict with key key.
$copy() MultiDict<Tkey, Titem> @public  Return a copy of the multiDict.
$get(key) list<Titem> @public  Return the list of entries for key key.
$get(key, default) list<Titem> @public  Return the list of entries for key key.
$ToString() string @public  Return a string representation of the multiDict.
$has(key) bool @public  Check if any item with key key is present in the multiDict.
$has(key, item) bool @public  Check if item with key key and value item is present in the multiDict.
$keys() list<Tkey> @public  Return a list with all the keys.
$values() list<list<Titem>> @public  Return a list with all the lists of values.
$add(key, item) MultiDict<Tkey, Titem> @public  Add an item to the multiDict.
$addDict(items) MultiDict<Tkey, Titem> @public  Add items from a dictionary.
$addList(key, itemList) MultiDict<Tkey, Titem> @public  Add a list of items to the multiDict.
$insert(key, item) MultiDict<Tkey, Titem> @public  Add an item to the multiDict.
$addList(items) MultiDict<Tkey, Titem> @public  Add all the items in a list of dicts to the multiDict.
$set(key, items) MultiDict<Tkey, Titem> @public  Add an item to the multiDict if not yet present.
$removeAll(key) MultiDict<Tkey, Titem> @public  Remove a list of items from the multiDict with key key.
$remove(key, item) MultiDict<Tkey, Titem> @public  Remove an item from the multiDict with key key and value equal to item
$clear(key) MultiDict<Tkey, Titem> @public  Remove an item from the multiDict if present.
$clear() MultiDict<Tkey, Titem> @public  Make the multiDict empty.
$map(f) multiDict<Tkey, Titem> @public  Execute function f on each item value. Each value is replaced by the result of the function.
$mapList(f) multiDict<Tkey, Titem> @public  Execute function f on the value list for each key. Each list is replaced by the result of the function.
$keyMap(f) multiDict<Tkey, Titem> @public  Execute function f on each item key and each value. Each item value is replaced by the result of the function.
$keyMapList(f) multiDict<Tkey, Titem> @public  Execute function f on each item key and value list. Each value list is replaced by the result of the function.
$mapTo<Tresult>(f) multiDict<Tkey, Tresult> @public  Create a new multiDict where each item is the result of executing function f on each item value of this multiDict.
$mapListTo<Tresult>(f) multiDict<Tkey, Tresult> @public  Create a new multiDict where each item list is the result of executing function f on each item list of this multiDict.
$keyMapTo<Tresult>(f) multiDict<Tkey, Tresult> @public  Create a new multiDict where each item is the result of executing function f on each item key and value of this multiDict.
$keyMapListTo<Tresult>(f) multiDict<Tkey, Tresult> @public  Create a new multiDict where each value list is the result of executing function f on each item key and value list of this multiDict.
$forEach(f) multiDict<Tkey, Titem> @public  Call method f for every item value in the multiDict.
$forEachList(f) multiDict<Tkey, Titem> @public  Call method f for every key in the multiDict, passing the list of values.
$forKeyEach(f) multiDict<Tkey, Titem> @public  Call method f for every item key and value in the multiDict.
$forKeyEachList(f) multiDict<Tkey, Titem> @public  Call method f for every key the multiDict, passing the list of values.
 

members (alphabetically)

     

PROC NEW() @public

     

Create a new empty multiDict.

PROC NEW(bool ordered) @public

     

Create a new empty multiDict.

When ordered is TRUE remember the order in which keys were added.

PROC NEW(dict<Tkey, list<Titem>> items) @public

     

Create a new multiDict from a dictionary.

This makes a copy of the argument.

When items is ordered then the multiDict will also be ordered.

PROC NEW(dict<Tkey, list<Titem>> items, bool ordered) @public

     

Create a new multiDict from a dictionary.

This makes a copy of the argument. When ordered is TRUE remember the order in which keys were added.

PROC NEW(list<dict<Tkey, Titem>> items) @public

     

Create a new multiDict from a list of dicts.

PROC NEW(list<dict<Tkey, Titem>> items, bool ordered) @public

     

Create a new multiDict from a list of dicts.

When ordered is TRUE remember the order in which keys were added.

FUNC $Size() int @public

     

Return the number of items in the multiDict.

FUNC $ToString() string @public

     

Return a string representation of the multiDict.

Looks like a list of the keys: [key1: [val1, val2], key2: [val3]]

The order of items is unpredictable, unless this is an ordered multiDict, then the keys will be in the order they were added.

FUNC $add(Tkey key, Titem item) MultiDict<Tkey, Titem> @public

     

Add an item to the multiDict.

Returns the multiDict.

FUNC $addDict(dict<Tkey, list<Titem>> items) MultiDict<Tkey, Titem> @public

     

Add items from a dictionary.

This makes a copy of the argument.

Returns the multiDict.

FUNC $addList(Tkey key, list<Titem> itemList) MultiDict<Tkey, Titem> @public

     

Add a list of items to the multiDict.

If key is already present the items are appended to the existing list of items.

Returns the multiDict.

FUNC $addList(list<dict<Tkey, Titem>> items) MultiDict<Tkey, Titem> @public

     

Add all the items in a list of dicts to the multiDict.

Returns the multiDict.

FUNC $clear(Tkey key) MultiDict<Tkey, Titem> @public

     

Remove an item from the multiDict if present.

Returns the multiDict.

FUNC $clear() MultiDict<Tkey, Titem> @public

     

Make the multiDict empty.

Returns the multiDict.

FUNC $copy() MultiDict<Tkey, Titem> @public

     

Return a copy of the multiDict.

FUNC $count(Tkey key) int @public

     

Return the number of items in the multiDict with key key.

FUNC $forEach(proc<Titem> f) multiDict<Tkey, Titem> @public

     

Call method f for every item value in the multiDict.

The argument for f is the value.

The order in which f is called for each key is undefined, unless this is an ordered multiDict.

Returns the multiDict.

FUNC $forEachList(proc<list<Titem>> f) multiDict<Tkey, Titem> @public

     

Call method f for every key in the multiDict, passing the list of values.

The argument for f is the list of values.

The order in which f is called for each key is undefined, unless this is an ordered multiDict.

Returns the multiDict.

FUNC $forKeyEach(proc<Tkey, Titem> f) multiDict<Tkey, Titem> @public

     

Call method f for every item key and value in the multiDict.

The first argument for f is the key, the second argument is each value.

The order in which f is called for each item is undefined. unless this is an ordered multiDict.

Returns the multiDict.

FUNC $forKeyEachList(proc<Tkey, list<Titem>> f) multiDict<Tkey, Titem> @public

     

Call method f for every key the multiDict, passing the list of values.

The first argument for f is the key, the second argument is the list of values.

The order in which f is called for each list of items is undefined, unless this is an ordered multiDict.

Returns the multiDict.

FUNC $get(Tkey key) list<Titem> @public

     

Return the list of entries for key key.

Throws an E.KeyNotFound exception when key is not present.

FUNC $get(Tkey key, list<Titem> default) list<Titem> @public

     

Return the list of entries for key key.

Returns default when key is not present.

FUNC $has(Tkey key) bool @public

     

Check if any item with key key is present in the multiDict.

Returns TRUE or FALSE.

FUNC $has(Tkey key, Titem item) bool @public

     

Check if item with key key and value item is present in the multiDict.

Returns TRUE or FALSE.

FUNC $insert(Tkey key, Titem item) MultiDict<Tkey, Titem> @public

     

Add an item to the multiDict.

Same as add(), but inserts before other items with the same key.

Returns the multiDict.

FUNC $isOrdered() bool @public

     

Return whether the order in which keys are added is remembered.

FUNC $keyMap(func<Tkey, Titem => Titem> f) multiDict<Tkey, Titem> @public

     

Execute function f on each item key and each value. Each item value is replaced by the result of the function.

f has two arguments: The key and the value of the item. f must return the new value of the item.

 multiDict<int, string> d = [1: ["a", "b"], 2: ["c"]]
 d.keyMap({ k, v => k .. "/" .. v })
 # d == [1: ["1/a", "2/b"], 2: ["3/c"]]

Returns the multiDict.

FUNC $keyMapList(func<Tkey, list<Titem> => list<Titem>> f) multiDict<Tkey, Titem> @public

     

Execute function f on each item key and value list. Each value list is replaced by the result of the function.

f has two arguments: The key and the value list. f must return the new value list.

Returns the multiDict.

FUNC $keyMapListTo<Tresult>(func<Tkey, list<Titem> => list<Tresult>> f) multiDict<Tkey, Tresult> @public

     

Create a new multiDict where each value list is the result of executing function f on each item key and value list of this multiDict.

This is like keyMapList() but with a different result type.

f has two arguments: The key in the multiDict and the value list. f must return the value list for the new multiDict.

If this dict is ordered, the resulting dict will also be ordered, thus the order of keys remains the same

Returns the new multiDict.

FUNC $keyMapTo<Tresult>(func<Tkey, Titem => Tresult> f) multiDict<Tkey, Tresult> @public

     

Create a new multiDict where each item is the result of executing function f on each item key and value of this multiDict.

This is like keyMap() but with a different result type.

f has two arguments: The key in the multiDict and the value of the item. f must return the value for the new multiDict.

 multiDict<string, int> id = ["one": [11, 22], "three": [33]]
 multiDict<string, string> sd = id.keyMapTo({ k, n => k .. ": " .. n })
 # sd == ["one": ["one: 11", "one: 22"], "three": ["three: 33"]]

If this dict is ordered, the resulting dict will also be ordered, thus the order of keys remains the same

Returns the new multiDict.

FUNC $keys() list<Tkey> @public

     

Return a list with all the keys.

The order is undefined, unless this is an ordered multiDict.

FUNC $map(func<Titem => Titem> f) multiDict<Tkey, Titem> @public

     

Execute function f on each item value. Each value is replaced by the result of the function.

f has one argument, which is the current value, and must return the new value.

 multiDict<int, string> d = [1: ["a", "b"], 2: ["c"]]
 d.map({ s => s .. "+" })
 # d == [1: ["a+", "b+"], 2: ["c+"]]

Returns the multiDict.

FUNC $mapList(func<list<Titem> => list<Titem>> f) multiDict<Tkey, Titem> @public

     

Execute function f on the value list for each key. Each list is replaced by the result of the function.

f has one argument, which is the current value list for the key, and it must return the new value list.

Returns the multiDict.

FUNC $mapListTo<Tresult>(func<list<Titem> => list<Tresult>> f) multiDict<Tkey, Tresult> @public

     

Create a new multiDict where each item list is the result of executing function f on each item list of this multiDict.

This is like mapList() but with a different result type.

f has one argument, which is the value list, and must return the value list for the new multiDict.

If this dict is ordered, the resulting dict will also be ordered, thus the order of keys remains the same

Returns the new multiDict.

FUNC $mapTo<Tresult>(func<Titem => Tresult> f) multiDict<Tkey, Tresult> @public

     

Create a new multiDict where each item is the result of executing function f on each item value of this multiDict.

This is like map() but with a different result type.

f has one argument, which is the value of the item, and must return the value for the new multiDict.

 multiDict<string, int> id = ["one": [1, 2], "two": [3]]
 multiDict<string, string> sd = id.mapTo({ n => n .. ":" })
 # sd == ["one": ["1:", "2:"], "two": ["3:"]]

If this dict is ordered, the resulting dict will also be ordered, thus the order of keys remains the same

Returns the new multiDict.

FUNC $remove(Tkey key, Titem item) MultiDict<Tkey, Titem> @public

     

Remove an item from the multiDict with key key and value equal to item

Throws an E.KeyNotFound exception if the key is not present.

Throws an E.ItemNotFound exception if the item is not present.

Only the first matching item found is removed.

Returns the multiDict.

FUNC $removeAll(Tkey key) MultiDict<Tkey, Titem> @public

     

Remove a list of items from the multiDict with key key.

Throws an E.KeyNotFound exception if the item is not present.

Returns the multiDict.

FUNC $set(Tkey key, list<Titem> items) MultiDict<Tkey, Titem> @public

     

Add an item to the multiDict if not yet present.

When the item is already present nothing happens.

Returns the multiDict.

FUNC $values() list<list<Titem>> @public

     

Return a list with all the lists of values.

The order is undefined, unless this is an ordered multiDict.

license

      Copyright 2009 Bram Moolenaar All Rights Reserved.

      Licensed under the Apache License, Version 2.0. See the LICENSE file or obtain a copy at: http://www.apache.org/licenses/LICENSE-2.0