Class IdentityHashSet<KType>

java.lang.Object
com.carrotsearch.randomizedtesting.rules.IdentityHashSet<KType>
All Implemented Interfaces:
Iterable<KType>

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

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

    Constructors
    Constructor
    Description
    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<KType>.
    IdentityHashSet(int initialCapacity, float loadFactor)
    Creates a hash set with the given capacity and load factor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Adds a reference to the set.
    private void
    allocateBuffers(int capacity)
    Allocate internal buffers for a given capacity.
    void
     
    boolean
    Checks if the set contains a given ref.
    private void
    Expand the internal storage buffers (capacity) or rehash current keys and values if there are a lot of deleted slots.
    boolean
     
     
    protected int
    nextCapacity(int current)
    Return the next possible capacity, counting from the current buffers' size.
    private static int
    Rehash via MurmurHash.
    protected int
    roundCapacity(int requestedCapacity)
    Round the capacity to the next allowed value.
    int
     

    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 Details

    • DEFAULT_LOAD_FACTOR

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

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

      public 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 Details

    • IdentityHashSet

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

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

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

    • 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(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 Iterator<KType> iterator()
      Specified by:
      iterator in interface Iterable<KType>