public class LongFloatMap extends java.lang.Object implements java.lang.Iterable<LongFloatMap.Entry>
| Modifier and Type | Class and Description |
|---|---|
static class |
LongFloatMap.Entries |
static class |
LongFloatMap.Entry |
static class |
LongFloatMap.Keys |
static class |
LongFloatMap.Values |
| Modifier and Type | Field and Description |
|---|---|
protected int |
mask
A bitmask used to confine hashcodes to the size of the table.
|
protected int |
shift
|
int |
size |
| Constructor and Description |
|---|
LongFloatMap()
Creates a new map with an initial capacity of 51 and a load factor of 0.8.
|
LongFloatMap(int initialCapacity)
Creates a new map with a load factor of 0.8.
|
LongFloatMap(int initialCapacity,
float loadFactor)
Creates a new map with the specified initial capacity and load factor.
|
LongFloatMap(LongFloatMap map)
Creates a new map identical to the specified map.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
void |
clear(int maximumCapacity)
Clears the map and reduces the size of the backing arrays to be the specified capacity / loadFactor, if they are larger.
|
boolean |
containsKey(long key) |
boolean |
containsValue(float value)
Returns true if the specified value is in the map.
|
boolean |
containsValue(float value,
float epsilon)
Returns true if the specified value is in the map.
|
void |
ensureCapacity(int additionalCapacity)
Increases the size of the backing array to accommodate the specified number of additional items / loadFactor.
|
LongFloatMap.Entries |
entries() |
boolean |
equals(java.lang.Object obj) |
long |
findKey(float value,
float epsilon,
long notFound)
Returns the key for the specified value, or notFound if it is not in the map.
|
long |
findKey(float value,
long notFound)
Returns the key for the specified value, or notFound if it is not in the map.
|
float |
get(long key,
float defaultValue) |
float |
getAndIncrement(long key,
float defaultValue,
float increment)
Returns the key's current value and increments the stored value.
|
int |
hashCode() |
boolean |
isEmpty()
Returns true if the map is empty.
|
java.util.Iterator<LongFloatMap.Entry> |
iterator() |
LongFloatMap.Keys |
keys()
Returns an iterator for the keys in the map.
|
boolean |
notEmpty()
Returns true if the map has one or more items.
|
protected int |
place(long item)
Returns an index >= 0 and <=
mask for the specified item. |
void |
put(long key,
float value) |
float |
put(long key,
float value,
float defaultValue)
Returns the old value associated with the specified key, or the specified default value.
|
void |
putAll(LongFloatMap map) |
float |
remove(long key,
float defaultValue)
Returns the value for the removed key, or the default value if the key is not in the map.
|
void |
shrink(int maximumCapacity)
Reduces the size of the backing arrays to be the specified capacity / loadFactor, or less.
|
java.lang.String |
toString() |
LongFloatMap.Values |
values() |
public int size
protected int shift
place(long) to bit shift the upper bits of a long into a usable range (>= 0 and <=
mask). The shift can be negative, which is convenient to match the number of bits in mask: if mask is a 7-bit
number, a shift of -7 shifts the upper 7 bits into the lowest 7 positions. This class sets the shift > 32 and < 64,
which if used with an int will still move the upper bits of an int to the lower bits due to Java's implicit modulus on
shifts.
mask can also be used to mask the low bits of a number, which may be faster for some hashcodes, if
place(long) is overridden.
protected int mask
place(long) is overriden, this can be used instead of shift to isolate usable bits of a
hash.public LongFloatMap()
public LongFloatMap(int initialCapacity)
initialCapacity - If not a power of two, it is increased to the next nearest power of two.public LongFloatMap(int initialCapacity,
float loadFactor)
initialCapacity - If not a power of two, it is increased to the next nearest power of two.public LongFloatMap(LongFloatMap map)
protected int place(long item)
mask for the specified item.
The default implementation uses Fibonacci hashing on the item's Object.hashCode(): the hashcode is multiplied by a
long constant (2 to the 64th, divided by the golden ratio) then the uppermost bits are shifted into the lowest positions to
obtain an index in the desired range. Multiplication by a long may be slower than int (eg on GWT) but greatly improves
rehashing, allowing even very poor hashcodes, such as those that only differ in their upper bits, to be used without high
collision rates. Fibonacci hashing has increased collision rates when all or most hashcodes are multiples of larger
Fibonacci numbers (see Malte
Skarupke's blog post).
This method can be overriden to customizing hashing. This may be useful eg in the unlikely event that most hashcodes are
Fibonacci numbers, if keys provide poor or incorrect hashcodes, or to simplify hashing if keys provide high quality
hashcodes and don't need Fibonacci hashing: return item.hashCode() & mask;
public void put(long key,
float value)
public float put(long key,
float value,
float defaultValue)
defaultValue - Float.NaN can be used for a value unlikely to be in the map.public void putAll(LongFloatMap map)
public float get(long key,
float defaultValue)
defaultValue - Float.NaN can be used for a value unlikely to be in the map.public float getAndIncrement(long key,
float defaultValue,
float increment)
public float remove(long key,
float defaultValue)
defaultValue - Float.NaN can be used for a value unlikely to be in the map.public boolean notEmpty()
public boolean isEmpty()
public void shrink(int maximumCapacity)
public void clear(int maximumCapacity)
public void clear()
public boolean containsValue(float value)
public boolean containsValue(float value,
float epsilon)
public boolean containsKey(long key)
public long findKey(float value,
long notFound)
public long findKey(float value,
float epsilon,
long notFound)
public void ensureCapacity(int additionalCapacity)
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.util.Iterator<LongFloatMap.Entry> iterator()
iterator in interface java.lang.Iterable<LongFloatMap.Entry>public LongFloatMap.Entries entries()
public LongFloatMap.Values values()
public LongFloatMap.Keys keys()
If Collections.allocateIterators is false, the same iterator instance is returned each time this method is called.
Use the LongFloatMap.Entries constructor for nested or multithreaded iteration.