TrieMap
Key-value hash maps.
An imperative hash map, with a general key and value type.
The
class
TrieMap
exposes the same interface asHashMap
.Unlike HashMap, the internal representation uses a functional representation (via
Trie
module).This class does not permit a direct
clone
operation (neither doesHashMap
), but it does permit creating iterators viaiter()
. Each iterator costsO(1)
to create, but represents a fixed view of the mapping that does not interfere with mutations (it will not reflect subsequent insertions or mutations, if any).
class TrieMap<K, V>
Function size
func size() : Nat
Returns the number of entries in the map.
Function put
func put(k : K, v : V)
Associate a key and value, overwriting any prior association for the key.
Function replace
func replace(k : K, v : V) : ?V
Put the key and value, and return the (optional) prior value for the key.
Function get
func get(k : K) : ?V
Get the (optional) value associated with the given key.
Function delete
func delete(k : K)
Delete the (optional) value associated with the given key.
Function remove
func remove(k : K) : ?V
Delete and return the (optional) value associated with the given key.
Function keys
func keys() : I.Iter<K>
An Iter
over the keys.
Each iterator gets a persistent view of the mapping, independent of concurrent updates to the iterated map.
Function vals
func vals() : I.Iter<V>
An Iter
over the values.
Each iterator gets a persistent view of the mapping, independent of concurrent updates to the iterated map.
Function 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.
Function clone
func clone<K, V>(h : TrieMap<K, V>, keyEq : (K, K) -> Bool, keyHash : K -> Hash.Hash) : TrieMap<K, V>
Clone the map, given its key operations.
Function fromEntries
func fromEntries<K, V>(entries : I.Iter<(K, V)>, keyEq : (K, K) -> Bool, keyHash : K -> Hash.Hash) : TrieMap<K, V>
Clone an iterator of key-value pairs.
Function map
func map<K, V1, V2>(h : TrieMap<K, V1>, keyEq : (K, K) -> Bool, keyHash : K -> Hash.Hash, mapFn : (K, V1) -> V2) : TrieMap<K, V2>
Transform (map) the values of a map, retaining its keys.
Function mapFilter
func mapFilter<K, V1, V2>(h : TrieMap<K, V1>, keyEq : (K, K) -> Bool, keyHash : K -> Hash.Hash, mapFn : (K, V1) -> ?V2) : TrieMap<K, V2>
Transform and filter the values of a map, retaining its keys.