Class FastHashSet<K>

java.lang.Object
org.apache.jena.mem2.collection.FastHashBase<K>
org.apache.jena.mem2.collection.FastHashSet<K>
All Implemented Interfaces:
JenaMapSetCommon<K>, JenaSet<K>, JenaSetHashOptimized<K>
Direct Known Subclasses:
FastHashedTripleBunch

public abstract class FastHashSet<K> extends FastHashBase<K> implements JenaSetHashOptimized<K>
Set which grows, if needed but never shrinks. This set does not guarantee any order. Although due to the way it is implemented the elements have a certain order. This set does not allow null values. This set is not thread safe. It´s purpose is to support fast add, remove, contains and stream / iterate operations. Only remove operations are not as fast as in HashSet Iterating over this set not get much faster again after removing elements because the set is not compacted.
  • Method Details

    • tryAdd

      public boolean tryAdd(K key)
      Description copied from interface: JenaSet
      Add the key to the set if it is not already present.
      Specified by:
      tryAdd in interface JenaSet<K>
      Parameters:
      key - the key to add
      Returns:
      true if the key was added, false if it was already present
    • tryAdd

      public boolean tryAdd(K value, int hashCode)
      Specified by:
      tryAdd in interface JenaSetHashOptimized<K>
    • addAndGetIndex

      public int addAndGetIndex(K value)
      Add and get the index of the added element.
      Parameters:
      value - the value to add
      Returns:
      the index of the added element or the inverse (~) index of the existing element
    • addAndGetIndex

      public int addAndGetIndex(K value, int hashCode)
      Add and get the index of the added element.
      Parameters:
      value - the value to add
      hashCode - the hash code of the value. This is a performance optimization.
      Returns:
      the index of the added element or the inverse (~) index of the existing element
    • addUnchecked

      public void addUnchecked(K key)
      Description copied from interface: JenaSet
      Add the key to the set without checking if it is already present. Attention: This method must only be used if it is guaranteed that the key is not already present.
      Specified by:
      addUnchecked in interface JenaSet<K>
      Parameters:
      key - the key to add
    • addUnchecked

      public void addUnchecked(K value, int hashCode)
      Specified by:
      addUnchecked in interface JenaSetHashOptimized<K>
    • getKeyAt

      public K getKeyAt(int i)
      Gets the key at the given index.
      Parameters:
      i - the index
      Returns:
      the key at the given index