public class IndexedSet<T> extends AbstractExtendedSet<T> implements Serializable
ExtendedSet implementation that maps each element of the universe (i.e., the collection of all possible elements) to an integer referred to as its "index".ExtendedSet,
AbstractExtendedSet,
Serialized FormAbstractExtendedSet.ExtendedSubSet, AbstractExtendedSet.FilteredSet, AbstractExtendedSet.UnmodifiableExtendedSetExtendedSet.ExtendedIterator<X>| Constructor and Description |
|---|
IndexedSet(IntSet indices,
Collection<T> universe)
Creates an empty
IndexedSet based on a given collection that
represents the set of all possible items that can be added to the
IndexedSet instance. |
| Modifier and Type | Method and Description |
|---|---|
T |
absoluteGet(int i)
Returns the item corresponding to the given index
|
Integer |
absoluteIndexOf(T item)
Returns the index of the given item
|
boolean |
add(T e) |
boolean |
addAll(Collection<? extends T> c) |
double |
bitmapCompressionRatio()
|
void |
clear() |
void |
clear(T from,
T to)
Removes from the set all the elements between
first and
last, both included. |
IndexedSet<T> |
clone()
See the
clone() of Object |
double |
collectionCompressionRatio()
|
Comparator<? super T> |
comparator() |
int |
compareTo(ExtendedSet<T> o)
Compares this object with the specified object for order.
|
void |
complement()
Complements the current set.
|
IndexedSet<T> |
complemented()
Generates the complement set.
|
int |
complementSize()
Computes the complement set size.
|
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
boolean |
containsAny(Collection<? extends T> other)
Returns
true if the specified Collection instance
contains any elements that are also contained within this
ExtendedSet instance |
boolean |
containsAtLeast(Collection<? extends T> other,
int minElements)
Returns
true if the specified Collection instance
contains at least minElements elements that are also
contained within this ExtendedSet instance |
IndexedSet<T> |
convert(Collection<?> c)
Converts a given
Collection instance into an instance of the
current class. |
IndexedSet<T> |
convert(Object... e)
Converts a given integer array into an instance of the current class
|
String |
debugInfo()
Prints debug info about the given
ExtendedSet implementation |
ExtendedSet.ExtendedIterator<T> |
descendingIterator()
Gets the descending order iterator over the elements of type
T |
IndexedSet<T> |
difference(Collection<? extends T> other)
Generates the difference set
|
int |
differenceSize(Collection<? extends T> other)
Computes the difference set size.
|
IndexedSet<T> |
empty()
Generates an empty set
|
boolean |
equals(Object obj) |
void |
fill(T from,
T to)
Adds to the set all the elements between
first and
last, both included. |
T |
first() |
void |
flip(T e)
Adds the element if it not existing, or removes it if existing
|
T |
get(int i)
Gets the
ith element of the set |
int |
hashCode() |
int |
indexOf(T e)
Provides position of element within the set.
|
IntSet |
indices()
Returns the set of indices.
|
IndexedSet<T> |
intersection(Collection<? extends T> other)
Generates the intersection set
|
int |
intersectionSize(Collection<? extends T> other)
Computes the intersection set size.
|
boolean |
isEmpty() |
ExtendedSet.ExtendedIterator<T> |
iterator() |
double |
jaccardSimilarity(ExtendedSet<T> other)
Computes the Jaccard similarity coefficient between this set and the
given set.
|
T |
last() |
List<? extends IndexedSet<T>> |
powerSet()
Computes the power-set of the current set.
|
List<? extends IndexedSet<T>> |
powerSet(int min,
int max)
Computes a subset of the power-set of the current set, composed by those
subsets that have cardinality between
min and
max. |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
int |
size() |
IndexedSet<T> |
symmetricDifference(Collection<? extends T> other)
Generates the symmetric difference set
|
int |
symmetricDifferenceSize(Collection<? extends T> other)
Computes the symmetric difference set size.
|
IndexedSet<T> |
union(Collection<? extends T> other)
Generates the union set
|
int |
unionSize(Collection<? extends T> other)
Computes the union set size.
|
IndexedSet<T> |
universe()
Returns the collection of all possible elements
|
descending, headSet, jaccardDistance, powerSetSize, powerSetSize, subSet, tailSet, unmodifiable, weightedJaccardDistance, weightedJaccardSimilaritytoArray, toArray, toStringpublic IndexedSet(IntSet indices, Collection<T> universe)
IndexedSet based on a given collection that
represents the set of all possible items that can be added to the
IndexedSet instance.
VERY IMPORTANT! to correctly work and effectively reduce the
memory allocation, new instances of IndexedSet must be
created through the clone() or empty() methods and
not by calling many times this constructor with the same
collection for universe!
indices - IntSet instance used for internal representationuniverse - collection of all possible items. Order will be
preserved.public IndexedSet<T> clone()
clone() of Object
NOTE: When overriding this method, please note that
Object.clone() is much slower then performing
new and "manually" copying data!
clone in interface ExtendedSet<T>clone in class AbstractExtendedSet<T>public boolean equals(Object obj)
equals in interface Collection<T>equals in interface Set<T>equals in class AbstractSet<T>public int hashCode()
hashCode in interface Collection<T>hashCode in interface Set<T>hashCode in class AbstractSet<T>public int compareTo(ExtendedSet<T> o)
IntSet
instance A is less than another IntSet instance
B if B-A (that is, the elements in
B that are not contained in A) contains at
least one element that is greater than all the elements in
A-B.
The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)
The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.
Finally, the implementor must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.
It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."
In the foregoing description, the notation sgn(expression ) designates the mathematical signum function, which is defined to return one of -1, 0, or 1 according to whether the value of expression is negative, zero or positive.
compareTo in interface ExtendedSet<T>compareTo in interface Comparable<ExtendedSet<T>>compareTo in class AbstractExtendedSet<T>o - the object to be compared.public Comparator<? super T> comparator()
comparator in interface SortedSet<T>public T first()
public T last()
public boolean add(T e)
add in interface Collection<T>add in interface Set<T>add in class AbstractCollection<T>public boolean addAll(Collection<? extends T> c)
addAll in interface Collection<T>addAll in interface Set<T>addAll in class AbstractCollection<T>public void clear()
clear in interface Collection<T>clear in interface Set<T>clear in class AbstractCollection<T>public void flip(T e)
flip in interface ExtendedSet<T>flip in class AbstractExtendedSet<T>e - element to flipExtendedSet.symmetricDifference(Collection)public boolean contains(Object o)
contains in interface Collection<T>contains in interface Set<T>contains in class AbstractCollection<T>public boolean containsAll(Collection<?> c)
containsAll in interface Collection<T>containsAll in interface Set<T>containsAll in class AbstractCollection<T>public boolean containsAny(Collection<? extends T> other)
true if the specified Collection instance
contains any elements that are also contained within this
ExtendedSet instancecontainsAny in interface ExtendedSet<T>containsAny in class AbstractExtendedSet<T>other - ExtendedSet to intersect withExtendedSet intersects
the specified ExtendedSet.public boolean containsAtLeast(Collection<? extends T> other, int minElements)
true if the specified Collection instance
contains at least minElements elements that are also
contained within this ExtendedSet instancecontainsAtLeast in interface ExtendedSet<T>containsAtLeast in class AbstractExtendedSet<T>other - Collection instance to intersect withminElements - minimum number of elements to be contained within this
ExtendedSet instanceExtendedSet intersects
the specified Collection.public boolean isEmpty()
isEmpty in interface Collection<T>isEmpty in interface Set<T>isEmpty in class AbstractCollection<T>public ExtendedSet.ExtendedIterator<T> iterator()
iterator in interface ExtendedSet<T>iterator in interface Iterable<T>iterator in interface Collection<T>iterator in interface Set<T>iterator in class AbstractExtendedSet<T>public ExtendedSet.ExtendedIterator<T> descendingIterator()
TdescendingIterator in interface ExtendedSet<T>descendingIterator in class AbstractExtendedSet<T>public boolean remove(Object o)
remove in interface Collection<T>remove in interface Set<T>remove in class AbstractCollection<T>public boolean removeAll(Collection<?> c)
removeAll in interface Collection<T>removeAll in interface Set<T>removeAll in class AbstractSet<T>public boolean retainAll(Collection<?> c)
retainAll in interface Collection<T>retainAll in interface Set<T>retainAll in class AbstractCollection<T>public int size()
size in interface Collection<T>size in interface Set<T>size in class AbstractCollection<T>public IndexedSet<T> intersection(Collection<? extends T> other)
intersection in interface ExtendedSet<T>intersection in class AbstractExtendedSet<T>other - ExtendedSet instance that represents the right
operandSet.retainAll(java.util.Collection)public IndexedSet<T> union(Collection<? extends T> other)
union in interface ExtendedSet<T>union in class AbstractExtendedSet<T>other - ExtendedSet instance that represents the right
operandSet.addAll(java.util.Collection)public IndexedSet<T> difference(Collection<? extends T> other)
difference in interface ExtendedSet<T>difference in class AbstractExtendedSet<T>other - ExtendedSet instance that represents the right
operandSet.removeAll(java.util.Collection)public IndexedSet<T> symmetricDifference(Collection<? extends T> other)
symmetricDifference in interface ExtendedSet<T>symmetricDifference in class AbstractExtendedSet<T>other - ExtendedSet instance that represents the right
operandExtendedSet.flip(Object)public IndexedSet<T> complemented()
SortedSet.last() that do not exist in the
current set.complemented in interface ExtendedSet<T>complemented in class AbstractExtendedSet<T>ExtendedSet.complement()public void complement()
SortedSet.last() that do not exist in the
current set.complement in interface ExtendedSet<T>ExtendedSet.complemented()public int intersectionSize(Collection<? extends T> other)
This is faster than calling ExtendedSet.intersection(Collection) and
then Set.size()
intersectionSize in interface ExtendedSet<T>intersectionSize in class AbstractExtendedSet<T>other - Collection instance that represents the right
operandpublic int unionSize(Collection<? extends T> other)
This is faster than calling ExtendedSet.union(Collection) and then
Set.size()
unionSize in interface ExtendedSet<T>unionSize in class AbstractExtendedSet<T>other - Collection instance that represents the right
operandpublic int symmetricDifferenceSize(Collection<? extends T> other)
This is faster than calling
ExtendedSet.symmetricDifference(Collection) and then Set.size()
symmetricDifferenceSize in interface ExtendedSet<T>symmetricDifferenceSize in class AbstractExtendedSet<T>other - Collection instance that represents the right
operandpublic int differenceSize(Collection<? extends T> other)
This is faster than calling ExtendedSet.difference(Collection) and
then Set.size()
differenceSize in interface ExtendedSet<T>differenceSize in class AbstractExtendedSet<T>other - Collection instance that represents the right
operandpublic int complementSize()
This is faster than calling ExtendedSet.complemented() and then
Set.size()
complementSize in interface ExtendedSet<T>complementSize in class AbstractExtendedSet<T>public IndexedSet<T> universe()
public Integer absoluteIndexOf(T item)
item - public T absoluteGet(int i)
i - indexpublic IntSet indices()
IndexedSet instance. Trying to perform operation on
out-of-bound indices will throw an IllegalArgumentException
exception.absoluteGet(int),
absoluteIndexOf(Object)public IndexedSet<T> empty()
empty in interface ExtendedSet<T>empty in class AbstractExtendedSet<T>public double bitmapCompressionRatio()
BitSet, 2 means twice the size of BitSet, etc.)bitmapCompressionRatio in interface ExtendedSet<T>bitmapCompressionRatio in class AbstractExtendedSet<T>public double collectionCompressionRatio()
ArrayList, 2 means twice the size of ArrayList, etc.)collectionCompressionRatio in interface ExtendedSet<T>collectionCompressionRatio in class AbstractExtendedSet<T>public IndexedSet<T> convert(Collection<?> c)
Collection instance into an instance of the
current class. NOTE: when the collection is already an instance of
the current class, the method returns the collection itself.convert in interface ExtendedSet<T>convert in class AbstractExtendedSet<T>c - collection to use to generate the new instanceExtendedSet.convert(Object...)public IndexedSet<T> convert(Object... e)
convert in interface ExtendedSet<T>convert in class AbstractExtendedSet<T>e - objects to use to generate the new instanceExtendedSet.convert(Collection)public List<? extends IndexedSet<T>> powerSet()
It is a particular implementation of the algorithm Apriori (see: Rakesh Agrawal, Ramakrishnan Srikant, Fast Algorithms for Mining Association Rules in Large Databases, in Proceedings of the 20th International Conference on Very Large Data Bases, p.487-499, 1994). The returned power-set does not contain the empty set.
The subsets composing the powerset are returned in a list that is sorted according to the lexicographical order provided by the sorted set.
powerSet in interface ExtendedSet<T>powerSet in class AbstractExtendedSet<T>ExtendedSet.powerSet(int, int),
ExtendedSet.powerSetSize()public List<? extends IndexedSet<T>> powerSet(int min, int max)
min and
max.
It is a particular implementation of the algorithm Apriori (see: Rakesh Agrawal, Ramakrishnan Srikant, Fast Algorithms for Mining Association Rules in Large Databases, in Proceedings of the 20th International Conference on Very Large Data Bases, p.487-499, 1994). The power-set does not contains the empty set.
The subsets composing the powerset are returned in a list that is sorted according to the lexicographical order provided by the sorted set.
powerSet in interface ExtendedSet<T>powerSet in class AbstractExtendedSet<T>min - minimum subset size (greater than zero)max - maximum subset sizeExtendedSet.powerSet(),
ExtendedSet.powerSetSize(int, int)public String debugInfo()
ExtendedSet implementationdebugInfo in interface ExtendedSet<T>debugInfo in class AbstractExtendedSet<T>public double jaccardSimilarity(ExtendedSet<T> other)
The coefficient is defined as
|A intersection B| / |A union B|.
jaccardSimilarity in interface ExtendedSet<T>jaccardSimilarity in class AbstractExtendedSet<T>other - the other setExtendedSet.jaccardDistance(ExtendedSet)public T get(int i)
ith element of the setget in interface ExtendedSet<T>get in class AbstractExtendedSet<T>i - position of the element in the sorted setith element of the setpublic int indexOf(T e)
It returns -1 if the element does not exist within the set.
indexOf in interface ExtendedSet<T>indexOf in class AbstractExtendedSet<T>e - element of the setpublic void clear(T from, T to)
first and
last, both included. It supposes that there is an ordering
of the elements of type T and that the universe of all
possible elements is known.clear in interface ExtendedSet<T>clear in class AbstractExtendedSet<T>from - first elementto - last elementpublic void fill(T from, T to)
first and
last, both included. It supposes that there is an ordering
of the elements of type T and that the universe of all
possible elements is known.fill in interface ExtendedSet<T>fill in class AbstractExtendedSet<T>from - first elementto - last elementCopyright © 2016. All rights reserved.