Hash - mfichman/jogo GitHub Wiki
A hash is a dynamically-resizable container that uses arbitrary keys. The key ':k' can be any object with the 'hash' method defined. Hashes provide efficient lookup and deletion (amortized constant) assuming a good hash function. Worst case lookup is linear with respect to the number of objects in the hash.
@init()
Creates a new hash with zero elements.
@destroy()
Releases memory used by the hash, and decrements all the reference counts on objects held by the hash
@insert(key :k, value :v)
Inserts 'value' into the hash map with key 'key'. The key can be used to retrieve the value later.
@index(key :k) :v
Returns the element associated with 'key'. Returns nil if there is no element associated with 'key'.
@add(other Hash[:k,:v]) Hash[:k,:v]
Returns a new hash that is the union over the keys in this hash and 'other'. If there is a key present in both hashes, the associated value in this hash takes takes precedence over the associated value in 'other'.
iter() HashIter[:k,:v]
Returns an iterator for all the key-value pairs in this hash.
values?() HashValueIter[:k,:v]
Returns an iterator for all the values in this hash.
keys?() HashKeyIter[:k,:v]
Returns an iterator for all the keys in this hash.
hash(element :k) Int
Returns the hash for 'element'
equal(first :k, second :v) Int
Compares 'first' and second' for equality
rehash()
Re-sizes the hash, and re-hashes all buckets.
capacity?() Int
No comment
count?() Int
No comment