This class provides a dedicated map from integers to doubles with a
much smaller memory overhead than standard java.util.Map.
This class is not synchronized. The specialized iterators returned by
iterator() are fail-fast: they throw a
ConcurrentModificationException when they detect the map has been
modified during iteration.
| Modifier and Type | Class and Description |
|---|---|
| public class | OpenIntToDoubleHashMap.
Iterator class for the map. |
| Modifier and Type | Field and Description |
|---|---|
| private transient int | count
Modifications count. |
| private static final int | DEFAULT_EXPECTED_SIZE
Default starting size. |
| protected static final byte | FREE
Status indicator for free table entries. |
| protected static final byte | FULL
Status indicator for full table entries. |
| private int[] | keys
Keys table. |
| private static final float | LOAD_FACTOR
Load factor for the map. |
| private int | mask
Bit mask for hash values. |
| private final double | missingEntries
Return value for missing entries. |
| private static final int | PERTURB_SHIFT
Number of bits to perturb the index when probing for collision resolution. |
| protected static final byte | REMOVED
Status indicator for removed table entries. |
| private static final int | RESIZE_MULTIPLIER
Multiplier for size growth when map fills up. |
| private static final long | serialVersionUID
Serializable version identifier |
| private int | size
Current size of the map. |
| private byte[] | states
States table. |
| private double[] | values
Values table. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | OpenIntToDoubleHashMap(final double
value to return when a missing entry is fetched missingEntries)Build an empty map with default size |
| public | OpenIntToDoubleHashMap(final int
expected number of elements in the map expectedSize)Build an empty map with specified size and using NaN for missing entries. |
| public | OpenIntToDoubleHashMap(final int
expected number of elements in the map expectedSize, final double value to return when a missing entry is fetched missingEntries)Build an empty map with specified size. |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static int | |
| private static int | Returns: capacity to use for the specified sizeexpected size of the map expectedSize)Compute the capacity needed for a given size. |
| public boolean | Returns: true if a value is associated with keykey to check key)Check if a value is associated with a key. |
| private boolean | Returns: true if an element is associated with key at indexkey to check key, final int index to check index)Check if the tables contain an element associated with specified key at specified index. |
| private double | Returns: removed valueindex of the element to remove index)Remove an element at specified index. |
| private int | Returns: index at which key should be insertedkey to lookup key)Find the index at which a key should be inserted |
| private static int | Returns: index at which key should be insertedkeys table keys, final byte[] states table states, final int key to lookup key, final int bit mask for hash values mask)Find the index at which a key should be inserted |
| public double | Returns: data associated with the keykey associated with the data key)Get the stored value associated with the given key |
| private void | |
| private static int | |
| public OpenIntToDoubleHashMap. | |
| private static int | Returns: smallest power of two greater than the input valueinput value i)Find the smallest power of two greater than the input value |
| private static int | |
| private static int | Returns: next probeperturbed hash perturb, final int previous probe j)Compute next probe for collision resolution |
| public double | Returns: previous value associated with the keykey to which value is associated key, final double value to put in the map value)Put a value associated with a key in the map. |
| private void | |
| public double | Returns: removed valuekey to which the value is associated key)Remove the value associated with a key. |
| private boolean | Returns: true if tables should growCheck if tables should grow due to increased size. |
| public int |
| count | back to summary |
|---|---|
| private transient int count Modifications count. | |
| DEFAULT_EXPECTED_SIZE | back to summary |
|---|---|
| private static final int DEFAULT_EXPECTED_SIZE Default starting size. This must be a power of two for bit mask to work properly. | |
| FREE | back to summary |
|---|---|
| protected static final byte FREE Status indicator for free table entries. | |
| FULL | back to summary |
|---|---|
| protected static final byte FULL Status indicator for full table entries. | |
| keys | back to summary |
|---|---|
| private int[] keys Keys table. | |
| LOAD_FACTOR | back to summary |
|---|---|
| private static final float LOAD_FACTOR Load factor for the map. | |
| mask | back to summary |
|---|---|
| private int mask Bit mask for hash values. | |
| missingEntries | back to summary |
|---|---|
| private final double missingEntries Return value for missing entries. | |
| PERTURB_SHIFT | back to summary |
|---|---|
| private static final int PERTURB_SHIFT Number of bits to perturb the index when probing for collision resolution. | |
| REMOVED | back to summary |
|---|---|
| protected static final byte REMOVED Status indicator for removed table entries. | |
| RESIZE_MULTIPLIER | back to summary |
|---|---|
| private static final int RESIZE_MULTIPLIER Multiplier for size growth when map fills up. This must be a power of two for bit mask to work properly. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serializable version identifier | |
| size | back to summary |
|---|---|
| private int size Current size of the map. | |
| states | back to summary |
|---|---|
| private byte[] states States table. | |
| values | back to summary |
|---|---|
| private double[] values Values table. | |
| OpenIntToDoubleHashMap | back to summary |
|---|---|
| public OpenIntToDoubleHashMap() Build an empty map with default size and using NaN for missing entries. | |
| OpenIntToDoubleHashMap | back to summary |
|---|---|
| public OpenIntToDoubleHashMap(final double missingEntries) Build an empty map with default size
| |
| OpenIntToDoubleHashMap | back to summary |
|---|---|
| public OpenIntToDoubleHashMap(final int expectedSize) Build an empty map with specified size and using NaN for missing entries.
| |
| OpenIntToDoubleHashMap | back to summary |
|---|---|
| public OpenIntToDoubleHashMap(final int expectedSize, final double missingEntries) Build an empty map with specified size.
| |
| OpenIntToDoubleHashMap | back to summary |
|---|---|
| public OpenIntToDoubleHashMap(final OpenIntToDoubleHashMap source) Copy constructor.
| |
| changeIndexSign | back to summary |
|---|---|
| private static int changeIndexSign(final int index) Change the index sign
| |
| computeCapacity | back to summary |
|---|---|
| private static int computeCapacity(final int expectedSize) Compute the capacity needed for a given size.
| |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(final int key) Check if a value is associated with a key.
| |
| containsKey | back to summary |
|---|---|
| private boolean containsKey(final int key, final int index) Check if the tables contain an element associated with specified key at specified index.
| |
| doRemove | back to summary |
|---|---|
| private double doRemove(int index) Remove an element at specified index.
| |
| findInsertionIndex | back to summary |
|---|---|
| private int findInsertionIndex(final int key) Find the index at which a key should be inserted
| |
| findInsertionIndex | back to summary |
|---|---|
| private static int findInsertionIndex(final int[] keys, final byte[] states, final int key, final int mask) Find the index at which a key should be inserted
| |
| get | back to summary |
|---|---|
| public double get(final int key) Get the stored value associated with the given key
| |
| growTable | back to summary |
|---|---|
| private void growTable() Grow the tables. | |
| hashOf | back to summary |
|---|---|
| private static int hashOf(final int key) Compute the hash value of a key
| |
| iterator | back to summary |
|---|---|
| public OpenIntToDoubleHashMap. Get an iterator over map elements. The specialized iterators returned are fail-fast: they throw a
| |
| nextPowerOfTwo | back to summary |
|---|---|
| private static int nextPowerOfTwo(final int i) Find the smallest power of two greater than the input value
| |
| perturb | back to summary |
|---|---|
| private static int perturb(final int hash) Perturb the hash for starting probing.
| |
| probe | back to summary |
|---|---|
| private static int probe(final int perturb, final int j) Compute next probe for collision resolution
| |
| put | back to summary |
|---|---|
| public double put(final int key, final double value) Put a value associated with a key in the map.
| |
| readObject | back to summary |
|---|---|
| private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException Read a serialized object.
| |
| remove | back to summary |
|---|---|
| public double remove(final int key) Remove the value associated with a key.
| |
| shouldGrowTable | back to summary |
|---|---|
| private boolean shouldGrowTable() Check if tables should grow due to increased size.
| |
| size | back to summary |
|---|---|
| public int size() Get the number of elements stored in the map.
| |
| Modifier and Type | Field and Description |
|---|---|
| private int | current
Index of current element. |
| private int | next
Index of next element. |
| private final int | referenceCount
Reference modification count. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public boolean | |
| public int | |
| public double |
| current | back to summary |
|---|---|
| private int current Index of current element. | |
| next | back to summary |
|---|---|
| private int next Index of next element. | |
| referenceCount | back to summary |
|---|---|
| private final int referenceCount Reference modification count. | |
| Iterator | back to summary |
|---|---|
| private Iterator() Simple constructor. | |
| advance | back to summary |
|---|---|
| public void advance() throws ConcurrentModificationException, NoSuchElementException Advance iterator one step further.
| |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Check if there is a next element in the map.
| |
| key | back to summary |
|---|---|
| public int key() throws ConcurrentModificationException, NoSuchElementException Get the key of current entry.
| |
| value | back to summary |
|---|---|
| public double value() throws ConcurrentModificationException, NoSuchElementException Get the value of current entry.
| |