TrieMap
Functional map
This module defines an imperative hash map, with a general key and value type. It matches the interface and semantics of HashMap. Unlike HashMap, its internal representation uses a functional hash trie (see library Trie).
This class permits us to compare the performance of two representations of hash-based maps, where tries (as binary trees) permit more efficient, constant-time, cloning compared with ordinary tables. This property is nice for supporting transactional workflows where map mutations may be provisional, and where we may expect some mutations to be uncommitted, or to "roll back".
For now, this class does not permit a direct clone operation (neither does HashMap), but it does permit creating iterators via iter(). The effect is similar: Each iterator costs O(1) to create, but represents a fixed view of the mapping that does not interfere with mutations (it will not view subsequent insertions or mutations, if any).
TrieMap
class TrieMap<K, V>(isEq : (K, K) -> Bool, hashOf : K -> Hash.Hash)
put
func put(k : K, v : V)
Associate a key and value, overwriting any prior association for the key.
replace
func replace(k : K, v : V) : ?V
Put the key and value, and return the (optional) prior value for the key.
remove
func remove(k : K) : ?V
Delete and return the (optional) value associated with the given key.
entries
func entries() : I.Iter<(K, V)>
Returns an Iter over the entries.
Each iterator gets a persistent view of the mapping, independent of concurrent updates to the iterated map.