Top Description Inners Fields Constructors Methods
org.apache.commons.math3.util

public Class OpenIntToDoubleHashMap

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.IOException, .ObjectInputStream, .Serializable, java.util.ConcurrentModificationException, .NoSuchElementException

Open addressed map from int to double.

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.

Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
OpenIntToDoubleHashMap.Iterator

Iterator class for the map.

Field Summary

Modifier and TypeField 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.

Constructor Summary

AccessConstructor and Description
public
OpenIntToDoubleHashMap()

Build an empty map with default size and using NaN for missing entries.

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
OpenIntToDoubleHashMap(final OpenIntToDoubleHashMap
map to copy
source
)

Copy constructor.

Method Summary

Modifier and TypeMethod and Description
private static int

Returns:

changed index
changeIndexSign
(final int
initial index
index
)

Change the index sign

private static int

Returns:

capacity to use for the specified size
computeCapacity
(final int
expected size of the map
expectedSize
)

Compute the capacity needed for a given size.

public boolean

Returns:

true if a value is associated with key
containsKey
(final int
key to check
key
)

Check if a value is associated with a key.

private boolean

Returns:

true if an element is associated with key at index
containsKey
(final int
key 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 value
doRemove
(int
index of the element to remove
index
)

Remove an element at specified index.

private int

Returns:

index at which key should be inserted
findInsertionIndex
(final int
key to lookup
key
)

Find the index at which a key should be inserted

private static int

Returns:

index at which key should be inserted
findInsertionIndex
(final int[]
keys 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 key
get
(final int
key associated with the data
key
)

Get the stored value associated with the given key

private void
growTable()

Grow the tables.

private static int

Returns:

hash value of the key
hashOf
(final int
key to hash
key
)

Compute the hash value of a key

public OpenIntToDoubleHashMap.Iterator

Returns:

iterator over the map elements
iterator
()

Get an iterator over map elements.

private static int

Returns:

smallest power of two greater than the input value
nextPowerOfTwo
(final int
input value
i
)

Find the smallest power of two greater than the input value

private static int

Returns:

perturbed hash
perturb
(final int
initial hash
hash
)

Perturb the hash for starting probing.

private static int

Returns:

next probe
probe
(final int
perturbed hash
perturb
,
final int
previous probe
j
)

Compute next probe for collision resolution

public double

Returns:

previous value associated with the key
put
(final int
key 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
readObject(final ObjectInputStream
input stream
stream
)

Read a serialized object.

public double

Returns:

removed value
remove
(final int
key to which the value is associated
key
)

Remove the value associated with a key.

private boolean

Returns:

true if tables should grow
shouldGrowTable
()

Check if tables should grow due to increased size.

public int

Returns:

number of elements stored in the map
size
()

Get the number of elements stored in the map.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
private transient int count

Modifications count.

DEFAULT_EXPECTED_SIZEback 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.

FREEback to summary
protected static final byte FREE

Status indicator for free table entries.

FULLback to summary
protected static final byte FULL

Status indicator for full table entries.

keysback to summary
private int[] keys

Keys table.

LOAD_FACTORback to summary
private static final float LOAD_FACTOR

Load factor for the map.

maskback to summary
private int mask

Bit mask for hash values.

missingEntriesback to summary
private final double missingEntries

Return value for missing entries.

PERTURB_SHIFTback to summary
private static final int PERTURB_SHIFT

Number of bits to perturb the index when probing for collision resolution.

REMOVEDback to summary
protected static final byte REMOVED

Status indicator for removed table entries.

RESIZE_MULTIPLIERback 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.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier

sizeback to summary
private int size

Current size of the map.

statesback to summary
private byte[] states

States table.

valuesback to summary
private double[] values

Values table.

Constructor Detail

OpenIntToDoubleHashMapback to summary
public OpenIntToDoubleHashMap()

Build an empty map with default size and using NaN for missing entries.

OpenIntToDoubleHashMapback to summary
public OpenIntToDoubleHashMap(final double missingEntries)

Build an empty map with default size

Parameters
missingEntries:double

value to return when a missing entry is fetched

OpenIntToDoubleHashMapback to summary
public OpenIntToDoubleHashMap(final int expectedSize)

Build an empty map with specified size and using NaN for missing entries.

Parameters
expectedSize:int

expected number of elements in the map

OpenIntToDoubleHashMapback to summary
public OpenIntToDoubleHashMap(final int expectedSize, final double missingEntries)

Build an empty map with specified size.

Parameters
expectedSize:int

expected number of elements in the map

missingEntries:double

value to return when a missing entry is fetched

OpenIntToDoubleHashMapback to summary
public OpenIntToDoubleHashMap(final OpenIntToDoubleHashMap source)

Copy constructor.

Parameters
source:OpenIntToDoubleHashMap

map to copy

Method Detail

changeIndexSignback to summary
private static int changeIndexSign(final int index)

Change the index sign

Parameters
index:int

initial index

Returns:int

changed index

computeCapacityback to summary
private static int computeCapacity(final int expectedSize)

Compute the capacity needed for a given size.

Parameters
expectedSize:int

expected size of the map

Returns:int

capacity to use for the specified size

containsKeyback to summary
public boolean containsKey(final int key)

Check if a value is associated with a key.

Parameters
key:int

key to check

Returns:boolean

true if a value is associated with key

containsKeyback 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.

Parameters
key:int

key to check

index:int

index to check

Returns:boolean

true if an element is associated with key at index

doRemoveback to summary
private double doRemove(int index)

Remove an element at specified index.

Parameters
index:int

index of the element to remove

Returns:double

removed value

findInsertionIndexback to summary
private int findInsertionIndex(final int key)

Find the index at which a key should be inserted

Parameters
key:int

key to lookup

Returns:int

index at which key should be inserted

findInsertionIndexback 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

Parameters
keys:int[]

keys table

states:byte[]

states table

key:int

key to lookup

mask:int

bit mask for hash values

Returns:int

index at which key should be inserted

getback to summary
public double get(final int key)

Get the stored value associated with the given key

Parameters
key:int

key associated with the data

Returns:double

data associated with the key

growTableback to summary
private void growTable()

Grow the tables.

hashOfback to summary
private static int hashOf(final int key)

Compute the hash value of a key

Parameters
key:int

key to hash

Returns:int

hash value of the key

iteratorback to summary
public OpenIntToDoubleHashMap.Iterator iterator()

Get an iterator over map elements.

The specialized iterators returned are fail-fast: they throw a ConcurrentModificationException when they detect the map has been modified during iteration.

Returns:OpenIntToDoubleHashMap.Iterator

iterator over the map elements

nextPowerOfTwoback to summary
private static int nextPowerOfTwo(final int i)

Find the smallest power of two greater than the input value

Parameters
i:int

input value

Returns:int

smallest power of two greater than the input value

perturbback to summary
private static int perturb(final int hash)

Perturb the hash for starting probing.

Parameters
hash:int

initial hash

Returns:int

perturbed hash

probeback to summary
private static int probe(final int perturb, final int j)

Compute next probe for collision resolution

Parameters
perturb:int

perturbed hash

j:int

previous probe

Returns:int

next probe

putback to summary
public double put(final int key, final double value)

Put a value associated with a key in the map.

Parameters
key:int

key to which value is associated

value:double

value to put in the map

Returns:double

previous value associated with the key

readObjectback to summary
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException

Read a serialized object.

Parameters
stream:ObjectInputStream

input stream

Exceptions
IOException:
if object cannot be read
ClassNotFoundException:
if the class corresponding to the serialized object cannot be found
removeback to summary
public double remove(final int key)

Remove the value associated with a key.

Parameters
key:int

key to which the value is associated

Returns:double

removed value

shouldGrowTableback to summary
private boolean shouldGrowTable()

Check if tables should grow due to increased size.

Returns:boolean

true if tables should grow

sizeback to summary
public int size()

Get the number of elements stored in the map.

Returns:int

number of elements stored in the map

org.apache.commons.math3.util back to summary

public Class OpenIntToDoubleHashMap.Iterator

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator

Iterator class for the map.

Field Summary

Modifier and TypeField and Description
private int
current

Index of current element.

private int
next

Index of next element.

private final int
referenceCount

Reference modification count.

Constructor Summary

AccessConstructor and Description
private
Iterator()

Simple constructor.

Method Summary

Modifier and TypeMethod and Description
public void
advance()

Advance iterator one step further.

public boolean

Returns:

true if there is a next element
hasNext
()

Check if there is a next element in the map.

public int

Returns:

key of current entry
key
()

Get the key of current entry.

public double

Returns:

value of current entry
value
()

Get the value of current entry.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentback to summary
private int current

Index of current element.

nextback to summary
private int next

Index of next element.

referenceCountback to summary
private final int referenceCount

Reference modification count.

Constructor Detail

Iteratorback to summary
private Iterator()

Simple constructor.

Method Detail

advanceback to summary
public void advance() throws ConcurrentModificationException, NoSuchElementException

Advance iterator one step further.

Exceptions
ConcurrentModificationException:
if the map is modified during iteration
NoSuchElementException:
if there is no element left in the map
hasNextback to summary
public boolean hasNext()

Check if there is a next element in the map.

Returns:boolean

true if there is a next element

keyback to summary
public int key() throws ConcurrentModificationException, NoSuchElementException

Get the key of current entry.

Returns:int

key of current entry

Exceptions
ConcurrentModificationException:
if the map is modified during iteration
NoSuchElementException:
if there is no element left in the map
valueback to summary
public double value() throws ConcurrentModificationException, NoSuchElementException

Get the value of current entry.

Returns:double

value of current entry

Exceptions
ConcurrentModificationException:
if the map is modified during iteration
NoSuchElementException:
if there is no element left in the map