@Internal public class KeyMap<K,V> extends Object implements Iterable<KeyMap.Entry<K,V>>
The differences between this hash map and Java's "java.util.HashMap" are:
Modifier and Type | Class and Description |
---|---|
static class |
KeyMap.Entry<K,V>
An entry in the hash table.
|
static interface |
KeyMap.LazyFactory<V>
A factory for lazy/on-demand instantiation of values.
|
static interface |
KeyMap.TraversalEvaluator<K,V>
A visitor for a traversal over the union of multiple hash maps.
|
Constructor and Description |
---|
KeyMap()
Creates a new hash table with the default initial capacity.
|
KeyMap(int expectedNumberOfElements)
Creates a new table with a capacity tailored to the given expected number of elements.
|
Modifier and Type | Method and Description |
---|---|
V |
get(K key)
Looks up the value mapped under the given key.
|
int |
getCurrentTableCapacity()
Gets the current table capacity, i.e., the number of slots in the hash table, without and
overflow chaining.
|
int |
getLog2TableCapacity()
Gets the base-2 logarithm of the hash table capacity, as returned by
getCurrentTableCapacity() . |
int |
getRehashThreshold() |
int |
getShift() |
boolean |
isEmpty()
Checks whether the map is empty.
|
Iterator<KeyMap.Entry<K,V>> |
iterator()
Creates an iterator over the entries of this map.
|
V |
put(K key,
V value)
Inserts the given value, mapped under the given key.
|
V |
putIfAbsent(K key,
KeyMap.LazyFactory<V> factory)
Inserts a value for the given key, if no value is yet contained for that key.
|
V |
putOrAggregate(K key,
V value,
ReduceFunction<V> aggregator)
Inserts or aggregates a value into the hash map.
|
int |
size()
Gets the number of elements currently in the map.
|
static <K,V> void |
traverseMaps(KeyMap<K,V>[] maps,
KeyMap.TraversalEvaluator<K,V> visitor,
long touchedTag)
Performs a traversal about logical the multi-map that results from the union of the given
maps.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public KeyMap()
public KeyMap(int expectedNumberOfElements)
expectedNumberOfElements
- The number of elements to tailor the capacity to.public final V put(K key, V value)
key
- The key to insert.value
- The value to insert.NullPointerException
- Thrown, if the key is null.public final V putIfAbsent(K key, KeyMap.LazyFactory<V> factory)
The value that is inserted in case that the key is not contained, yet, is lazily created using the given factory.
key
- The key to insert.factory
- The factory that produces the value, if no value is contained, yet, for the
key.NullPointerException
- Thrown, if the key is null.public final V putOrAggregate(K key, V value, ReduceFunction<V> aggregator) throws Exception
key
- The key to map the value.value
- The new value to insert, or aggregate with the existing value.aggregator
- The aggregator to use if a value is already contained.NullPointerException
- Thrown, if the key is null.Exception
- The method forwards exceptions from the aggregation function.public V get(K key)
key
- The key to look up.NullPointerException
- Thrown, if the key is null.public Iterator<KeyMap.Entry<K,V>> iterator()
iterator
in interface Iterable<KeyMap.Entry<K,V>>
public int size()
public boolean isEmpty()
public int getCurrentTableCapacity()
public int getLog2TableCapacity()
getCurrentTableCapacity()
.public int getRehashThreshold()
public int getShift()
public static <K,V> void traverseMaps(KeyMap<K,V>[] maps, KeyMap.TraversalEvaluator<K,V> visitor, long touchedTag) throws Exception
K
- The type of the map's key.V
- The type of the map's value.maps
- The array uf maps whose union should be traversed.visitor
- The visitor that is called for each key and all values.touchedTag
- A tag that is used to mark elements that have been touched in this specific
traversal. Each successive traversal should supply a larger value for this tag than the
previous one.Exception
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.