public class OpenHashMap<K,V> extends AbstractSet implements Map<K,V>
entrySet(), values, and keySet() do not return
collections that share storage with the main map, and changes to those returned objects
are not reflected in the container.| Modifier and Type | Field and Description |
|---|---|
protected static byte |
FREE |
protected int |
freeEntries
The number of table entries in state==FREE.
|
protected static byte |
FULL |
protected static Object |
NO_KEY_VALUE |
protected static byte |
REMOVED |
protected byte[] |
state
The state of each hash table entry (FREE, FULL, REMOVED).
|
protected Object[] |
table
The hash table keys.
|
protected Object[] |
values
The hash table values.
|
DEFAULT_CAPACITY, DEFAULT_MAX_LOAD_FACTOR, DEFAULT_MIN_LOAD_FACTOR, distinct, highWaterMark, lowWaterMark, maxLoadFactor, minLoadFactor| Constructor and Description |
|---|
OpenHashMap()
Constructs an empty map with default capacity and default load factors.
|
OpenHashMap(int initialCapacity)
Constructs an empty map with the specified initial capacity and default load factors.
|
OpenHashMap(int initialCapacity,
double minLoadFactor,
double maxLoadFactor)
Constructs an empty map with the specified initial capacity and the specified minimum and maximum load factor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all (key,value) associations from the receiver.
|
Object |
clone()
Returns a deep copy of the receiver.
|
boolean |
containsKey(Object key)
Returns true if the receiver contains the specified key.
|
boolean |
containsValue(Object value)
Returns true if the receiver contains the specified value.
|
void |
ensureCapacity(int minCapacity)
Ensures that the receiver can hold at least the specified number of associations without needing to allocate new
internal memory.
|
Set<Map.Entry<K,V>> |
entrySet()
Allocate a set to contain Map.Entry objects for the pairs and return it.
|
boolean |
equals(Object obj) |
boolean |
forEachKey(ObjectProcedure<K> procedure)
Applies a procedure to each key of the receiver, if any.
|
boolean |
forEachPair(ObjectObjectProcedure<K,V> procedure)
Applies a procedure to each (key,value) pair of the receiver, if any.
|
V |
get(Object key)
Returns the value associated with the specified key.
|
protected int |
indexOfInsertion(K key) |
protected int |
indexOfKey(K key) |
protected int |
indexOfValue(V value) |
void |
keys(List<K> list)
Fills all keys contained in the receiver into the specified list.
|
Set<K> |
keySet()
Allocate a set to contain keys and return it.
|
V |
put(K key,
V value)
Associates the given key with the given value.
|
void |
putAll(Map<? extends K,? extends V> m) |
protected void |
rehash(int newCapacity)
Rehashes the contents of the receiver into a new table with a smaller or larger capacity.
|
V |
remove(Object key)
Removes the given key with its associated element from the receiver, if present.
|
protected void |
setUp(int initialCapacity,
double minLoadFactor,
double maxLoadFactor)
Initializes the receiver.
|
String |
toString() |
void |
trimToSize()
Trims the capacity of the receiver to be the receiver's current size.
|
Collection<V> |
values()
Allocate a list to contain the values and return it.
|
chooseGrowCapacity, chooseHighWaterMark, chooseLowWaterMark, chooseMeanCapacity, chooseShrinkCapacity, equalsMindTheNull, isEmpty, nextPrime, sizeprotected static final byte FREE
protected static final byte FULL
protected static final byte REMOVED
protected static final Object NO_KEY_VALUE
protected Object[] table
protected Object[] values
protected byte[] state
protected int freeEntries
public OpenHashMap()
public OpenHashMap(int initialCapacity)
initialCapacity - the initial capacity of the map.IllegalArgumentException - if the initial capacity is less than zero.public OpenHashMap(int initialCapacity,
double minLoadFactor,
double maxLoadFactor)
initialCapacity - the initial capacity.minLoadFactor - the minimum load factor.maxLoadFactor - the maximum load factor.IllegalArgumentException - if initialCapacity < 0 || (minLoadFactor < 0.0 || minLoadFactor >= 1.0) ||
(maxLoadFactor <= 0.0 || maxLoadFactor >= 1.0) || (minLoadFactor >=
maxLoadFactor).public void clear()
public Object clone()
clone in class PersistentObjectpublic boolean containsKey(Object key)
containsKey in interface Map<K,V>public boolean containsValue(Object value)
containsValue in interface Map<K,V>public void ensureCapacity(int minCapacity)
This method never need be called; it is for performance tuning only. Calling this method before put()ing a large number of associations boosts performance, because the receiver will grow only once instead of potentially many times and hash collisions get less probable.
ensureCapacity in class AbstractSetminCapacity - the desired minimum capacity.public boolean forEachKey(ObjectProcedure<K> procedure)
procedure - the procedure to be applied. Stops iteration if the procedure returns false, otherwise
continues.public boolean forEachPair(ObjectObjectProcedure<K,V> procedure)
forEachKey(ObjectProcedure).procedure - the procedure to be applied. Stops iteration if the procedure returns false, otherwise
continues.public V get(Object key)
containsKey(Object) whether the given key has a value associated or not, i.e. whether there exists an association
for the given key or not.protected int indexOfInsertion(K key)
key - the key to be added to the receiver.protected int indexOfKey(K key)
key - the key to be searched in the receiver.protected int indexOfValue(V value)
value - the value to be searched in the receiver.public void keys(List<K> list)
list - the list to be filled, can have any size.public V put(K key, V value)
put in interface Map<K,V>key - the key the value shall be associated with.value - the value to be associated.protected void rehash(int newCapacity)
public V remove(Object key)
protected void setUp(int initialCapacity,
double minLoadFactor,
double maxLoadFactor)
setUp in class AbstractSetinitialCapacity - the initial capacity of the receiver.minLoadFactor - the minLoadFactor of the receiver.maxLoadFactor - the maxLoadFactor of the receiver.IllegalArgumentException - if initialCapacity < 0 || (minLoadFactor < 0.0 || minLoadFactor >= 1.0) ||
(maxLoadFactor <= 0.0 || maxLoadFactor >= 1.0) || (minLoadFactor >=
maxLoadFactor).public void trimToSize()
trimToSize in class AbstractSetpublic Set<Map.Entry<K,V>> entrySet()
public Set<K> keySet()
public Collection<V> values()
public boolean equals(Object obj)
Copyright © 2008–2015 The Apache Software Foundation. All rights reserved.