Class SetFactory<V>

java.lang.Object
edu.udel.cis.vsl.sarl.util.KeySetFactory<V,V>
edu.udel.cis.vsl.sarl.util.SetFactory<V>
Type Parameters:
V - the type of elements of the set

public abstract class SetFactory<V> extends KeySetFactory<V,V>
A SetFactory is used to manipulate arrays as if they were sets. An array is used to represent a set by listing its element in increasing order. In particular a SetFactory requires a Comparator on the element type of the set, to specify the order. A set is represented as an array of its elements. Each element occurs exactly once. They occur in increasing order. This kind of set is implemented as a "key set" in which the key and value are identical.
  • Constructor Details

    • SetFactory

      public SetFactory(Comparator<V> comparator)
      Constructs a new set factory based on the given comparator.
      Parameters:
      comparator - a comparator on the element type
  • Method Details

    • union

      public V[] union(V[] set1, V[] set2)
      Returns the set which is the union of the two given sets.
      Parameters:
      set1 - the first set
      set2 - the second set
      Returns:
      the union of the two sets
    • intersection

      public V[] intersection(Collection<V[]> sets)
      Computes the intersection of a collection of sets.
      Parameters:
      sets - a collection of sets
      Returns:
      the intersection of those sets
    • factor

      public V[] factor(V[][] sets)
      Factors out commonality from an array of sets. Give an array A of sets [S1,S2,...,Sn], the method returns the intersection U of the Si, and also modifies A so that it becomes [T1,T2,...,Tn], where Ti is Si-U. The elements of A themselves are not modified.
      Parameters:
      sets - a list of sets of V, where each set is represented as an ordered array (as produced by this factory)
      Returns:
      the pair (U, [T1,T2,...,Tn]), where U is the intersection of the Si and Ti is Si-U
    • contains

      public boolean contains(V[] set, V element)
      Does the given set contain the given element?
      Parameters:
      set - the set
      element - the object
      Returns: