W3cubDocs

/Pony

HashMap[K: Any #share, V: Any #share, H: HashFunction[K] val]

[Source]

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

[Source]

new val create()
: HashMap[K, V, H] val^

Returns

_create

[Source]

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

Parameters

Returns

Public Functions

apply

[Source]

Attempt to get the value corresponding to k.

fun val apply(
  k: K)
: val->V ?

Parameters

  • k: K

Returns

  • val->V ?

size

[Source]

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

fun val size()
: USize val

Returns

update

[Source]

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

remove

[Source]

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

[Source]

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

[Source]

Check whether the node contains the provided key.

fun val contains(
  k: K)
: Bool val

Parameters

  • k: K

Returns

concat

[Source]

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

Returns

keys

[Source]

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

Returns

values

[Source]

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

Returns

pairs

[Source]

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

Returns

Private Functions

_root_node

[Source]

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

Returns

© 2016-2018, The Pony Developers
© 2014-2015, Causality Ltd.
Licensed under the BSD 2-Clause License.
https://stdlib.ponylang.io/collections-persistent-HashMap