HashMap[K: Any #share, V: Any #share, H: HashFunction[K] val]¶
A persistent map based on the Compressed Hash Array Mapped Prefix-tree from 'Optimizing Hash-Array Mapped Tries for Fast and Lean Immutable JVM Collections' by Michael J. Steindorfer and Jurgen J. Vinju
Usage¶
use "collections/persistent"
actor Main
new create(env: Env) =>
try
let m1 = Map[String, U32] // {}
// Update returns a new map with the provided key set
// to the provided value. The old map is unchanged.
let m2 = m1("a") = 5 // {a: 5}
let m3 = m2("b") = 10 // {a: 5, b: 10}
let m4 = m3.remove("a")? // {b: 10}
// You can create a new map from key value pairs.
let m5 = Map[String, U32].concat([("a", 2); ("b", 3)].values()) // {a: 2, b: 3}
end
Constructors¶
create¶
Returns¶
- HashMap[K, V, H] val^
Public Functions¶
apply¶
Attempt to get the value corresponding to k.
Parameters¶
- k: K
Returns¶
- val->V ?
size¶
Return the amount of key-value pairs in the Map.
Returns¶
- USize val
update¶
Update the value associated with the provided key.
Parameters¶
- key: K
- value: val->V
Returns¶
- HashMap[K, V, H] val
remove¶
Try to remove the provided key from the Map.
Parameters¶
- k: K
Returns¶
- HashMap[K, V, H] val ?
get_or_else¶
Get the value associated with provided key if present. Otherwise, return the provided alternate value.
Parameters¶
- k: K
- alt: val->V
Returns¶
- val->V
contains¶
Check whether the node contains the provided key.
Parameters¶
- k: K
Returns¶
- Bool val
concat¶
Add the K, V pairs from the given iterator to the map.
Parameters¶
- iter: Iterator[(val->K , val->V)] ref
Returns¶
- HashMap[K, V, H] val
add¶
Return this Map with the given (key, value) mapping.
Parameters¶
- key: K
- value: val->V
Returns¶
- HashMap[K, V, H] val
sub¶
Return this Map without the given key.
Parameters¶
- key: K
Returns¶
- HashMap[K, V, H] val
keys¶
Returns¶
- MapKeys[K, V, H] ref
values¶
Returns¶
- MapValues[K, V, H] ref
pairs¶
Returns¶
- MapPairs[K, V, H] ref