T
- type of objects to store in this mappublic class FastAccessNumberMap<T>
extends java.lang.Object
implements java.lang.Iterable<T>
pageSize*maxPageCount
at the cost of high memory use. Values are kept in dynamically
allocated pages, each of a fixed size.
It can be thought of as a big array that is split up into pages of a fixed size. This is useful if you want to use a sparse set of indexes since you don't have to allocate the full array immediately. If you are going to fill all indexes then it is more practical to use a normal array or list.
If you try to access an index outside of the max page count then an overflow hash map is used as a fallback mechanism. In that case access will be slower than O(1).
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Long,T> |
overflow |
private java.lang.Object[][] |
pages |
private int |
pageSize |
private int |
pagesUpperLimit |
Constructor and Description |
---|
FastAccessNumberMap()
Constructs a map with O(1) access up to index 5000.
|
FastAccessNumberMap(int pageSize,
int maxPageCount)
Constructs a map with O(1) access up to index
pageSize*maxPageCount . |
Modifier and Type | Method and Description |
---|---|
T |
get(long index)
Get the value at an index.
|
private T |
getLow(int index) |
private java.util.Map<java.lang.Long,T> |
getOverflowMap() |
private java.lang.Object[] |
getPage(int pageIndex) |
java.util.Iterator<T> |
iterator() |
void |
put(long index,
T value)
Store a value at an index.
|
private void |
putLow(int index,
T object) |
private final int pagesUpperLimit
private final int pageSize
private java.lang.Object[][] pages
private java.util.Map<java.lang.Long,T> overflow
public FastAccessNumberMap()
public FastAccessNumberMap(int pageSize, int maxPageCount)
pageSize*maxPageCount
.pageSize
- page sizemaxPageCount
- max page countprivate java.lang.Object[] getPage(int pageIndex)
private T getLow(int index)
private void putLow(int index, T object)
public T get(long index)
index
- value indexpublic void put(long index, T value)
index
- value indexvalue
- value to storeprivate java.util.Map<java.lang.Long,T> getOverflowMap()