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
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
class val HashMap[K: Any #share, V: Any #share, H: HashFunction[K] val]
new val create() : HashMap[K, V, H] val^
new val _create( r: _MapSubNodes[K, V, H] val, s: USize val) : HashMap[K, V, H] val^
Attempt to get the value corresponding to k.
fun val apply( k: K) : val->V ?
Return the amount of key-value pairs in the Map.
fun val size() : USize val
Update the value associated with the provided key.
fun val update( key: K, value: val->V) : HashMap[K, V, H] val
Try to remove the provided key from the Map.
fun val remove( k: K) : HashMap[K, V, H] val ?
Get the value associated with provided key if present. Otherwise, return the provided alternate value.
fun val get_or_else( k: K, alt: val->V) : val->V
Check whether the node contains the provided key.
fun val contains( k: K) : Bool val
Add the K, V pairs from the given iterator to the map.
fun val concat( iter: Iterator[(val->K , val->V)] ref) : HashMap[K, V, H] val
fun val keys() : MapKeys[K, V, H] ref
fun val values() : MapValues[K, V, H] ref
fun val pairs() : MapPairs[K, V, H] ref
fun box _root_node() : _MapSubNodes[K, V, H] val
© 2016-2018, The Pony Developers
© 2014-2015, Causality Ltd.
Licensed under the BSD 2-Clause License.
https://stdlib.ponylang.io/collections-persistent-HashMap