Class IntHashSet

All Implemented Interfaces:
Iterable<Integer>, Collection<Integer>, Set<Integer>

public class IntHashSet extends AbstractSet<Integer>
Open-addressing with linear-probing expandable hash set. Allocation free in steady state use when expanded.

By storing elements as int primitives this significantly reduces memory consumption compared with Java's builtin HashSet<Integer>. It implements Set<Integer> for convenience, but calling functionality via those methods can add boxing overhead to your usage.

This class is not Threadsafe.

This HashSet caches its iterator object by default, so nested iteration is not supported. You can override this behaviour at construction by indicating that the iterator should not be cached.

See Also:
  • Field Details

    • DEFAULT_INITIAL_CAPACITY

      public static final int DEFAULT_INITIAL_CAPACITY
      The initial capacity used when none is specified in the constructor.
      See Also:
  • Constructor Details

    • IntHashSet

      public IntHashSet()
      Construct a hash set with DEFAULT_INITIAL_CAPACITY, Hashing.DEFAULT_LOAD_FACTOR, iterator caching support and 0 as a missing value.
    • IntHashSet

      public IntHashSet(int proposedCapacity)
      Construct a hash set with a proposed capacity, Hashing.DEFAULT_LOAD_FACTOR, iterator caching support and 0 as a missing value.
      Parameters:
      proposedCapacity - for the initial capacity of the set.
    • IntHashSet

      public IntHashSet(int proposedCapacity, float loadFactor)
      Construct a hash set with a proposed initial capacity, load factor, iterator caching support and 0 as a missing value.
      Parameters:
      proposedCapacity - for the initial capacity of the set.
      loadFactor - to be used for resizing.
    • IntHashSet

      public IntHashSet(int proposedCapacity, float loadFactor, boolean shouldAvoidAllocation)
      Construct a hash set with a proposed initial capacity, load factor, iterator caching support and -1 as a missing value.
      Parameters:
      proposedCapacity - for the initial capacity of the set.
      loadFactor - to be used for resizing.
      shouldAvoidAllocation - should the iterator be cached to avoid further allocation.
  • Method Details