|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectIntMultiMap
public class IntMultiMap
This class efficiently implements a "one to many" relationship between integer keys and multiple integer values. The maximum key ID is fixed at construction time, but the number of values can grow insanely large, without large penalties for resizing arrays, etc.
Nested Class Summary | |
---|---|
private class |
IntMultiMap.Block
Keeps track of a block of values, with links to the following values. |
Field Summary | |
---|---|
private static int |
BLOCK_SIZE
|
private IntMultiMap.Block[] |
blocks
|
private IntMultiMap.Block |
curBlock
|
private short |
curBlockNum
|
private short |
curBlockTop
|
private int[] |
keyLinks
|
static Tester |
tester
Basic regression test |
Constructor Summary | |
---|---|
IntMultiMap(int maxKey)
Initialize the mapping table. |
Method Summary | |
---|---|
void |
add(int key,
int value)
Add a new association between a key and a value. |
long |
byteSize()
Calculate the size in bytes of the major structures of the map. |
int |
firstPos(int key)
For iteration: get the first position for the given key, or -1 if it has none. |
int |
getValue(int pos)
Retrieve the value for a given link. |
int |
nextPos(int prevPos)
For iteration: get the next position after the given pos, or -1 if we're at the end of the chain. |
void |
reverseOrder()
Reverse the order of all links. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private int[] keyLinks
private static final int BLOCK_SIZE
private IntMultiMap.Block[] blocks
private short curBlockNum
private IntMultiMap.Block curBlock
private short curBlockTop
public static final Tester tester
Constructor Detail |
---|
public IntMultiMap(int maxKey)
maxKey
- One larger than the largest key value that will ever be
passed to add(int, int)
. Note that the mapping
cannot be expanded.Method Detail |
---|
public long byteSize()
public void add(int key, int value)
public void reverseOrder()
public final int firstPos(int key)
public final int nextPos(int prevPos)
public final int getValue(int pos)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |