Package fj.data

Class HashSet<A>

java.lang.Object
fj.data.HashSet<A>
All Implemented Interfaces:
Iterable<A>

public final class HashSet<A> extends Object implements Iterable<A>
A mutable hash set that guarantees uniqueness of its elements providing O(1) lookup.
Version:
%build.number%
See Also:
  • Field Details

  • Constructor Details

    • HashSet

      public HashSet(Equal<A> e, Hash<A> h)
      Construct a hash set with the given equality and hashing strategy.
      Parameters:
      e - The equality strategy.
      h - The hashing strategy.
    • HashSet

      public HashSet(Equal<A> e, Hash<A> h, int initialCapacity)
      Construct a hash set with the given equality and hashing strategy.
      Parameters:
      e - The equality strategy.
      h - The hashing strategy.
      initialCapacity - The initial capacity.
    • HashSet

      public HashSet(Equal<A> e, Hash<A> h, int initialCapacity, float loadFactor)
      Construct a hash set with the given equality and hashing strategy.
      Parameters:
      e - The equality strategy.
      h - The hashing strategy.
      initialCapacity - The initial capacity.
      loadFactor - The load factor.
  • Method Details

    • iterator

      public Iterator<A> iterator()
      Returns an iterator for this hash set. This method exists to permit the use in a for-each loop.
      Specified by:
      iterator in interface Iterable<A>
      Returns:
      A iterator for this hash set.
    • eq

      public boolean eq(A a1, A a2)
      Compare two values for equality using the underlying equality strategy.
      Parameters:
      a1 - One value to compare.
      a2 - The other value to compare.
      Returns:
      true if the two values are equal, false otherwise.
    • hash

      public int hash(A a)
      Compute the hash of the given value using the underlying hashing strategy.
      Parameters:
      a - The value to computer the hash of.
      Returns:
      The hash of the given value.
    • empty

      public static <A> HashSet<A> empty(Equal<A> e, Hash<A> h)
      Creates a new HashSet using the given Equal and Hash
    • empty

      public static <A> HashSet<A> empty()
      Creates an empty HashSet
    • iterableHashSet

      public static <A> HashSet<A> iterableHashSet(Iterable<A> it)
      Create a HashSet from the Iterable.
    • iterableHashSet

      public static <A> HashSet<A> iterableHashSet(Equal<A> e, Hash<A> h, Iterable<A> it)
      Create a HashSet from the Iterable.
    • iteratorHashSet

      public static <A> HashSet<A> iteratorHashSet(Iterator<A> it)
      Create a HashSet from the Iterator.
    • iteratorHashSet

      public static <A> HashSet<A> iteratorHashSet(Equal<A> e, Hash<A> h, Iterator<A> it)
      Create a HashSet from the Iterator.
    • arrayHashSet

      @SafeVarargs public static <A> HashSet<A> arrayHashSet(A... as)
      Create a HashSet from the array.
    • arrayHashSet

      @SafeVarargs public static <A> HashSet<A> arrayHashSet(Equal<A> e, Hash<A> h, A... as)
      Create a HashSet from the array.
    • hashSet

      @SafeVarargs public static <A> HashSet<A> hashSet(A... as)
      Create a HashSet from the array.
    • hashSet

      @SafeVarargs public static <A> HashSet<A> hashSet(Equal<A> e, Hash<A> h, A... as)
      Create a HashSet from the array.
    • contains

      public boolean contains(A a)
      Determines if this hash set contains the given element.
      Parameters:
      a - The element to look for in this hash set.
      Returns:
      true if this hash set contains the given element, false otherwise.
    • set

      public void set(A a)
      Insert the given element into this hash set.
      Parameters:
      a - The element to insert.
    • clear

      public void clear()
      Clear all elements from this hash set.
    • isEmpty

      public boolean isEmpty()
      Determines if this hash set contains any elements.
      Returns:
      true if this hash set contains no elements, false otherwise.
    • size

      public int size()
      Returns the number of entries in this hash set.
      Returns:
      The number of entries in this hash set.
    • delete

      public boolean delete(A a)
      Deletes the given element from this hash set.
      Parameters:
      a - The element to delete from this hash set.
      Returns:
      true if this hash set contained the given element prior to deletion, false otherwise.
    • toList

      public List<A> toList()
      Returns a list projection of this hash set.
      Returns:
      A list projection of this hash set.
    • toJavaList

      public List<A> toJavaList()
    • toJavaSet

      public Set<A> toJavaSet()
    • fromSet

      public static <A> HashSet<A> fromSet(Set<A> s)
    • toCollection

      public Collection<A> toCollection()
      Projects an immutable collection of this hash set.
      Returns:
      An immutable collection of this hash set.