|
Parsing Engine | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,Object>
danbikel.util.AbstractMapToPrimitive<K>
danbikel.util.HashMapPrimitive<K>
public abstract class HashMapPrimitive<K>
A home-grown hash map from objects to indexed sequences of primitives.
Concrete implementations need only provide a map entry implementation and
provide a concrete implementation of the getNewEntry(int, Object,
HashMapPrimitive.Entry)
method.
Nested Class Summary | |
---|---|
static class |
HashMapPrimitive.Entry<K>
A still-abstract extension of the AbstractMapToPrimitive.Entry that
adds a next pointer and an int to cache the hash value of the
key held by this entry. |
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V> |
Field Summary | |
---|---|
protected static int |
defaultInitialCapacity
The default initial capacity, 11. |
protected static float |
defaultLoadFactor
The default load factor, 0.75f. |
protected static int |
hashCodeBitmask
The hash code bit mask, 0x7fffffff . |
protected static BigInteger |
maxCapacity
The maximum capacity (number of buckets) of this hash map, Integer.MAX_VALUE . |
Constructor Summary | |
---|---|
HashMapPrimitive()
Constructs a new map from objects to primitive values, using the default initial capacity and the default load factor. |
|
HashMapPrimitive(int initialCapacity)
Constructs a new map from objects to primitive values, using the default load factory |
|
HashMapPrimitive(int initialCapacity,
float loadFactor)
Constructs a new map from objects to primitive values. |
|
HashMapPrimitive(Map<? extends K,Object> map)
|
Method Summary | |
---|---|
void |
add(K key,
int index,
byte addend)
Adds the specified addend to the byte value at the specified
index associated with the specified key, or if no mapping previously
existed for the specified key, then this method adds a new map entry
mapping the key to the specified addend at the specified index. |
void |
add(K key,
int index,
double addend)
Adds the specified addend to the double value at the specified
index associated with the specified key, or if no mapping previously
existed for the specified key, then this method adds a new map entry
mapping the key to the specified addend at the specified index. |
void |
add(K key,
int index,
float addend)
Adds the specified addend to the float value at the specified
index associated with the specified key, or if no mapping previously
existed for the specified key, then this method adds a new map entry
mapping the key to the specified addend at the specified index. |
void |
add(K key,
int index,
int addend)
Adds the specified addend to the int value at the specified
index associated with the specified key, or if no mapping previously
existed for the specified key, then this method adds a new map entry
mapping the key to the specified addend at the specified index. |
void |
add(K key,
int index,
long addend)
Adds the specified addend to the long value at the specified
index associated with the specified key, or if no mapping previously
existed for the specified key, then this method adds a new map entry
mapping the key to the specified addend at the specified index. |
void |
add(K key,
int index,
short addend)
Adds the specified addend to the short value at the specified
index associated with the specified key, or if no mapping previously
existed for the specified key, then this method adds a new map entry
mapping the key to the specified addend at the specified index. |
protected void |
addEntryMRU(HashMapPrimitive.Entry entry)
Adds the specified entry to the beginning of the singly-linked list at its bucket index (indicating it is the most-recently used entry). |
boolean |
containsKey(Object key)
|
Set<Map.Entry<K,Object>> |
entrySet()
|
Object |
get(K key,
int hashCode)
Returns the value for the specified key. |
int |
getCapacity()
Gets the capacity of this map (optional operation). |
MapToPrimitive.Entry<K> |
getEntry(K key)
Gets the map entry associated with the specified key, or null
if this map does not contain such a mapping. |
MapToPrimitive.Entry<K> |
getEntry(K key,
int hashCode)
Returns the entry associated with the specified key, or null
if no such entry exists. |
MapToPrimitive.Entry<K> |
getEntryMRU(K key)
Gets the map entry for the specified key and, as a side-effect, puts the map entry at the front of the bucket list, indicating that it is the most-recently used entry (useful for caches implementing a bucket-LRU replacement scheme). |
MapToPrimitive.Entry<K> |
getEntryMRU(K key,
int hashCode)
|
float |
getLoadFactor()
Gets the load factor of this map (optional operation). |
protected abstract HashMapPrimitive.Entry<K> |
getNewEntry(int hash,
K key,
HashMapPrimitive.Entry<K> next)
The method used when constructing map entries for concrete subclasses. |
protected MapToPrimitive.Entry<K> |
getOrCreateEntry(K key)
Returns the entry associated with the specified key, or, if no such entry exists, creates one and returns it. |
String |
getStats()
Returns a string that represents the useful statistics of this map (useful/necessary in the case of hash maps, where it is desirable to know the number of collisions and average and maximum buckets sizes). |
byte |
put(K key,
int index,
byte value)
|
char |
put(K key,
int index,
char value)
|
double |
put(K key,
int index,
double value)
|
float |
put(K key,
int index,
float value)
|
int |
put(K key,
int index,
int value)
|
long |
put(K key,
int index,
long value)
|
short |
put(K key,
int index,
short value)
|
Object |
put(K key,
Object value)
Throws an UnsupportedOperationException . |
Object |
remove(Object key)
Removes the entry for the specified key. |
protected MapToPrimitive.Entry |
removeLRU(int hashCode)
Removes the last entry at the specified bucket index, if that bucket contains at least one entry. |
protected MapToPrimitive.Entry |
removeLRU(K key)
|
void |
removeRandom(int bucketIndex)
Removes a random entry from the bucket at the specified index (optional operation). |
Methods inherited from class danbikel.util.AbstractMapToPrimitive |
---|
add, add, add, add, add, add, put, put, put, put, put, put, put, removeRandom, toString |
Methods inherited from class java.util.AbstractMap |
---|
clear, clone, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, size, values |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
clear, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, size, values |
Field Detail |
---|
protected static final float defaultLoadFactor
protected static final int defaultInitialCapacity
protected static final int hashCodeBitmask
0x7fffffff
.
protected static final BigInteger maxCapacity
Integer.MAX_VALUE
.
Constructor Detail |
---|
public HashMapPrimitive()
defaultInitialCapacity
,
defaultLoadFactor
public HashMapPrimitive(int initialCapacity)
initialCapacity
- the initial capacity of this mappublic HashMapPrimitive(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacity of this maploadFactor
- the load factor of this mappublic HashMapPrimitive(Map<? extends K,Object> map)
Method Detail |
---|
protected abstract HashMapPrimitive.Entry<K> getNewEntry(int hash, K key, HashMapPrimitive.Entry<K> next)
hash
- the hash value of the key of the new entrykey
- the key of the new entrynext
- the next pointer of the new entry’s singly-linked list
public Object remove(Object key)
Map.remove(Object)
, this method does not return the value
associated with the key, because that value could be one or more primitive
values.
remove
in interface Map<K,Object>
remove
in class AbstractMap<K,Object>
key
- the key of the entry to remove
null
public boolean containsKey(Object key)
containsKey
in interface Map<K,Object>
containsKey
in class AbstractMap<K,Object>
public Object put(K key, Object value)
UnsupportedOperationException
.
put
in interface Map<K,Object>
put
in class AbstractMap<K,Object>
key
- ignoredvalue
- ignored
UnsupportedOperationException
- under all circumstancespublic MapToPrimitive.Entry<K> getEntry(K key)
null
if this map does not contain such a mapping.
getEntry
in interface MapToPrimitive<K>
getEntry
in class AbstractMapToPrimitive<K>
key
- the key for which to look up a map entry
null
if no
such mapping exists in this mapprotected MapToPrimitive.Entry<K> getOrCreateEntry(K key)
key
- the key for which to return or create a map entry
public MapToPrimitive.Entry<K> getEntry(K key, int hashCode)
null
if no such entry exists. It is an error to invoke this method with a hash
code that is not equal to key.hashCode()
.
getEntry
in interface MapToPrimitive<K>
key
- the key for which to retrieve its map entryhashCode
- the hash code for the specified key
null
if no such entry existspublic MapToPrimitive.Entry<K> getEntryMRU(K key)
getEntryMRU
in interface MapToPrimitive<K>
getEntryMRU
in class AbstractMapToPrimitive<K>
key
- the key whose map entry is to be retrieved and made the MRU in
its bucket inside the hash map
UnsupportedOperationException
- if this map is not a hash mappublic MapToPrimitive.Entry<K> getEntryMRU(K key, int hashCode)
getEntryMRU
in interface MapToPrimitive<K>
protected void addEntryMRU(HashMapPrimitive.Entry entry)
entry
- the entry to add as most-recently used in its bucketprotected MapToPrimitive.Entry removeLRU(K key)
protected MapToPrimitive.Entry removeLRU(int hashCode)
hashCode
- the hashCode of an object whose bucket is to be emptied of
its least-recently-used entry
null
if no entry was removedpublic void removeRandom(int bucketIndex)
removeRandom
in interface MapToPrimitive<K>
removeRandom
in class AbstractMapToPrimitive<K>
bucketIndex
- the index of the bucket from which to remove an element
IllegalArgumentException
- if
0 <= bucketIndex < getCapacity()is
false
UnsupportedOperationException
- if this map is not a hash mappublic int getCapacity()
FlexibleMap
getCapacity
in interface FlexibleMap<K,Object>
public float getLoadFactor()
FlexibleMap
getLoadFactor
in interface FlexibleMap<K,Object>
public String getStats()
FlexibleMap
getStats
in interface FlexibleMap<K,Object>
public Object get(K key, int hashCode)
FlexibleMap
key.hashCode()
, the behavior of thiscollins
method is not defined.
get
in interface FlexibleMap<K,Object>
key
- the key whose value is to be looked uphashCode
- the value of key.hashCode()
public byte put(K key, int index, byte value)
put
in interface MapToPrimitive<K>
put
in class AbstractMapToPrimitive<K>
public void add(K key, int index, byte addend)
AbstractMapToPrimitive
byte
value at the specified
index associated with the specified key, or if no mapping previously
existed for the specified key, then this method adds a new map entry
mapping the key to the specified addend at the specified index. If this
map maps keys to multiple byte
values, then the other
byte
s will be set to their default instance-variable value,
0.
add
in interface MapToPrimitive<K>
add
in class AbstractMapToPrimitive<K>
key
- the key whose byte
value is to be incremented,
or for which a mapping is to be added to the specified addendindex
- the index of the byte
value to be incrementedaddend
- the amount by which to increment the byte
value
for the specified keypublic char put(K key, int index, char value)
put
in interface MapToPrimitive<K>
put
in class AbstractMapToPrimitive<K>
public short put(K key, int index, short value)
put
in interface MapToPrimitive<K>
put
in class AbstractMapToPrimitive<K>
public void add(K key, int index, short addend)
AbstractMapToPrimitive
short
value at the specified
index associated with the specified key, or if no mapping previously
existed for the specified key, then this method adds a new map entry
mapping the key to the specified addend at the specified index. If this
map maps keys to multiple short
values, then the other
short
s will be set to their default instance-variable value,
0.
add
in interface MapToPrimitive<K>
add
in class AbstractMapToPrimitive<K>
key
- the key whose short
value is to be incremented,
or for which a mapping is to be added to the specified addendindex
- the index of the short
value to be incrementedaddend
- the amount by which to increment the short
value
for the specified keypublic int put(K key, int index, int value)
put
in interface MapToPrimitive<K>
put
in class AbstractMapToPrimitive<K>
public void add(K key, int index, int addend)
AbstractMapToPrimitive
int
value at the specified
index associated with the specified key, or if no mapping previously
existed for the specified key, then this method adds a new map entry
mapping the key to the specified addend at the specified index. If this
map maps keys to multiple int
values, then the other
int
s will be set to their default instance-variable value,
0.
add
in interface MapToPrimitive<K>
add
in class AbstractMapToPrimitive<K>
key
- the key whose int
value is to be incremented,
or for which a mapping is to be added to the specified addendindex
- the index of the int
value to be incrementedaddend
- the amount by which to increment the int
value
for the specified keypublic long put(K key, int index, long value)
put
in interface MapToPrimitive<K>
put
in class AbstractMapToPrimitive<K>
public void add(K key, int index, long addend)
AbstractMapToPrimitive
long
value at the specified
index associated with the specified key, or if no mapping previously
existed for the specified key, then this method adds a new map entry
mapping the key to the specified addend at the specified index. If this
map maps keys to multiple long
values, then the other
long
s will be set to their default instance-variable value,
0.
add
in interface MapToPrimitive<K>
add
in class AbstractMapToPrimitive<K>
key
- the key whose long
value is to be incremented,
or for which a mapping is to be added to the specified addendindex
- the index of the long
value to be incrementedaddend
- the amount by which to increment the long
value
for the specified keypublic float put(K key, int index, float value)
put
in interface MapToPrimitive<K>
put
in class AbstractMapToPrimitive<K>
public void add(K key, int index, float addend)
AbstractMapToPrimitive
float
value at the specified
index associated with the specified key, or if no mapping previously
existed for the specified key, then this method adds a new map entry
mapping the key to the specified addend at the specified index. If this
map maps keys to multiple float
values, then the other
float
s will be set to their default instance-variable value,
0.
add
in interface MapToPrimitive<K>
add
in class AbstractMapToPrimitive<K>
key
- the key whose float
value is to be incremented,
or for which a mapping is to be added to the specified addendindex
- the index of the float
value to be incrementedaddend
- the amount by which to increment the float
value
for the specified keypublic double put(K key, int index, double value)
put
in interface MapToPrimitive<K>
put
in class AbstractMapToPrimitive<K>
public void add(K key, int index, double addend)
AbstractMapToPrimitive
double
value at the specified
index associated with the specified key, or if no mapping previously
existed for the specified key, then this method adds a new map entry
mapping the key to the specified addend at the specified index. If this
map maps keys to multiple double
values, then the other
double
s will be set to their default instance-variable value,
0.
add
in interface MapToPrimitive<K>
add
in class AbstractMapToPrimitive<K>
key
- the key whose double
value is to be incremented,
or for which a mapping is to be added to the specified addendindex
- the index of the double
value to be incrementedaddend
- the amount by which to increment the double
value for the specified keypublic Set<Map.Entry<K,Object>> entrySet()
entrySet
in interface Map<K,Object>
entrySet
in class AbstractMap<K,Object>
|
Parsing Engine | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |