public class ArrayMap<T> extends Object
ArrayMap
class implements an efficient one-level map which is implemented as an
array. Note that because of the one-level array inside, this data structure performs best when
the range of integer keys is small and densely used. Note that the implementation can handle
arbitrary intervals, including negative numbers, up to intervals of size 2^31 - 1.Modifier and Type | Field and Description |
---|---|
private static int |
EXTRA |
private static int |
INITIAL_SIZE |
(package private) int |
low |
(package private) Object[] |
map |
Constructor and Description |
---|
ArrayMap()
Constructs a new
ArrayMap with no initial assumptions. |
ArrayMap(int low,
int high)
Constructs a new
ArrayMap that initially covers the specified interval. |
Modifier and Type | Method and Description |
---|---|
T |
get(int i)
Gets the value at the specified index in the map.
|
private void |
growBackward(int i,
T value) |
private void |
growForward(int i,
T value) |
int |
length() |
void |
put(int i,
T value)
Puts a new value in the map at the specified index.
|
private static final int INITIAL_SIZE
private static final int EXTRA
int low
public ArrayMap()
ArrayMap
with no initial assumptions.public ArrayMap(int low, int high)
ArrayMap
that initially covers the specified interval. Note that
this map will automatically expand if necessary later.low
- the low index, inclusivehigh
- the high index, exclusivepublic void put(int i, T value)
i
- the index at which to store the valuevalue
- the value to store at the specified indexpublic T get(int i)
i
- the indexnull
if there is no value at the specified
index, or if the index is out of the currently stored rangepublic int length()
private void growBackward(int i, T value)
private void growForward(int i, T value)