Class ASet

java.lang.Object
org.basex.util.hash.ASet
Direct Known Subclasses:
HashItemSet, IntSet, QNmSet, TokenSet

public abstract class ASet extends Object
This is the basic structure of an efficient and memory-saving hash set. The first entry of the token set (offset 0) will always be kept empty.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int[]
    Hash table buckets.
    protected int[]
    Pointers to the next entry.
    protected int
    Hash entries.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Empty constructor.
    protected
    ASet(long capacity)
    Constructor with initial capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected final int
    Returns the current array capacity.
    protected final void
    Resizes the hash table.
    protected void
    Resets the data structure.
    protected abstract int
    hash(int id)
    Returns the hash value of the element with the specified id.
    final boolean
    Tests is the set is empty.
    protected abstract void
    rehash(int newSize)
    Rehashes all entries.
    final int
    Returns the number of entries.
    toString(Object[] keys)
    Returns a string representation of the set or map.
    toString(Object[] keys, Object[] values)
    Returns a string representation of the set or map.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • buckets

      protected int[] buckets
      Hash table buckets.
    • next

      protected int[] next
      Pointers to the next entry.
    • size

      protected int size
      Hash entries. The actual number of entries is size - 1.
  • Constructor Details

    • ASet

      protected ASet()
      Empty constructor.
    • ASet

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

    • clear

      protected void clear()
      Resets the data structure.
    • size

      public final int size()
      Returns the number of entries. The actual number of keys may be smaller if keys have been deleted.
      Returns:
      number of entries
    • isEmpty

      public final boolean isEmpty()
      Tests is the set is empty.
      Returns:
      result of check
    • checkSize

      protected final void checkSize()
      Resizes the hash table.
    • capacity

      protected final int capacity()
      Returns the current array capacity.
      Returns:
      array capacity
    • hash

      protected abstract int hash(int id)
      Returns the hash value of the element with the specified id.
      Parameters:
      id - id of the element
      Returns:
      hash value
    • rehash

      protected abstract void rehash(int newSize)
      Rehashes all entries.
      Parameters:
      newSize - new hash size
    • toString

      public String toString(Object[] keys)
      Returns a string representation of the set or map.
      Parameters:
      keys - hash keys
      Returns:
      string
    • toString

      public String toString(Object[] keys, Object[] values)
      Returns a string representation of the set or map.
      Parameters:
      keys - hash keys
      values - hash values or null
      Returns:
      string