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