@Generated(date="2017-07-11T19:16:32+0200",
value="KTypeVTypeHashMap.java")
public class DoubleShortHashMap
extends java.lang.Object
implements DoubleShortMap, java.lang.Cloneable
double to short, implemented using open
addressing with linear probing for collision resolution.
The internal buffers of this implementation (keys, values),
are always allocated to the nearest size that is a power of two. When
the capacity exceeds the given load factor, the buffer size is doubled.
| Modifier and Type | Class and Description |
|---|---|
class |
DoubleShortHashMap.EntryIterator
An iterator implementation for
iterator(). |
class |
DoubleShortHashMap.KeysCollection
A view of the keys inside this map.
|
class |
DoubleShortHashMap.KeysIterator
An iterator over the set of keys.
|
class |
DoubleShortHashMap.ValuesCollection
A view over the set of values of this map.
|
class |
DoubleShortHashMap.ValuesIterator
An iterator over the set of values.
|
| Modifier and Type | Field and Description |
|---|---|
boolean |
allocatedDefaultKey
True if key = 0/null is in the map.
|
short |
allocatedDefaultKeyValue
if allocatedDefaultKey = true, contains the associated V to the key = 0/null
|
protected int |
assigned
Cached number of assigned slots in
keys. |
protected short |
defaultValue |
protected IteratorPool<DoubleShortCursor,DoubleShortHashMap.EntryIterator> |
entryIteratorPool
internal pool of EntryIterator
|
double[] |
keys
Hash-indexed array holding all keys.
|
protected double |
loadFactor
The load factor for this map (fraction of allocated slots
before the buffers must be rehashed or reallocated).
|
short[] |
values
Hash-indexed array holding all values associated to the keys.
|
| Constructor and Description |
|---|
DoubleShortHashMap()
Default constructor: Creates a hash map with the default capacity of
Containers.DEFAULT_EXPECTED_ELEMENTS,
load factor of HashContainers.DEFAULT_LOAD_FACTOR. |
DoubleShortHashMap(DoubleShortAssociativeContainer container)
Create a hash map from all key-value pairs of another container.
|
DoubleShortHashMap(int initialCapacity)
Creates a hash map with the given initial capacity, default load factor of
HashContainers.DEFAULT_LOAD_FACTOR. |
DoubleShortHashMap(int initialCapacity,
double loadFactor)
Creates a hash map with the given initial capacity,
load factor.
|
| Modifier and Type | Method and Description |
|---|---|
short |
addTo(double key,
short incrementValue)
Adds
incrementValue to any existing value for the given key
or inserts incrementValue if key did not previously exist. |
int |
capacity()
Return the maximum number of keys this container is guaranteed to hold without reallocating.
|
void |
clear()
Clear all keys and values in the container.
|
DoubleShortHashMap |
clone() |
boolean |
containsKey(double key)
Returns
true if this container has an association to a value for
the given key. |
boolean |
equals(java.lang.Object obj) |
<T extends DoubleShortPredicate> |
forEach(T predicate)
Applies a
predicate to container elements, as long as the predicate
returns true. |
<T extends DoubleShortProcedure> |
forEach(T procedure)
Applies a given procedure to all keys-value pairs in this container.
|
static DoubleShortHashMap |
from(double[] keys,
short[] values)
Creates a hash map from two index-aligned arrays of key-value pairs.
|
static DoubleShortHashMap |
from(DoubleShortAssociativeContainer container)
Create a hash map from another associative container.
|
short |
get(double key) |
short |
getDefaultValue()
Returns the "default value" value used in containers methods returning
"default value"
|
int |
hashCode() |
boolean |
isEmpty()
Note that an empty container may still contain many deleted keys (that occupy buffer
space).
|
DoubleShortHashMap.EntryIterator |
iterator()
Returns a cursor over the entries (key-value pairs) in this map.
|
DoubleShortHashMap.KeysCollection |
keys()
Returns a collection view of keys of this container.
|
static DoubleShortHashMap |
newInstance()
Create a new hash map without providing the full generic signature
(constructor shortcut).
|
static DoubleShortHashMap |
newInstance(int initialCapacity,
double loadFactor)
Create a new hash map with initial capacity and load factor control.
|
short |
put(double key,
short value)
Place a given key and value in the container.
|
int |
putAll(DoubleShortAssociativeContainer container)
Puts all keys from another container to this map, replacing the values
of existing keys, if such keys are present.
|
int |
putAll(java.lang.Iterable<? extends DoubleShortCursor> iterable)
Puts all keys from an iterable cursor to this map, replacing the values
of existing keys, if such keys are present.
|
boolean |
putIfAbsent(double key,
short value)
Trove-inspired API method.
|
short |
putOrAdd(double key,
short putValue,
short incrementValue)
If
key exists, putValue is inserted into the map,
otherwise any existing value is incremented by additionValue. |
short |
remove(double key)
Remove the (key, value) pair associated with the given key, and returns the assocaited value.
|
int |
removeAll(DoubleContainer other)
Removes all keys (and associated values) present in a given container.
|
int |
removeAll(DoublePredicate predicate)
Removes all keys (and associated values) for which the predicate on keys returns
true. |
int |
removeAll(DoubleShortPredicate predicate)
Removes all keys (and associated values) for which the predicate on (key, value) pairs returns
true. |
void |
setDefaultValue(short defaultValue)
Set the "default value" value to be used in containers methods returning
"default value"
|
int |
size() |
java.lang.String |
toString()
Convert the contents of this map to a human-friendly string.
|
DoubleShortHashMap.ValuesCollection |
values()
Returns a collection view of all values present in this container.
|
protected short defaultValue
public double[] keys
Direct map iteration: iterate {keys[i], values[i]} for i in [0; keys.length[ where keys[i] != 0/null, then also
{0/null, allocatedDefaultKeyValue } is in the map if allocatedDefaultKey = true.
public short[] values
keys.public boolean allocatedDefaultKey
public short allocatedDefaultKeyValue
protected int assigned
keys.protected final double loadFactor
protected final IteratorPool<DoubleShortCursor,DoubleShortHashMap.EntryIterator> entryIteratorPool
public DoubleShortHashMap()
Containers.DEFAULT_EXPECTED_ELEMENTS,
load factor of HashContainers.DEFAULT_LOAD_FACTOR.
See class notes about hash distribution importance.
public DoubleShortHashMap(int initialCapacity)
HashContainers.DEFAULT_LOAD_FACTOR.
See class notes about hash distribution importance.
initialCapacity - Initial capacity (greater than zero and automatically
rounded to the next power of two).public DoubleShortHashMap(int initialCapacity,
double loadFactor)
loadFactor - The load factor (greater than zero and smaller than 1).public DoubleShortHashMap(DoubleShortAssociativeContainer container)
public short put(double key,
short value)
put in interface DoubleShortMappublic int putAll(DoubleShortAssociativeContainer container)
putAll in interface DoubleShortMappublic int putAll(java.lang.Iterable<? extends DoubleShortCursor> iterable)
putAll in interface DoubleShortMappublic boolean putIfAbsent(double key,
short value)
if (!map.containsKey(key))
map.put(key, value);
putIfAbsent in interface DoubleShortMapkey - The key of the value to check.value - The value to put if key does not exist.true if key did not exist and value
was placed in the map.public short putOrAdd(double key,
short putValue,
short incrementValue)
key exists, putValue is inserted into the map,
otherwise any existing value is incremented by additionValue.putOrAdd in interface DoubleShortMapkey - The key of the value to adjust.putValue - The value to put if key does not exist.incrementValue - The value to add to the existing value if key exists.key (after
changes).public short addTo(double key,
short incrementValue)
incrementValue to any existing value for the given key
or inserts incrementValue if key did not previously exist.addTo in interface DoubleShortMapkey - The key of the value to adjust.incrementValue - The value to put or add to the existing value if key exists.key (after changes).public short remove(double key)
remove in interface DoubleShortMappublic int removeAll(DoubleContainer other)
removeAll in interface DoubleShortAssociativeContainerpublic int removeAll(DoublePredicate predicate)
true.removeAll in interface DoubleShortAssociativeContainerpublic int removeAll(DoubleShortPredicate predicate)
true.removeAll in interface DoubleShortAssociativeContainerpublic short get(double key)
get in interface DoubleShortMappublic boolean containsKey(double key)
true if this container has an association to a value for
the given key.containsKey in interface DoubleShortAssociativeContainerpublic void clear()
clear in interface DoubleShortMappublic int size()
size in interface DoubleShortAssociativeContainerpublic int capacity()
O(n) time.capacity in interface DoubleShortAssociativeContainerpublic boolean isEmpty()
Note that an empty container may still contain many deleted keys (that occupy buffer space). Adding even a single element to such a container may cause rehashing.
isEmpty in interface DoubleShortAssociativeContainertrue if this hash map contains no assigned keys.public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic DoubleShortHashMap.EntryIterator iterator()
Iterator.next(). To read the current key and value use the cursor's
public fields. An example is shown below.
for (IntShortCursor c : intShortMap)
{
System.out.println("index=" + c.index
+ " key=" + c.key
+ " value=" + c.value);
}
The index field inside the cursor gives the internal index inside
the container's implementation. The interpretation of this index depends on
to the container.
iterator in interface DoubleShortAssociativeContaineriterator in interface java.lang.Iterable<DoubleShortCursor>public <T extends DoubleShortProcedure> T forEach(T procedure)
DoubleShortProcedure. This lets the caller to call methods of the argument
by chaining the call (even if the argument is an anonymous type) to retrieve computed values,
for example.forEach in interface DoubleShortAssociativeContainerpublic <T extends DoubleShortPredicate> T forEach(T predicate)
predicate to container elements, as long as the predicate
returns true. The iteration is interrupted otherwise.
Returns the argument (any
subclass of DoubleShortPredicate. This lets the caller to call methods of the argument
by chaining the call (even if the argument is an anonymous type) to retrieve computed values,
for example.
The iteration is continued as long as the predicate returns true.forEach in interface DoubleShortAssociativeContainerpublic DoubleShortHashMap.KeysCollection keys()
keys in interface DoubleShortAssociativeContainerpublic DoubleShortHashMap.ValuesCollection values()
values in interface DoubleShortAssociativeContainerpublic DoubleShortHashMap clone()
clone in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic static DoubleShortHashMap from(double[] keys, short[] values)
public static DoubleShortHashMap from(DoubleShortAssociativeContainer container)
public static DoubleShortHashMap newInstance()
public static DoubleShortHashMap newInstance(int initialCapacity, double loadFactor)
public short getDefaultValue()
getDefaultValue in interface DoubleShortMappublic void setDefaultValue(short defaultValue)
setDefaultValue in interface DoubleShortMapCopyright © 2017. All rights reserved.