Package edu.udel.cis.vsl.sarl.util
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
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 Summary
ConstructorsConstructorDescriptionSetFactory(Comparator<V> comparator) Constructs a new set factory based on the given comparator. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDoes the given set contain the given element?V[]Factors out commonality from an array of sets.V[]intersection(Collection<V[]> sets) Computes the intersection of a collection of sets.V[]Returns the set which is the union of the two given sets.Methods inherited from class edu.udel.cis.vsl.sarl.util.KeySetFactory
combine, emptySet, get, getKeys, keyComparator, put, removeKey, singletonSet
-
Constructor Details
-
SetFactory
Constructs a new set factory based on the given comparator.- Parameters:
comparator- a comparator on the element type
-
-
Method Details
-
union
Returns the set which is the union of the two given sets.- Parameters:
set1- the first setset2- the second set- Returns:
- the union of the two sets
-
intersection
Computes the intersection of a collection of sets.- Parameters:
sets- a collection of sets- Returns:
- the intersection of those sets
-
factor
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
Does the given set contain the given element?- Parameters:
set- the setelement- the object- Returns:
-