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


_create

new val _create(
  r: _MapNode[K, V, H] val,
  s: USize val)
: HashMap[K, V, H] val^

Parameters

Returns


Public Functions

apply

Attempt to get the value corresponding to k.

fun val apply(
  k: K)
: V ?

Parameters

  • k: K

Returns

  • V ?

size

Return the amount of key-value pairs in the Map.

fun val size()
: USize val

Returns


update

Update the value associated with the provided key.

fun val update(
  key: K,
  value: V)
: HashMap[K, V, H] val

Parameters

  • key: K
  • value: V

Returns


remove

Try to remove the provided key from the Map.

fun val remove(
  k: K)
: HashMap[K, V, H] val ?

Parameters

  • k: K

Returns


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: V)
: V

Parameters

  • k: K
  • alt: V

Returns

  • V

contains

Check whether the node contains the provided key.

fun val contains(
  k: K)
: Bool val

Parameters

  • k: K

Returns


concat

Add the K, V pairs from the given iterator to the map.

fun val concat(
  iter: Iterator[(K , V)] ref)
: HashMap[K, V, H] val

Parameters

Returns


keys

fun val keys()
: MapKeys[K, V, H] ref

Returns


values

fun val values()
: MapValues[K, V, H] ref

Returns


pairs

fun val pairs()
: MapPairs[K, V, H] ref

Returns


Private Functions

_root_node

fun box _root_node()
: _MapNode[K, V, H] val

Returns