Class IntSet

java.lang.Object
org.basex.util.hash.ASet
org.basex.util.hash.IntSet
Direct Known Subclasses:
IntMap, IntObjMap

public class IntSet extends ASet
This is an efficient and memory-saving hash set for storing primitive integers. It is related to the TokenSet class.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Summary

    Fields inherited from class org.basex.util.hash.ASet

    buckets, next, size
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    IntSet(long capacity)
    Constructor with initial capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    add(int key)
    Stores the specified key if it has not been stored before.
    final boolean
    contains(int key)
    Checks if the set contains the specified key.
    protected int
    hash(int id)
    Returns the hash value of the element with the specified id.
    final int
    key(int id)
    Returns the key with the specified id.
    protected void
    rehash(int newSize)
    Rehashes all entries.
    final int[]
    Returns an array with all elements.
     

    Methods inherited from class org.basex.util.hash.ASet

    capacity, checkSize, clear, isEmpty, size, toString, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • IntSet

      public IntSet()
      Default constructor.
    • IntSet

      public IntSet(long capacity)
      Constructor with initial capacity.
      Parameters:
      capacity - array capacity (will be resized to a power of two)
  • Method Details

    • add

      public final boolean add(int key)
      Stores the specified key if it has not been stored before.
      Parameters:
      key - key to be added
      Returns:
      true if the key did not exist yet and was stored
    • contains

      public final boolean contains(int key)
      Checks if the set contains the specified key.
      Parameters:
      key - key to be looked up
      Returns:
      result of check
    • key

      public final int key(int id)
      Returns the key with the specified id. All ids starts with 1 instead of 0.
      Parameters:
      id - id of the key to return
      Returns:
      key
    • hash

      protected int hash(int id)
      Description copied from class: ASet
      Returns the hash value of the element with the specified id.
      Specified by:
      hash in class ASet
      Parameters:
      id - id of the element
      Returns:
      hash value
    • rehash

      protected void rehash(int newSize)
      Description copied from class: ASet
      Rehashes all entries.
      Specified by:
      rehash in class ASet
      Parameters:
      newSize - new hash size
    • toArray

      public final int[] toArray()
      Returns an array with all elements.
      Returns:
      array
    • toString

      public String toString()
      Overrides:
      toString in class Object