Class Set<V>

java.lang.Object
io.lacuna.bifurcan.ISet.Mixin<V>
io.lacuna.bifurcan.Set<V>
All Implemented Interfaces:
ICollection<ISet<V>,V>, ISet<V>, Iterable<V>, Predicate<V>

public class Set<V> extends ISet.Mixin<V>
A set which builds atop Map, and shares the same performance characteristics.
  • Field Details

    • EMPTY

      public static final Set EMPTY
  • Constructor Details

    • Set

      public Set()
    • Set

      public Set(ToLongFunction<V> hashFn, BiPredicate<V,V> equalsFn)
      Parameters:
      hashFn - the hash function used by the set
      equalsFn - the equality semantics used by the set
  • Method Details

    • from

      public static <V> Set<V> from(ISet<V> s)
      Parameters:
      s - a set
      Returns:
      an equivalent set, with the same equality semantics
    • from

      public static <V> Set<V> from(Iterator<V> iterator)
      Parameters:
      iterator - an iterator
      Returns:
      a set containing the remaining values in the iterator
    • from

      public static <V> Set<V> from(Iterable<V> iterable)
      Parameters:
      iterable - an Iterable object
      Returns:
      a set containing the values in the iterator
    • of

      public static <V> Set<V> of(V... elements)
    • empty

      public static <V> Set<V> empty()
    • isLinear

      public boolean isLinear()
      Returns:
      true, if the set is linear
    • valueHash

      public ToLongFunction<V> valueHash()
      Returns:
      the hash function used by the set
    • valueEquality

      public BiPredicate<V,V> valueEquality()
      Returns:
      the equality semantics used by the set
    • contains

      public boolean contains(V value)
      Returns:
      true, if the set contains value
    • size

      public long size()
      Returns:
      the number of elements in the collection
    • indexOf

      public OptionalLong indexOf(V element)
      Returns:
      the position of element in the collection, if it's present
    • nth

      public V nth(long idx)
      Returns:
      the element at idx
    • add

      public Set<V> add(V value)
      Returns:
      the set, containing value
    • add

      public Set<V> add(V value, Object editor)
    • remove

      public Set<V> remove(V value)
      Returns:
      the set, without value
    • remove

      public Set<V> remove(V value, Object editor)
    • split

      public List<Set<V>> split(int parts)
      Description copied from interface: ICollection
      Splits the collection into roughly even pieces, for parallel processing. Depending on the size and contents of the collection, this function may not return exactly parts subsets.
      Parameters:
      parts - the target number of pieces
      Returns:
      a list containing subsets of the collection.
    • iterator

      public Iterator<V> iterator()
    • zip

      public <U> Map<V,U> zip(Function<V,U> f)
      Returns:
      a map which has a corresponding value, computed by f, for each element in the set
    • union

      public Set<V> union(ISet<V> s)
      Returns:
      a new set, representing the union with set
    • difference

      public Set<V> difference(ISet<V> s)
      Returns:
      a new set, representing the difference with set
    • intersection

      public Set<V> intersection(ISet<V> s)
      Returns:
      a new set, representing the intersection with set
    • forked

      public Set<V> forked()
      Description copied from interface: ICollection
      This returns a data structure which is forked, which is equivalent to Clojure's persistent data structures, also sometimes called functional or immutable. This is called "forked" because it means that multiple functions can make divergent changes to the data structure without affecting each other.

      If only a single function or scope uses the data structure, it can be left as a linear data structure, which can have significant performance benefits.

      If the data structure is already forked, it will simply return itself.

      Returns:
      a forked form of the data structure
    • linear

      public Set<V> linear()
      Description copied from interface: ICollection
      This returns a data structure which is linear, or temporarily mutable. The term "linear", as used here, does not completely align with the formal definition of linear types as used in type theory. It is meant to describe the linear dataflow of the method calls, and as a converse to "forked" data structures.

      If ICollection.forked() is called on a linear collection, all references to that linear collection should be discarded.

      If the data structure is already linear, it will simply return itself.

      Returns:
      a linear form of this data structure
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class ISet.Mixin<V>
    • clone

      public Set<V> clone()
      Specified by:
      clone in interface ICollection<ISet<V>,V>
      Overrides:
      clone in class ISet.Mixin<V>
      Returns:
      a cloned copy of the collection