Package org.jboss.logmanager
Class FastCopyHashMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.jboss.logmanager.FastCopyHashMap<K,V>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<K,V>
class FastCopyHashMap<K,V> extends java.util.AbstractMap<K,V> implements java.util.Map<K,V>, java.lang.Cloneable, java.io.SerializableA 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classFastCopyHashMap.Entry<K,V>private classFastCopyHashMap.EntryIteratorprivate classFastCopyHashMap.EntrySetprivate classFastCopyHashMap.FastCopyHashMapIterator<E>private classFastCopyHashMap.KeyIteratorprivate classFastCopyHashMap.KeySetprotected static classFastCopyHashMap.SimpleEntry<K,V>private classFastCopyHashMap.ValueIteratorprivate classFastCopyHashMap.Values
-
Field Summary
Fields Modifier and Type Field Description private static intDEFAULT_CAPACITYSame default as HashMap, must be a power of 2private static floatDEFAULT_LOAD_FACTOR67%, just like IdentityHashMapprivate FastCopyHashMap.EntrySetentrySetprivate FastCopyHashMap.KeySetkeySetprivate floatloadFactorThe user defined load factor which defines when to resizeprivate static intMAXIMUM_CAPACITYMAX_INT - 1private intmodCountCounter used to detect changes made outside of an iteratorprivate static java.lang.ObjectNULLMarks null keys.private static longserialVersionUIDSerialization IDprivate intsizeThe current number of key-value pairsprivate FastCopyHashMap.Entry<K,V>[]tableThe open-addressed tableprivate intthresholdThe next resizeprivate FastCopyHashMap.Valuesvalues
-
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 voidclear()FastCopyHashMap<K,V>clone()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<K,V>>entrySet()private static booleaneq(java.lang.Object o1, java.lang.Object o2)Vget(java.lang.Object key)private static inthash(java.lang.Object key)private static intindex(int hashCode, int length)private voidinit(int initialCapacity, float loadFactor)booleanisEmpty()java.util.Set<K>keySet()private static <K> KmaskNull(K key)private intnextIndex(int index, int length)voidprintDebugStats()Vput(K key, V value)voidputAll(java.util.Map<? extends K,? extends V> map)private voidputForCreate(K key, V value)private voidreadObject(java.io.ObjectInputStream s)private voidrelocate(int start)Vremove(java.lang.Object key)private voidresize(int from)intsize()private static <K> KunmaskNull(K key)java.util.Collection<V>values()private voidwriteObject(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()
-
clone
public FastCopyHashMap<K,V> clone()
-
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.IOExceptionjava.lang.ClassNotFoundException
-
writeObject
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException- Throws:
java.io.IOException
-
-