Class HamtPMap<K,V>
- All Implemented Interfaces:
PMap<K,
,V> 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.Reconciler<K, 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.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.google.javascript.rhino.PMap
PMap.Reconciler<K,
V> -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> HamtPMap <K, V> empty()
Returns an empty map.boolean
equivalent
(PMap<K, V> that, BiPredicate<V, V> equivalence) Checks equality recursively based on the given equivalence.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.keys()
Returns an iterable for a (possibly null) tree.Returns a new map with the given key removed.Returns a new map with the given key-value pair added.Performs a reconcile operation to mergethis
andthat
.toString()
values()
Returns an iterable for a (possibly null) tree.
-
Method Details
-
empty
Returns an empty map. -
toString
-
isEmpty
@CheckReturnValue public boolean isEmpty()Returns whether this map is empty. -
values
Returns an iterable for a (possibly null) tree. -
keys
Returns an iterable for a (possibly null) tree. -
get
Retrieves the value associated with the given key from the map, or returns null if it is not present. -
plus
Returns a new map with the given key-value pair added. If the value is already present, then this same map will be returned. -
minus
Returns a new map with the given key removed. If the key was not present in the first place, then this same map will be returned. -
reconcile
Description copied from interface:PMap
Performs a reconcile operation to mergethis
andthat
.joiner
is called for each pair of entries, one from each map, which share the same key and whose values are notObject.equals(java.lang.Object)
. This includes entries that are absent from one of the maps, for whichnull
is passed as the absent value.The return of calling
joiner
will appear in the merged map at the key of the original entry pair. The return may not be null. If the values in a pair of entries areObject.equals(java.lang.Object)
, that value will be used directly in the result without callingjoiner
.The first value passed to
joiner
comes fromthis
, and the second value comes fromthat
. There are no guarantees on the source ofkey
. Note thatthat
map must be the same implementation. -
equivalent
Checks equality recursively based on the given equivalence. Short-circuits as soon as a 'false' result is found.- Specified by:
equivalent
in interfacePMap<K,
V>
-