Class IdentityHashSet<KType>

  • All Implemented Interfaces:
    java.lang.Iterable<KType>

    final class IdentityHashSet<KType>
    extends java.lang.Object
    implements java.lang.Iterable<KType>
    An identity hash set implemented using open addressing. No null keys are allowed.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int assigned
      Cached number of assigned slots.
      static float DEFAULT_LOAD_FACTOR
      Default load factor.
      java.lang.Object[] keys
      All of set entries.
      float loadFactor
      The load factor for this set (fraction of allocated or deleted slots before the buffers must be rehashed or reallocated).
      static int MIN_CAPACITY
      Minimum capacity for the set.
      private int resizeThreshold
      Cached capacity threshold at which we must resize the buffers.
    • Constructor Summary

      Constructors 
      Constructor Description
      IdentityHashSet()
      Creates a hash set with the default capacity of 16.
      IdentityHashSet​(int initialCapacity)
      Creates a hash set with the given capacity, load factor of 0.75f.
      IdentityHashSet​(int initialCapacity, float loadFactor)
      Creates a hash set with the given capacity and load factor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(KType e)
      Adds a reference to the set.
      private void allocateBuffers​(int capacity)
      Allocate internal buffers for a given capacity.
      void clear()  
      boolean contains​(KType e)
      Checks if the set contains a given ref.
      private void expandAndRehash()
      Expand the internal storage buffers (capacity) or rehash current keys and values if there are a lot of deleted slots.
      boolean isEmpty()  
      java.util.Iterator<KType> iterator()  
      protected int nextCapacity​(int current)
      Return the next possible capacity, counting from the current buffers' size.
      private static int rehash​(java.lang.Object o)
      Rehash via MurmurHash.
      protected int roundCapacity​(int requestedCapacity)
      Round the capacity to the next allowed value.
      int size()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • DEFAULT_LOAD_FACTOR

        public static final float DEFAULT_LOAD_FACTOR
        Default load factor.
        See Also:
        Constant Field Values
      • MIN_CAPACITY

        public static final int MIN_CAPACITY
        Minimum capacity for the set.
        See Also:
        Constant Field Values
      • keys

        public java.lang.Object[] keys
        All of set entries. Always of power of two length.
      • assigned

        public int assigned
        Cached number of assigned slots.
      • loadFactor

        public final float loadFactor
        The load factor for this set (fraction of allocated or deleted slots before the buffers must be rehashed or reallocated).
      • resizeThreshold

        private int resizeThreshold
        Cached capacity threshold at which we must resize the buffers.
    • Constructor Detail

      • IdentityHashSet

        public IdentityHashSet()
        Creates a hash set with the default capacity of 16. load factor of 0.75f. `
      • IdentityHashSet

        public IdentityHashSet​(int initialCapacity)
        Creates a hash set with the given capacity, load factor of 0.75f.
      • IdentityHashSet

        public IdentityHashSet​(int initialCapacity,
                               float loadFactor)
        Creates a hash set with the given capacity and load factor.
    • Method Detail

      • add

        public boolean add​(KType e)
        Adds a reference to the set. Null keys are not allowed.
      • contains

        public boolean contains​(KType e)
        Checks if the set contains a given ref.
      • rehash

        private static int rehash​(java.lang.Object o)
        Rehash via MurmurHash.
      • expandAndRehash

        private void expandAndRehash()
        Expand the internal storage buffers (capacity) or rehash current keys and values if there are a lot of deleted slots.
      • allocateBuffers

        private void allocateBuffers​(int capacity)
        Allocate internal buffers for a given capacity.
        Parameters:
        capacity - New capacity (must be a power of two).
      • nextCapacity

        protected int nextCapacity​(int current)
        Return the next possible capacity, counting from the current buffers' size.
      • roundCapacity

        protected int roundCapacity​(int requestedCapacity)
        Round the capacity to the next allowed value.
      • clear

        public void clear()
      • size

        public int size()
      • isEmpty

        public boolean isEmpty()
      • iterator

        public java.util.Iterator<KType> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<KType>