Class StrongInternPool<E>

java.lang.Object
org.jboss.jandex.StrongInternPool<E>
All Implemented Interfaces:
Serializable, Cloneable

class StrongInternPool<E> extends Object implements Cloneable, Serializable
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.
  • Field Details

    • NULL

      private static final Object NULL
      Marks null keys.
    • serialVersionUID

      private static final long serialVersionUID
      Serialization ID
      See Also:
    • DEFAULT_CAPACITY

      private static final int DEFAULT_CAPACITY
      Same default as HashMap, must be a power of 2
      See Also:
    • MAXIMUM_CAPACITY

      private static final int MAXIMUM_CAPACITY
      MAX_INT - 1
      See Also:
    • DEFAULT_LOAD_FACTOR

      private static final float DEFAULT_LOAD_FACTOR
      67%, just like IdentityHashMap
      See Also:
    • table

      private transient Object[] 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
    • index

      private transient StrongInternPool<E>.Index index
      Cache for an index
  • Constructor Details

    • StrongInternPool

      public StrongInternPool(int initialCapacity, float loadFactor)
    • StrongInternPool

      public StrongInternPool(int initialCapacity)
    • StrongInternPool

      public StrongInternPool()
  • Method Details

    • init

      private void init(int initialCapacity, float loadFactor)
    • eq

      private static boolean eq(Object o1, Object o2)
    • hash

      private static int hash(Object o)
    • 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)
    • index

      private static final int index(int hashCode, int length)
    • size

      public int size()
    • isEmpty

      public boolean isEmpty()
    • contains

      public boolean contains(Object entry)
    • offset

      private int offset(Object entry)
    • intern

      public E intern(E entry)
      Internalizes the specified object by always returning the first ever stored. Equivalent objects (via .equals) but with different identity (aka duplicates) can be eliminated with this method.
      Parameters:
      entry - the object to internalize
      Returns:
      the one true unique (and equivalent) object
    • resize

      private void resize(int from)
    • remove

      public boolean remove(Object o)
    • relocate

      private void relocate(int start)
    • clear

      public void clear()
    • clone

      public StrongInternPool<E> clone()
      Overrides:
      clone in class Object
    • toInternalArray

      public Object[] 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

      private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • putForCreate

      private void putForCreate(E entry)
    • writeObject

      private void writeObject(ObjectOutputStream s) throws IOException
      Throws:
      IOException
    • iterator

      public Iterator<E> iterator()
    • index

      public StrongInternPool<E>.Index index()
    • toString

      public String toString()
      Overrides:
      toString in class Object