Balanced tree of 'Compare' keys and 'Base' values
OperationsCode example:
function : Example() ~ Nil {
# insert elements
map := Collection.Map->New()<IntRef, String>;
map->Insert(415, "San Francisco");
map->Insert(510, "Oakland");
map->Insert(925, "East Bay");
# get size
map->Size()->PrintLine();
# get value by key
map->Find(510)->PrintLine();
# get key/values
key_values := map->GetKeyValues()<Pair<IntRef, String>>;
each(key_value := key_values) {
key_value->GetFirst()->PrintLine();
};
# get values
values := map->GetValues()<String>;
each(value := values) {
value->PrintLine();
};
# check for key
map->Has(408)->PrintLine();
}
Default constructor
New()
Function called for each element
method : public : Each(f:(K,V)~Nil) ~ Map<K,V>
Name | Type | Description |
---|---|---|
f | (K,V)~Nil | function called |
Clears the map
method : public : Empty() ~ Nil
Uses the given function to filter out values
method : public : Filter(f:(K)~Bool) ~ Map<K,V>
Name | Type | Description |
---|---|---|
f | (K)~Bool | function to use a filter. If the function evaluates to true the value is added to the collection. |
Type | Description |
---|---|
Map<K,V> | filtered map |
Searches for a value in a map
method : public : Find(key:K) ~ V
Name | Type | Description |
---|---|---|
key | K | search key |
Type | Description |
---|---|
V | found value, Nil if not found |
Get a collection of keys
method : public : GetKeyValues() ~ Collection.Vector<Pair<K,V>>
Type | Description |
---|---|
Vector<Pair<K,V>> | vector of keys |
Get a collection of keys
method : public : GetKeys() ~ Collection.Vector<K>
Type | Description |
---|---|
Vector<K> | vector of keys |
Gets a collection of values
method : public : GetValues() ~ Collection.Vector<V>
Type | Description |
---|---|
Vector<V> | vector of values |
Checks for a value in a map
method : public : Has(key:K) ~ Bool
Name | Type | Description |
---|---|---|
key | K | search key |
Type | Description |
---|---|
Bool | true if found, false otherwise |
Inserts a value into the map
method : public : Insert(key:K, value:V) ~ Nil
Name | Type | Description |
---|---|---|
key | K | key |
value | V | value |
Checks to see if the map is empty
method : public : IsEmpty() ~ Bool
Type | Description |
---|---|
Bool | true if empty, false otherwise |
Removes a value from the map
method : public : Remove(key:K) ~ Bool
Name | Type | Description |
---|---|---|
key | K | key for value to remove |
Size of queue
method : public : Size() ~ Int
Type | Description |
---|---|
Int | size of queue |
Formats the collection into a string. If an element implements the 'Stringify' interface, it's 'ToString()' is called.
method : public : ToString() ~ String
Type | Description |
---|---|
String | string representation |
Creates a map from a vector of keys and values
function : Zip(keys:CompareVector<K>, values:Vector<V>) ~ Map<K,V>
Name | Type | Description |
---|---|---|
keys | CompareVector<K> | keys |
values | Vector<V> | values |
Type | Description |
---|---|
Map<K,V> | map of key/value pairs |