Package org.jboss.jandex
Class StrongInternPool<E>
java.lang.Object
org.jboss.jandex.StrongInternPool<E>
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
StrongInternPool.ByteArrayInternPool
,StrongInternPool.FieldInternPool
,StrongInternPool.MethodInternPool
,StrongInternPool.RecordComponentInternPool
,StrongInternPool.StringInternPool
,StrongInternPool.TypeArrayInternPool
,StrongInternPool.TypeInternPool
A strong intern pool. The pool acts as a set where the first stored entry can be retrieved.
This can be used to conserve memory by eliminating duplicate objects (those that are equal
but have different identity). It however holds strong references to every item in the pool,
so it must be cleared to allow for GC.
Note: It is very important to use a smaller load factor than you normally would for HashSet, 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 static final class
private class
class
private static final class
private static final class
private static final class
private static final class
private static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
Same default as HashMap, must be a power of 2private static final float
67%, just like IdentityHashMapThe class of values that may be present intable
.private StrongInternPool<E>.Index
Cache for an indexprivate 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 Object[]
The open-addressed tableprivate int
The next resize -
Constructor Summary
ConstructorsConstructorDescriptionStrongInternPool
(Class<E> elementType) StrongInternPool
(Class<E> elementType, int initialCapacity) StrongInternPool
(Class<E> elementType, int initialCapacity, float loadFactor) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
clone()
boolean
(package private) boolean
(package private) abstract boolean
(package private) static StrongInternPool
<byte[]> (package private) static StrongInternPool
<FieldInternal> (package private) static StrongInternPool
<MethodInternal> (package private) static StrongInternPool
<RecordComponentInternal> (package private) static StrongInternPool
<String> (package private) static StrongInternPool
<Type[]> (package private) static StrongInternPool
<Type> forTypes()
(package private) int
(package private) abstract int
index()
private static int
index
(int hashCode, int length) private void
init
(int initialCapacity, float loadFactor) Internalizes the specified object by always returning the first ever stored.boolean
isEmpty()
iterator()
private static <K> K
maskNull
(K key) (package private) boolean
mayContain
(Object o) private int
nextIndex
(int index, int length) private int
void
private void
putForCreate
(E entry) private void
private void
relocate
(int start) boolean
private void
resize
(int from) int
size()
Object[]
Advanced method that returns the internal table.toString()
private static <K> K
unmaskNull
(K key) private void
-
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:
-
elementType
The class of values that may be present intable
. -
table
The open-addressed tableMust be
Object[]
instead ofE[]
to allow storing theNULL
marker. -
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 -
index
Cache for an index
-
-
Constructor Details
-
StrongInternPool
-
StrongInternPool
-
StrongInternPool
-
-
Method Details
-
init
private void init(int initialCapacity, float loadFactor) -
mayContain
-
eq
-
hash
-
equality
-
hashCode
-
maskNull
private static <K> K maskNull(K key) -
unmaskNull
private static <K> K unmaskNull(K key) -
nextIndex
private int nextIndex(int index, int length) -
index
private static int index(int hashCode, int length) -
size
public int size() -
isEmpty
public boolean isEmpty() -
contains
-
offset
-
intern
Internalizes the specified object by always returning the first ever stored. Equal objects with different identity (aka duplicates) can be eliminated with this method.- Parameters:
entry
- the object to internalize- Returns:
- the one true unique object (equal to
entry
)
-
resize
private void resize(int from) -
remove
-
relocate
private void relocate(int start) -
clear
public void clear() -
clone
-
toInternalArray
Advanced method that returns the internal table. The resulting array will contain nulls at random places that must be skipped. In addition, it will not operate correctly if a null was inserted into the set. Use at your own risk....- Returns:
- an array containing elements in this set along with randomly placed nulls,
-
printDebugStats
public void printDebugStats() -
readObject
- Throws:
IOException
ClassNotFoundException
-
putForCreate
-
writeObject
- Throws:
IOException
-
iterator
-
index
-
toString
-
forByteArrays
-
forStrings
-
forTypes
-
forTypeArrays
-
forMethods
-
forFields
-
forRecordComponents
-