Hash
Hash unordered table of generics
# 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();
Operations
- New
- Empty
- Find
- GetCapacity
- GetKeyValues
- GetKeys
- GetValues
- Has
- Insert
- IsAutoResize
- IsEmpty
- Remove
- Resize
- SetAutoResize
- SetCapacity
- Size
- ToString
Find
Searches for a value in a hash
method : public : native : Find(key:K) ~ V
Parameters
Name | Type | Description |
---|---|---|
key | K | search key |
Return
Type | Description |
---|---|
V | found value, Nil if not found |
GetCapacity
Gets the hash table capacity
method : public : GetCapacity() ~ Hash->Capacity
Return
Type | Description |
---|---|
Hash->Capacity | hash table capacity |
GetKeyValues
Gets a collection of key/value pairs
method : public : GetKeyValues() ~ Vector<Pair<K,V>>
Return
Type | Description |
---|---|
Vector<Pair<K,V>> | vector of key/value pairs |
GetKeys
Get a collection of keys
method : public : native : GetKeys() ~ Vector<K>
Return
Type | Description |
---|---|
Vector<K> | vector of keys |
GetValues
Gets a collection of values
method : public : native : GetValues() ~ Vector<V>
Return
Type | Description |
---|---|
Vector<V> | vector of values |
Has
Checks for a value in a hash
method : public : Has(key:K) ~ Bool
Parameters
Name | Type | Description |
---|---|---|
key | K | search key |
Return
Type | Description |
---|---|
Bool | true if found, false otherwise |
Insert
Inserts a value into the hash
method : public : Insert(key:K, value:V) ~ Nil
Parameters
Name | Type | Description |
---|---|---|
key | K | key |
value | V | value |
IsAutoResize
Gets auto-resize setting
method : public : IsAutoResize() ~ Bool
Return
Type | Description |
---|---|
Bool | true if auto-resize is set, false otherwise |
IsEmpty
Checks to see if the hash table is empty
method : public : IsEmpty() ~ Bool
Return
Type | Description |
---|---|
Bool | true if empty, false otherwise |
New
Default constructor
New(auto_resize:Bool)
Parameters
Name | Type | Description |
---|---|---|
auto_resize | Bool | if true, automatically resized the hash table |
New
Default constructor
New(capacity:Hash->Capacity, auto_resize:Bool)
Parameters
Name | Type | Description |
---|---|---|
capacity | Hash->Capacity | capacity of hash table |
auto_resize | Bool | if true, automatically resized the hash table |
Remove
Removes a value from the hash
method : public : native : Remove(key:K) ~ Bool
Parameters
Name | Type | Description |
---|---|---|
key | K | key for value to remove |
Resize
Resizes the hash table
method : public : native : Resize(capacity:Hash->Capacity, auto_resize:Bool) ~ Nil
Parameters
Name | Type | Description |
---|---|---|
capacity | Hash->Capacity | table capacity |
auto_resize | Bool | true for hash table auto resizing, false otherwise |
SetAutoResize
Set auto-resize setting
method : public : SetAutoResize(auto_resize:Bool) ~ Nil
Parameters
Name | Type | Description |
---|---|---|
auto_resize | Bool | true if auto-resize is enable, false otherwise |
SetCapacity
Sets hash table capacity
method : public : SetCapacity(capacity:Hash->Capacity) ~ Nil
Parameters
Name | Type | Description |
---|---|---|
capacity | Hash->Capacity | hash table capacity |
ToString
Formats the collection into a string. If an element implements the 'Stringify' interface, it's 'ToString()' is called.
method : public : ToString() ~ String
Return
Type | Description |
---|---|
String | string representation |