public abstract class AbstractIntHashMap
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractIntHashMap.DelegatingMapIterator<T>
Implements an abstract delegating element iterator.
|
static class |
AbstractIntHashMap.MapElement
Implements a map element storing the contents of the buckets.
|
protected class |
AbstractIntHashMap.MapIterator
Implements a map element iterator.
|
| Modifier and Type | Field and Description |
|---|---|
private int |
capacity
Stores the current capacity.
|
private int |
contents
Stores the number of elements.
|
static int |
DEFAULT_CAPACITY
The default capacity for hash map instances.
|
static float |
DEFAULT_LOADFACTOR
The default load factor for hash map instances.
|
private float |
loadFactor
Stores the load factor.
|
private AbstractIntHashMap.MapElement[] |
map
Stores the first bucket for each key.
|
static int |
MAXIMUM_CAPACITY
The maximum allowed capacity for hash map instances.
|
private int |
maxLoad
Stores the maximum load.
|
private int |
objectCounter
Stores the counter for objects created.
|
private boolean |
rehashing
Stores if rehashing is permitted.
|
| Constructor and Description |
|---|
AbstractIntHashMap()
Constructs an empty instance with the default initial capacity and the
default load factor.
|
AbstractIntHashMap(AbstractIntHashMap map)
Constructs a new IntHashMap with the same mappings as the specified Map.
|
AbstractIntHashMap(int initialCapacity)
Constructs an empty instance with the given initial capacity and the
default load factor.
|
AbstractIntHashMap(int initialCapacity,
float loadFactor)
Constructs an empty instance with the given initial capacity and the
given load factor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all mappings from this map.
|
private void |
construct(int initialCapacity,
float loadFactor)
Construction helper method.
|
boolean |
containsKey(int key)
Returns
true if this map contains a mapping for the
specified key. |
protected AbstractIntHashMap.MapElement |
create(int key,
java.lang.Object value)
Creates an element.
|
java.lang.Iterable<AbstractIntHashMap.MapElement> |
elements()
Returns an iterator over the entries stored in this map.
|
int |
getCapacity()
Return the current capacity of the instance.
|
AbstractIntHashMap.MapElement |
getElement(int key)
Returns the element matching the key, or null
if no such element exists.
|
float |
getLoadFactor()
Return the load factor of the instance.
|
int |
getObjectCounter()
Return the number of objects created in / by this instance.
|
boolean |
isEmpty()
Returns
true if this map contains no key-value mappings. |
int[] |
keySet()
Return the keys in the hash map.
|
abstract void |
putAll(AbstractIntHashMap map)
Puts all the keys and values in the specified hash
map into this hash map.
|
protected java.lang.Object |
putElement(int key,
java.lang.Object value)
Associates the specified value with the specified key in this map.
|
private void |
rehash()
Increase the capacity of the map to improve performance.
|
protected AbstractIntHashMap.MapElement |
removeElement(int key)
Removes the mapping for this key from this map if present.
|
void |
removeNotIn(int[] keys)
Remove those elements which are not in
keys. |
void |
setRehash(boolean rehashing)
Enable/disable rehashing (defaults to
true). |
int |
size()
Return the current number of mappings in the hash map.
|
public static final int DEFAULT_CAPACITY
public static final int MAXIMUM_CAPACITY
public static final float DEFAULT_LOADFACTOR
private AbstractIntHashMap.MapElement[] map
private int contents
private int objectCounter
private int capacity
private float loadFactor
private int maxLoad
private boolean rehashing
public AbstractIntHashMap()
public AbstractIntHashMap(int initialCapacity)
initialCapacity - The initial capacity for this hash map.public AbstractIntHashMap(int initialCapacity,
float loadFactor)
initialCapacity - The initial capacity for this hash map.loadFactor - The load factor for this hash map.public AbstractIntHashMap(AbstractIntHashMap map)
map - The map whose mappings are to be placed in this map.java.lang.NullPointerException - if the specified map is null.public abstract void putAll(AbstractIntHashMap map)
map - the source mappublic int size()
public boolean isEmpty()
true if this map contains no key-value mappings.true if there are no mappings, false
elsepublic void clear()
public int getObjectCounter()
public int getCapacity()
public float getLoadFactor()
public int[] keySet()
public java.lang.Iterable<AbstractIntHashMap.MapElement> elements()
public void setRehash(boolean rehashing)
true).rehashing - A boolean indicating the desired rehashing status.protected java.lang.Object putElement(int key,
java.lang.Object value)
key - The key with which the specified value is to be associated.value - The value to be associated with the specified key.null if there was no mapping for key. A
null return can also indicate that the IntHashMap
previously associated null
with the specified key.public boolean containsKey(int key)
true if this map contains a mapping for the
specified key.key - The key whose presence in this map is to be tested.true if this map contains a mapping for the
specified key.protected AbstractIntHashMap.MapElement removeElement(int key)
key - The key whose mapping is to be removed from the map.public AbstractIntHashMap.MapElement getElement(int key)
key - the key to look forpublic void removeNotIn(int[] keys)
keys.keys - the keys to check forprivate void rehash()
protected AbstractIntHashMap.MapElement create(int key, java.lang.Object value)
key - the hash key of the elementvalue - the generic value to be attachedprivate void construct(int initialCapacity,
float loadFactor)
initialCapacity - The initial capacity for this hash map.loadFactor - The load factor for this hash map.