public final class HamtPMap<K,V> extends java.lang.Object implements PMap<K,V>, java.io.Serializable
Uses a hash array mapped trie: http://en.wikipedia.org/wiki/Hash_array_mapped_trie.
This implementation stores the bare minimum in each node: a key (with its hash), value, mask,
and children. It is also optimized to take maximum advantage of binary operations on shared
trees. Specifically, reconcile(com.google.javascript.rhino.PMap<K, V>, com.google.javascript.rhino.PMap.BiFunction<V, V, V>)
avoids recursing into entire subtrees if they are
identical objects. Null keys and values are not allowed. The implementation special-cases away
the EMPTY map as soon as possible, using 'null' instead for all the logic (since EMPTY violates
the invariant that key and value are non-null). Finally, we maintain an invariant that the
entry with the smallest hash code is always at the root of the tree, which avoids almost all
extra tree rebuilding during binary operations.
PMap.BiFunction<A,B,C>, PMap.BiPredicate<A,B>
Modifier and Type | Method and Description |
---|---|
static <K,V> HamtPMap<K,V> |
empty()
Returns an empty map.
|
boolean |
equivalent(PMap<K,V> that,
PMap.BiPredicate<V,V> equivalence)
Checks equality recursively based on the given equivalence.
|
V |
get(K key)
Retrieves the value associated with the given key from the map, or returns null if it is not
present.
|
boolean |
isEmpty()
Returns whether this map is empty.
|
HamtPMap<K,V> |
minus(K key)
Returns a new map with the given key removed.
|
HamtPMap<K,V> |
plus(K key,
V value)
Returns a new map with the given key-value pair added.
|
HamtPMap<K,V> |
reconcile(PMap<K,V> that,
PMap.BiFunction<V,V,V> joiner)
Performs a reconcile operation.
|
java.lang.String |
toString() |
java.lang.Iterable<V> |
values()
Returns an iterable for a (possibly null) tree.
|
public static <K,V> HamtPMap<K,V> empty()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isEmpty()
public java.lang.Iterable<V> values()
public V get(K key)
public HamtPMap<K,V> plus(K key, V value)
public HamtPMap<K,V> minus(K key)
public HamtPMap<K,V> reconcile(PMap<K,V> that, PMap.BiFunction<V,V,V> joiner)
PMap
that
map must be the same implementation.public boolean equivalent(PMap<K,V> that, PMap.BiPredicate<V,V> equivalence)
equivalent
in interface PMap<K,V>
Copyright © 2009-2019 Google. All Rights Reserved.