All Bundles

Hash<K:Compare,V>

Hash unordered table of generics

Operations

Code 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();

New

Default constructor

New()

Default constructor

New(capacity:Hash->Capacity)
Parameters
NameTypeDescription
capacityHash->Capacitycapacity of hash table

Capacity

Gets the hash table capacity

method : public : Capacity() ~ Hash->Capacity
Return
TypeDescription
Hash->Capacityhash table capacity

Empty

Clears the map

method : public : Empty() ~ Nil

Find

Searches for a value in a hash

method : public : native : Find(key:K) ~ V
Parameters
NameTypeDescription
keyKsearch key

Return
TypeDescription
Vfound value, Nil if not found

GetKeyValues

Gets a collection of key/value pairs

method : public : GetKeyValues() ~ Vector<Pair<K,V>>
Return
TypeDescription
Vector<Pair<K,V>>vector of key/value pairs

GetKeys

Get a collection of keys

method : public : native : GetKeys() ~ Vector<K>
Return
TypeDescription
Vector<K>vector of keys

GetValues

Gets a collection of values

method : public : native : GetValues() ~ Vector<V>
Return
TypeDescription
Vector<V>vector of values

Has

Checks for a value in a hash

method : public : Has(key:K) ~ Bool
Parameters
NameTypeDescription
keyKsearch key

Return
TypeDescription
Booltrue if found, false otherwise

Insert

Inserts a value into the hash

method : public : Insert(key:K, value:V) ~ Nil
Parameters
NameTypeDescription
keyKkey
valueVvalue

IsEmpty

Checks to see if the hash table is empty

method : public : IsEmpty() ~ Bool
Return
TypeDescription
Booltrue if empty, false otherwise

Remove

Removes a value from the hash

method : public : native : Remove(key:K) ~ Bool
Parameters
NameTypeDescription
keyKkey for value to remove

Resize

Resizes the hash table

method : public : native : Resize(capacity:Hash->Capacity, auto_resize:Bool) ~ Nil
Parameters
NameTypeDescription
capacityHash->Capacitytable capacity
auto_resizeBooltrue for hash table auto resizing, false otherwise

Size

Size of map

method : public : Size() ~ Int
Return
TypeDescription
Intsize of map

ToString

Formats the collection into a string. If an element implements the 'Stringify' interface, it's 'ToString()' is called.

method : public : ToString() ~ String
Return
TypeDescription
Stringstring representation