public class ReferenceCountMap
extends java.lang.Object
Object
keys. The map implementation is not very efficient when
resizing, but works well when the size of the map is known in advance or when accesses are substantially more common
than adds.Modifier and Type | Field and Description |
---|---|
private static double |
DEFAULT_FILL
Default fill fraction allowed before growing table.
|
private int |
m_arraySize
Size of array used for keys.
|
private int |
m_entryCount
Number of entries present in table.
|
private int |
m_entryLimit
Entries allowed before growing table.
|
private int |
m_hitOffset
Offset added (modulo table size) to slot number on collision.
|
private java.lang.Object[] |
m_keyTable
Array of key table slots.
|
private int[] |
m_valueTable
Array of value table slots.
|
private static int |
MINIMUM_SIZE
Minimum size used for hash table.
|
Constructor and Description |
---|
ReferenceCountMap()
Default constructor.
|
ReferenceCountMap(int count)
Constructor with count.
|
ReferenceCountMap(ReferenceCountMap base)
Copy (clone) constructor.
|
Modifier and Type | Method and Description |
---|---|
private int |
assignSlot(java.lang.Object key,
int value)
Assign slot for entry.
|
void |
clear()
Clear all keys and counts.
|
java.lang.Object |
clone()
Construct a copy of the table.
|
private int |
freeSlot(int slot)
Find free slot number for entry.
|
int |
getCount(java.lang.Object key)
Find an entry in the table.
|
int |
incrementCount(java.lang.Object key)
Increment a use count in the table.
|
private void |
internalRemove(int slot)
Internal remove pair from the table.
|
java.util.Iterator |
iterator()
Get iterator for keys in map.
|
java.lang.Object[] |
keyArray()
Get array of keys in map.
|
private boolean |
reinsert(int slot)
Reinsert an entry into the hash map.
|
private void |
restructure(java.lang.Object[] keys,
int[] values)
Restructure the table.
|
int |
size()
Get number of entries in map.
|
private int |
standardFind(java.lang.Object key)
Standard find key in table.
|
private int |
standardSlot(java.lang.Object key)
Standard base slot computation for a key.
|
private int |
stepSlot(int slot)
Step the slot number for an entry.
|
private static final double DEFAULT_FILL
private static final int MINIMUM_SIZE
private int m_entryCount
private int m_entryLimit
private int m_arraySize
private int m_hitOffset
private java.lang.Object[] m_keyTable
private int[] m_valueTable
public ReferenceCountMap(int count)
count
- number of values to assume in initial sizing of tablepublic ReferenceCountMap()
public ReferenceCountMap(ReferenceCountMap base)
base
- instance being copiedprivate final int stepSlot(int slot)
slot
- slot number to be steppedprivate final int freeSlot(int slot)
slot
- initial slot computed from keyprivate final int standardSlot(java.lang.Object key)
key
- key value to be computedprivate int standardFind(java.lang.Object key)
hashCode()
method defined for the key objects or the System.identityHashCode()
method, and either the equals()
method defined for the key objects or the ==
operator, as selected by the hash technique constructor parameter. To implement a hash class based on some other
methods of hashing and/or equality testing, define a separate method in the subclass with a different name and
use that method instead. This avoids the overhead caused by overrides of a very heavily used method.key
- to be found in table-index-1
of slot to be used for inserting key in table if not
already present (always negative)private boolean reinsert(int slot)
slot
- position of entry to be reinserted into hash maptrue
if the slot number used by the entry has has changed, false
if notprivate void internalRemove(int slot)
null
and adjusting the count present, then chains through the table to reinsert any other pairs
which may have collided with the removed pair. If the associated value is an object reference, it should be set
to null
before this method is called.slot
- index number of pair to be removedprivate void restructure(java.lang.Object[] keys, int[] values)
keys
- array of keysvalues
- array of valuesprivate int assignSlot(java.lang.Object key, int value)
key
- to be added to tablevalue
- associated value for keypublic int incrementCount(java.lang.Object key)
key
- referenced object (non-null
)public final int getCount(java.lang.Object key)
key
- key for entry to be returnedpublic int size()
public java.util.Iterator iterator()
public java.lang.Object[] keyArray()
public java.lang.Object clone()
clone
in class java.lang.Object
public void clear()