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 class
private class
private class
private class
private class
private class
protected static class
private class
private class
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleImmutableEntry<K extends Object,
V extends Object> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
Same default as HashMap, must be a power of 2private static final float
67%, just like IdentityHashMapprivate FastCopyHashMap<K,
V>.EntrySet private FastCopyHashMap<K,
V>.KeySet private final float
The user defined load factor which defines when to resizeprivate static final int
MAX_INT - 1private int
Counter used to detect changes made outside of an iteratorprivate static final Object
Marks null keys.private static final long
Serialization IDprivate int
The current number of key-value pairsprivate FastCopyHashMap.Entry<K,
V>[] The open-addressed tableprivate int
The 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 TypeMethodDescriptionvoid
clear()
clone()
boolean
containsKey
(Object key) boolean
containsValue
(Object value) entrySet()
private static final boolean
private static final int
private static final int
index
(int hashCode, int length) private void
init
(int initialCapacity, float loadFactor) boolean
isEmpty()
keySet()
private static final <K> K
maskNull
(K key) private int
nextIndex
(int index, int length) void
void
private void
putForCreate
(K key, V value) private void
private void
relocate
(int start) private void
resize
(int from) int
size()
private static final <K> K
unmaskNull
(K key) values()
private void
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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:
containsKey
in interfaceMap<K,
V> - Overrides:
containsKey
in classAbstractMap<K,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V> - Overrides:
containsValue
in classAbstractMap<K,
V>
-
put
-
resize
private void resize(int from) -
putAll
-
remove
-
relocate
private void relocate(int start) -
clear
public void clear() -
clone
- Overrides:
clone
in classAbstractMap<K,
V>
-
printDebugStats
public void printDebugStats() -
entrySet
-
keySet
-
values
-
readObject
- Throws:
IOException
ClassNotFoundException
-
putForCreate
-
writeObject
- Throws:
IOException
-