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
class val HashMap[K: Any #share, V: Any #share, H: HashFunction[K] val]
Constructors
create
new val create() : HashMap[K, V, H] val^
Returns
- HashMap[K, V, H] val^
Public Functions
apply
Attempt to get the value corresponding to k.
fun val apply( k: K) : val->V ?
Parameters
- k: K
Returns
- val->V ?
size
Return the amount of key-value pairs in the Map.
fun val size() : USize val
Returns
- USize val
update
Update the value associated with the provided key.
fun val update( key: K, value: val->V) : HashMap[K, V, H] val
Parameters
- key: K
- value: val->V
Returns
- HashMap[K, V, H] val
remove
Try to remove the provided key from the Map.
fun val remove( k: K) : HashMap[K, V, H] val ?
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.
fun val get_or_else( k: K, alt: val->V) : val->V
Parameters
- k: K
- alt: val->V
Returns
- val->V
contains
Check whether the node contains the provided key.
fun val contains( k: K) : Bool val
Parameters
- k: K
Returns
- Bool val
concat
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
Parameters
- iter: Iterator[(val->K , val->V)] ref
Returns
- HashMap[K, V, H] val
add
Return this Map with the given (key, value) mapping.
fun val add( key: K, value: val->V) : HashMap[K, V, H] val
Parameters
- key: K
- value: val->V
Returns
- HashMap[K, V, H] val
sub
Return this Map without the given key.
fun val sub( key: K) : HashMap[K, V, H] val
Parameters
- key: K
Returns
- HashMap[K, V, H] val
keys
fun val keys() : MapKeys[K, V, H] ref
Returns
- MapKeys[K, V, H] ref
values
fun val values() : MapValues[K, V, H] ref
Returns
- MapValues[K, V, H] ref
pairs
fun val pairs() : MapPairs[K, V, H] ref
Returns
- MapPairs[K, V, H] ref
© 2016-2020, The Pony Developers
© 2014-2015, Causality Ltd.
Licensed under the BSD 2-Clause License.
https://stdlib.ponylang.io/collections-persistent-HashMap