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:
Serializable,Cloneable,Map<K,V>
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 than
HashMap.
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 ClassesModifier and TypeClassDescriptionprivate static final classprivate classprivate classprivate classprivate classprivate classprotected static classprivate classprivate classNested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleImmutableEntry<K,V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intSame default as HashMap, must be a power of 2private static final float67%, just like IdentityHashMapprivate FastCopyHashMap<K,V>.EntrySet private FastCopyHashMap<K,V>.KeySet private final floatThe user defined load factor which defines when to resizeprivate static final intMAX_INT - 1private intCounter used to detect changes made outside of an iteratorprivate static final ObjectMarks null keys.private static final longSerialization IDprivate intThe current number of key-value pairsprivate FastCopyHashMap.Entry<K,V>[] The open-addressed tableprivate intThe next resizeprivate FastCopyHashMap<K,V>.Values -
Constructor Summary
ConstructorsConstructorDescriptionFastCopyHashMap(int initialCapacity) FastCopyHashMap(int initialCapacity, float loadFactor) FastCopyHashMap(Map<? extends K, ? extends V> map) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()clone()booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()private static final booleanprivate static final intprivate static final intindex(int hashCode, int length) private voidinit(int initialCapacity, float loadFactor) booleanisEmpty()keySet()private static final <K> KmaskNull(K key) private intnextIndex(int index, int length) voidvoidprivate voidputForCreate(K key, V value) private voidprivate voidrelocate(int start) private voidresize(int from) intsize()private static final <K> KunmaskNull(K key) values()private voidMethods inherited from class java.util.AbstractMap
equals, hashCode, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
NULL
Marks null keys. -
serialVersionUID
private static final long serialVersionUIDSerialization ID- See Also:
-
DEFAULT_CAPACITY
private static final int DEFAULT_CAPACITYSame default as HashMap, must be a power of 2- See Also:
-
MAXIMUM_CAPACITY
private static final int MAXIMUM_CAPACITYMAX_INT - 1- See Also:
-
DEFAULT_LOAD_FACTOR
private static final float DEFAULT_LOAD_FACTOR67%, just like IdentityHashMap- See Also:
-
table
The open-addressed table -
size
private transient int sizeThe current number of key-value pairs -
threshold
private transient int thresholdThe next resize -
loadFactor
private final float loadFactorThe user defined load factor which defines when to resize -
modCount
private transient int modCountCounter used to detect changes made outside of an iterator -
keySet
-
values
-
entrySet
-
-
Constructor Details
-
FastCopyHashMap
public FastCopyHashMap(int initialCapacity, float loadFactor) -
FastCopyHashMap
-
FastCopyHashMap
public FastCopyHashMap(int initialCapacity) -
FastCopyHashMap
public FastCopyHashMap()
-
-
Method Details
-
init
private void init(int initialCapacity, float loadFactor) -
hash
-
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
-
index
private static final int index(int hashCode, int length) -
size
public int size() -
isEmpty
public boolean isEmpty() -
get
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classAbstractMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V> - Overrides:
containsValuein classAbstractMap<K,V>
-
put
-
resize
private void resize(int from) -
putAll
-
remove
-
relocate
private void relocate(int start) -
clear
public void clear() -
clone
- Overrides:
clonein classAbstractMap<K,V>
-
printDebugStats
public void printDebugStats() -
entrySet
-
keySet
-
values
-
readObject
- Throws:
IOExceptionClassNotFoundException
-
putForCreate
-
writeObject
- Throws:
IOException
-