Package org.jboss.util.collection
Class FastCopyHashMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.jboss.util.collection.FastCopyHashMap<K,V>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<K,V>
public class FastCopyHashMap<K,V> extends java.util.AbstractMap<K,V> implements java.util.Map<K,V>, java.lang.Cloneable, java.io.Serializable
A HashMap that is optimized for fast shallow copies. If the copy-ctor is passed another FastCopyHashMap, or clone is called on this map, the shallow copy can be performed using little more than a single array copy. In order to accomplish this, immutable objects must be used internally, so update operations result in slightly more object churn thanHashMap
. Note: It is very important to use a smaller load factor than you normally would for HashMap, since the implementation is open-addressed with linear probing. With a 50% load-factor a get is expected to return in only 2 probes. However, a 90% load-factor is expected to return in around 50 probes.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FastCopyHashMap.Entry<K,V>
private class
FastCopyHashMap.EntryIterator
private class
FastCopyHashMap.EntrySet
private class
FastCopyHashMap.FastCopyHashMapIterator<E>
private class
FastCopyHashMap.KeyIterator
private class
FastCopyHashMap.KeySet
protected static class
FastCopyHashMap.SimpleEntry<K,V>
private class
FastCopyHashMap.ValueIterator
private class
FastCopyHashMap.Values
-
Field Summary
Fields Modifier and Type Field Description private static int
DEFAULT_CAPACITY
Same default as HashMap, must be a power of 2private static float
DEFAULT_LOAD_FACTOR
67%, just like IdentityHashMapprivate FastCopyHashMap.EntrySet
entrySet
private FastCopyHashMap.KeySet
keySet
private float
loadFactor
The user defined load factor which defines when to resizeprivate static int
MAXIMUM_CAPACITY
MAX_INT - 1private int
modCount
Counter used to detect changes made outside of an iteratorprivate static java.lang.Object
NULL
Marks null keys.private static long
serialVersionUID
Serialization IDprivate int
size
The current number of key-value pairsprivate FastCopyHashMap.Entry<K,V>[]
table
The open-addressed tableprivate int
threshold
The next resizeprivate FastCopyHashMap.Values
values
-
Constructor Summary
Constructors Constructor Description FastCopyHashMap()
FastCopyHashMap(int initialCapacity)
FastCopyHashMap(int initialCapacity, float loadFactor)
FastCopyHashMap(java.util.Map<? extends K,? extends V> map)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
java.lang.Object
clone()
boolean
containsKey(java.lang.Object key)
boolean
containsValue(java.lang.Object value)
java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
private static boolean
eq(java.lang.Object o1, java.lang.Object o2)
V
get(java.lang.Object key)
private static int
hash(java.lang.Object key)
private static int
index(int hashCode, int length)
private void
init(int initialCapacity, float loadFactor)
boolean
isEmpty()
java.util.Set<K>
keySet()
private static <K> K
maskNull(K key)
private int
nextIndex(int index, int length)
void
printDebugStats()
V
put(K key, V value)
void
putAll(java.util.Map<? extends K,? extends V> map)
private void
putForCreate(K key, V value)
private void
readObject(java.io.ObjectInputStream s)
private void
relocate(int start)
V
remove(java.lang.Object key)
private void
resize(int from)
int
size()
private static <K> K
unmaskNull(K key)
java.util.Collection<V>
values()
private void
writeObject(java.io.ObjectOutputStream s)
-
-
-
Field Detail
-
NULL
private static final java.lang.Object NULL
Marks null keys.
-
serialVersionUID
private static final long serialVersionUID
Serialization ID- See Also:
- Constant Field Values
-
DEFAULT_CAPACITY
private static final int DEFAULT_CAPACITY
Same default as HashMap, must be a power of 2- See Also:
- Constant Field Values
-
MAXIMUM_CAPACITY
private static final int MAXIMUM_CAPACITY
MAX_INT - 1- See Also:
- Constant Field Values
-
DEFAULT_LOAD_FACTOR
private static final float DEFAULT_LOAD_FACTOR
67%, just like IdentityHashMap- See Also:
- Constant Field Values
-
table
private transient FastCopyHashMap.Entry<K,V>[] table
The open-addressed table
-
size
private transient int size
The current number of key-value pairs
-
threshold
private transient int threshold
The next resize
-
loadFactor
private final float loadFactor
The user defined load factor which defines when to resize
-
modCount
private transient int modCount
Counter used to detect changes made outside of an iterator
-
keySet
private transient FastCopyHashMap.KeySet keySet
-
values
private transient FastCopyHashMap.Values values
-
entrySet
private transient FastCopyHashMap.EntrySet entrySet
-
-
Method Detail
-
init
private void init(int initialCapacity, float loadFactor)
-
hash
private static final int hash(java.lang.Object key)
-
maskNull
private static final <K> K maskNull(K key)
-
unmaskNull
private static final <K> K unmaskNull(K key)
-
nextIndex
private int nextIndex(int index, int length)
-
eq
private static final boolean eq(java.lang.Object o1, java.lang.Object o2)
-
index
private static final int index(int hashCode, int length)
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
get
public V get(java.lang.Object key)
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(java.lang.Object value)
-
resize
private void resize(int from)
-
remove
public V remove(java.lang.Object key)
-
relocate
private void relocate(int start)
-
clear
public void clear()
-
printDebugStats
public void printDebugStats()
-
keySet
public java.util.Set<K> keySet()
-
values
public java.util.Collection<V> values()
-
readObject
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
writeObject
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException
- Throws:
java.io.IOException
-
-