@Generated(date="2017-07-11T19:16:29+0200",
value="KTypeVTypeHashMap.java")
public class ShortObjectHashMap<VType>
extends java.lang.Object
implements ShortObjectMap<VType>, java.lang.Cloneable
short to Object, 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.
This implementation supports null values.
| Modifier and Type | Class and Description |
|---|---|
class |
ShortObjectHashMap.EntryIterator
An iterator implementation for
iterator(). |
class |
ShortObjectHashMap.KeysCollection
A view of the keys inside this map.
|
class |
ShortObjectHashMap.KeysIterator
An iterator over the set of keys.
|
class |
ShortObjectHashMap.ValuesCollection
A view over the set of values of this map.
|
class |
ShortObjectHashMap.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.
|
VType |
allocatedDefaultKeyValue
if allocatedDefaultKey = true, contains the associated V to the key = 0/null
|
protected int |
assigned
Cached number of assigned slots in
keys. |
protected VType |
defaultValue |
protected IteratorPool<ShortObjectCursor<VType>,ShortObjectHashMap.EntryIterator> |
entryIteratorPool
internal pool of EntryIterator
|
short[] |
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).
|
java.lang.Object[] |
values
Hash-indexed array holding all values associated to the keys.
|
| Constructor and Description |
|---|
ShortObjectHashMap()
Default constructor: Creates a hash map with the default capacity of
Containers.DEFAULT_EXPECTED_ELEMENTS,
load factor of HashContainers.DEFAULT_LOAD_FACTOR. |
ShortObjectHashMap(int initialCapacity)
Creates a hash map with the given initial capacity, default load factor of
HashContainers.DEFAULT_LOAD_FACTOR. |
ShortObjectHashMap(int initialCapacity,
double loadFactor)
Creates a hash map with the given initial capacity,
load factor.
|
ShortObjectHashMap(ShortObjectAssociativeContainer<VType> container)
Create a hash map from all key-value pairs of another container.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
ShortObjectHashMap<VType> |
clone() |
boolean |
containsKey(short key)
Returns
true if this container has an association to a value for
the given key. |
boolean |
equals(java.lang.Object obj) |
<T extends ShortObjectPredicate<? super VType>> |
forEach(T predicate)
Applies a
predicate to container elements, as long as the predicate
returns true. |
<T extends ShortObjectProcedure<? super VType>> |
forEach(T procedure)
Applies a given procedure to all keys-value pairs in this container.
|
static <VType> ShortObjectHashMap<VType> |
from(short[] keys,
VType[] values)
Creates a hash map from two index-aligned arrays of key-value pairs.
|
static <VType> ShortObjectHashMap<VType> |
from(ShortObjectAssociativeContainer<VType> container)
Create a hash map from another associative container.
|
VType |
get(short key) |
VType |
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).
|
ShortObjectHashMap.EntryIterator |
iterator()
Returns a cursor over the entries (key-value pairs) in this map.
|
ShortObjectHashMap.KeysCollection |
keys()
Returns a collection view of keys of this container.
|
static <VType> ShortObjectHashMap<VType> |
newInstance()
Create a new hash map without providing the full generic signature
(constructor shortcut).
|
static <VType> ShortObjectHashMap<VType> |
newInstance(int initialCapacity,
double loadFactor)
Create a new hash map with initial capacity and load factor control.
|
VType |
put(short key,
VType value)
Place a given key and value in the container.
|
int |
putAll(java.lang.Iterable<? extends ShortObjectCursor<? extends VType>> iterable)
Puts all keys from an iterable cursor to this map, replacing the values
of existing keys, if such keys are present.
|
int |
putAll(ShortObjectAssociativeContainer<? extends VType> container)
Puts all keys from another container to this map, replacing the values
of existing keys, if such keys are present.
|
boolean |
putIfAbsent(short key,
VType value)
Trove-inspired API method.
|
VType |
remove(short key)
Remove the (key, value) pair associated with the given key, and returns the assocaited value.
|
int |
removeAll(ShortContainer other)
Removes all keys (and associated values) present in a given container.
|
int |
removeAll(ShortObjectPredicate<? super VType> predicate)
Removes all keys (and associated values) for which the predicate on (key, value) pairs returns
true. |
int |
removeAll(ShortPredicate predicate)
Removes all keys (and associated values) for which the predicate on keys returns
true. |
void |
setDefaultValue(VType 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.
|
ShortObjectHashMap.ValuesCollection |
values()
Returns a collection view of all values present in this container.
|
protected VType defaultValue
public short[] 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 java.lang.Object[] values
keys.public boolean allocatedDefaultKey
public VType allocatedDefaultKeyValue
protected int assigned
keys.protected final double loadFactor
protected final IteratorPool<ShortObjectCursor<VType>,ShortObjectHashMap.EntryIterator> entryIteratorPool
public ShortObjectHashMap()
Containers.DEFAULT_EXPECTED_ELEMENTS,
load factor of HashContainers.DEFAULT_LOAD_FACTOR.
See class notes about hash distribution importance.
public ShortObjectHashMap(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 ShortObjectHashMap(int initialCapacity,
double loadFactor)
loadFactor - The load factor (greater than zero and smaller than 1).public ShortObjectHashMap(ShortObjectAssociativeContainer<VType> container)
public VType put(short key, VType value)
put in interface ShortObjectMap<VType>public int putAll(ShortObjectAssociativeContainer<? extends VType> container)
putAll in interface ShortObjectMap<VType>public int putAll(java.lang.Iterable<? extends ShortObjectCursor<? extends VType>> iterable)
putAll in interface ShortObjectMap<VType>public boolean putIfAbsent(short key,
VType value)
if (!map.containsKey(key))
map.put(key, value);
putIfAbsent in interface ShortObjectMap<VType>key - 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 VType remove(short key)
remove in interface ShortObjectMap<VType>public int removeAll(ShortContainer other)
removeAll in interface ShortObjectAssociativeContainer<VType>public int removeAll(ShortPredicate predicate)
true.removeAll in interface ShortObjectAssociativeContainer<VType>public int removeAll(ShortObjectPredicate<? super VType> predicate)
true.removeAll in interface ShortObjectAssociativeContainer<VType>public VType get(short key)
get in interface ShortObjectMap<VType>public boolean containsKey(short key)
true if this container has an association to a value for
the given key.containsKey in interface ShortObjectAssociativeContainer<VType>public void clear()
clear in interface ShortObjectMap<VType>public int size()
size in interface ShortObjectAssociativeContainer<VType>public int capacity()
O(n) time.capacity in interface ShortObjectAssociativeContainer<VType>public 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 ShortObjectAssociativeContainer<VType>true 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 ShortObjectHashMap.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 ShortObjectAssociativeContainer<VType>iterator in interface java.lang.Iterable<ShortObjectCursor<VType>>public <T extends ShortObjectProcedure<? super VType>> T forEach(T procedure)
ShortObjectProcedure. 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 ShortObjectAssociativeContainer<VType>public <T extends ShortObjectPredicate<? super VType>> 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 ShortObjectPredicate. 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 ShortObjectAssociativeContainer<VType>public ShortObjectHashMap.KeysCollection keys()
keys in interface ShortObjectAssociativeContainer<VType>public ShortObjectHashMap.ValuesCollection values()
values in interface ShortObjectAssociativeContainer<VType>public ShortObjectHashMap<VType> clone()
clone in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic static <VType> ShortObjectHashMap<VType> from(short[] keys, VType[] values)
public static <VType> ShortObjectHashMap<VType> from(ShortObjectAssociativeContainer<VType> container)
public static <VType> ShortObjectHashMap<VType> newInstance()
public static <VType> ShortObjectHashMap<VType> newInstance(int initialCapacity, double loadFactor)
public VType getDefaultValue()
getDefaultValue in interface ShortObjectMap<VType>public void setDefaultValue(VType defaultValue)
setDefaultValue in interface ShortObjectMap<VType>Copyright © 2017. All rights reserved.