Hash unordered table of generics
OperationsCode example:
# insert elements
hash := Collection.Hash->New()<IntRef, String>;
hash->Insert(415, "San Francisco");
hash->Insert(510, "Oakland");
hash->Insert(925, "East Bay");
# get size
hash->Size()->PrintLine();
# get value by key
hash->Find(510)->PrintLine();
# get key/values
key_values := hash->GetKeyValues()<Pair<IntRef, String>>;
each(key_value := key_values) {
key_value->GetFirst()->PrintLine();
};
# get values
values := hash->GetValues()<String>;
each(value := values) {
value->PrintLine();
};
# check for key
hash->Has(408)->PrintLine();
Default constructor
New()
Default constructor
New(capacity:Hash->Capacity)
Name | Type | Description |
---|---|---|
capacity | Hash->Capacity | capacity of hash table |
Gets the hash table capacity
method : public : Capacity() ~ Hash->Capacity
Type | Description |
---|---|
Hash->Capacity | hash table capacity |
Clears the map
method : public : Empty() ~ Nil
Searches for a value in a hash
method : public : native : Find(key:K) ~ V
Name | Type | Description |
---|---|---|
key | K | search key |
Type | Description |
---|---|
V | found value, Nil if not found |
Gets a collection of key/value pairs
method : public : GetKeyValues() ~ Vector<Pair<K,V>>
Type | Description |
---|---|
Vector<Pair<K,V>> | vector of key/value pairs |
Get a collection of keys
method : public : native : GetKeys() ~ Vector<K>
Type | Description |
---|---|
Vector<K> | vector of keys |
Gets a collection of values
method : public : native : GetValues() ~ Vector<V>
Type | Description |
---|---|
Vector<V> | vector of values |
Checks for a value in a hash
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 hash
method : public : Insert(key:K, value:V) ~ Nil
Name | Type | Description |
---|---|---|
key | K | key |
value | V | value |
Checks to see if the hash table is empty
method : public : IsEmpty() ~ Bool
Type | Description |
---|---|
Bool | true if empty, false otherwise |
Removes a value from the hash
method : public : native : Remove(key:K) ~ Bool
Name | Type | Description |
---|---|---|
key | K | key for value to remove |
Resizes the hash table
method : public : native : Resize(capacity:Hash->Capacity, auto_resize:Bool) ~ Nil
Name | Type | Description |
---|---|---|
capacity | Hash->Capacity | table capacity |
auto_resize | Bool | true for hash table auto resizing, false otherwise |
Size of map
method : public : Size() ~ Int
Type | Description |
---|---|
Int | size of map |
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 |