This is a drastically simplified table system, made soley because the standard library's implementation, while more efficient, is missing important and necessary low-level functionality.
Types
HashTable[A; B] = object keys: seq[A] vals: seq[B] graph: HashTableItem
HashTableRef[A; B] = ref HashTable[A, B]
SomeHashTable[A; B] = HashTable[A, B] | HashTableRef[A, B]
Procs
proc `[]=`[A, B](self: var SomeHashTable[A, B]; key: A; val: B)
- Sets or creates the association of val for key
proc delIndex[A, B](self: var SomeHashTable[A, B]; idx: int)
- Delete the key and value pair associated with the given numerical index
Funcs
func getKey[A, B](self: SomeHashTable[A, B]; idx: int): A
- Returns the key by numerical index
func getIndex[A, B](self: SomeHashTable[A, B]; key: A): int
- Returns the index of the given key
func hasKey[A, B](self: SomeHashTable[A, B]; key: A): bool
- Returns whether or not the hash table has the given key
func `[]`[A, B](self: SomeHashTable[A, B]; key: A): B
- Returns the value associated with the given key
func getByIndex[A, B](self: SomeHashTable[A, B]; idx: int): B
- Get the val associated with the given numerical index
func setByIndex[A, B](self: var SomeHashTable[A, B]; idx: int; val: B)
- Set the val associated with the given numerical index
func pop[A, B](self: var SomeHashTable[A, B]; key: A): B
- Delete and return the value associated with key
func len[A, B](self: SomeHashTable[A, B]): int {...}{.inline.}
- Return the number of items in the hash table
func high[A, B](self: SomeHashTable[A, B]): int {...}{.inline.}
- Return the last index in the hash table
Iterators
iterator pairs[A, B](self: SomeHashTable[A, B]): tuple[key: A, value: B]
- Walk the hash table and return each key value pair
iterator values[A, B](self: SomeHashTable[A, B]): B
- Walk the hash table and return each value
iterator keys[A, B](self: SomeHashTable[A, B]): A
- Walk the hash table and return each key
Templates
template del[A; B](self: var SomeHashTable[A, B]; key: A)
- Delete the value and key