Class FastAccessNumberMap<T>
- java.lang.Object
-
- org.openjdk.jmc.common.collection.FastAccessNumberMap<T>
-
- Type Parameters:
T
- type of objects to store in this map
- All Implemented Interfaces:
Iterable<T>
public class FastAccessNumberMap<T> extends Object implements Iterable<T>
A map from long to T. Gives O(1) access to indexes that are between 0 andpageSize*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).
-
-
Constructor Summary
Constructors Constructor Description FastAccessNumberMap()
Constructs a map with O(1) access up to approximately index 5000.FastAccessNumberMap(int expectedSize)
Constructs a map with O(1) access up to indexexpectedSize
.FastAccessNumberMap(int pageSize, int maxPageCount)
Constructs a map with O(1) access up to indexpageSize*maxPageCount
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
get(long index)
Get the value at an index.Iterator<T>
iterator()
void
put(long index, T value)
Store a value at an index.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
FastAccessNumberMap
public FastAccessNumberMap()
Constructs a map with O(1) access up to approximately index 5000.
-
FastAccessNumberMap
public FastAccessNumberMap(int expectedSize)
Constructs a map with O(1) access up to indexexpectedSize
.- Parameters:
expectedSize
- - the maximum number of elements expected to be inserted into the map before overflowing to slower storage.
-
FastAccessNumberMap
public FastAccessNumberMap(int pageSize, int maxPageCount)
Constructs a map with O(1) access up to indexpageSize*maxPageCount
.- Parameters:
pageSize
- page sizemaxPageCount
- max page count
-
-