public class ConciseSet extends AbstractIntSet implements Serializable
IntSet
internally represented by
compressed bitmaps though a RLE (Run-Length Encoding) compression algorithm.
See http
://ricerca.mat.uniroma3.it/users/colanton/docs/concise.pdf for more
details.
Notice that the iterator by iterator()
is fail-fast,
similar to most Collection
-derived classes. If the set is
structurally modified at any time after the iterator is created, the iterator
will throw a ConcurrentModificationException
. Thus, in the face of
concurrent modification, the iterator fails quickly and cleanly, rather than
risking arbitrary, non-deterministic behavior at an undetermined time in the
future. The iterator throws a ConcurrentModificationException
on a
best-effort basis. Therefore, it would be wrong to write a program that
depended on this exception for its correctness: the fail-fast behavior of
iterators should be used only to detect bugs.IntSet.IntIterator
Constructor and Description |
---|
ConciseSet()
Creates an empty integer set
|
ConciseSet(boolean simulateWAH)
Creates an empty integer set
|
ConciseSet(int[] words,
boolean simulateWAH) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(int e)
Adds the specified element to this set if it is not already present.
|
boolean |
addAll(IntSet c)
Adds all of the elements in the specified collection to this set if
they're not already present.
|
double |
bitmapCompressionRatio()
|
void |
clear()
Removes all of the elements from this set.
|
void |
clear(int from,
int to)
Removes from the set all the elements between
first and
last , both included. |
ConciseSet |
clone()
See the
clone() of Object |
double |
collectionCompressionRatio()
|
int |
compareTo(IntSet o) |
void |
complement()
Complements the current set.
|
ConciseSet |
complemented()
Generates the complement set.
|
boolean |
contains(int o)
Returns true if this set contains the specified element.
|
boolean |
containsAll(IntSet c)
Returns true if this set contains all of the elements of the
specified collection.
|
boolean |
containsAny(IntSet c)
|
boolean |
containsAtLeast(IntSet c,
int minElements)
|
ConciseSet |
convert(Collection<Integer> c)
Converts a given collection into an instance of the current class.
|
ConciseSet |
convert(int... a)
Converts a given array into an instance of the current class.
|
String |
debugInfo()
Prints debug info about the given
IntSet implementation |
IntSet.IntIterator |
descendingIterator() |
ConciseSet |
difference(IntSet other)
Generates the difference set
|
ConciseSet |
empty()
Generates an empty set
|
boolean |
equals(Object obj) |
void |
fill(int from,
int to)
Adds to the set all the elements between
first and
last , both included. |
void |
flip(int e)
Adds the element if it not existing, or removes it if existing
|
int |
get(int i)
Gets the
i th element of the set |
int[] |
getWords() |
int |
hashCode() |
int |
indexOf(int e)
Provides position of element within the set.
|
ConciseSet |
intersection(IntSet other)
Generates the intersection set
|
int |
intersectionSize(IntSet o)
Computes the intersection set size.
|
boolean |
isEmpty() |
IntSet.IntIterator |
iterator() |
int |
last()
Returns the last (highest) element currently in this set.
|
boolean |
remove(int o)
Removes the specified element from this set if it is present.
|
boolean |
removeAll(IntSet c)
Removes from this set all of its elements that are contained in the
specified collection.
|
boolean |
retainAll(IntSet c)
Retains only the elements in this set that are contained in the specified
collection.
|
int |
size() |
ConciseSet |
symmetricDifference(IntSet other)
Generates the symmetric difference set
|
ByteBuffer |
toByteBuffer() |
ConciseSet |
union(IntSet other)
Generates the union set
|
complementSize, differenceSize, first, jaccardDistance, jaccardSimilarity, powerSet, powerSet, powerSetSize, powerSetSize, symmetricDifferenceSize, toArray, toArray, toString, unionSize, weightedJaccardDistance, weightedJaccardSimilarity
public ConciseSet()
public ConciseSet(boolean simulateWAH)
simulateWAH
- true
if the class must simulate the behavior of
WAHpublic ConciseSet(int[] words, boolean simulateWAH)
public ConciseSet clone()
clone()
of Object
clone
in interface IntSet
clone
in class AbstractIntSet
public int intersectionSize(IntSet o)
This is faster than calling IntSet.intersection(IntSet)
and
then IntSet.size()
intersectionSize
in interface IntSet
intersectionSize
in class AbstractIntSet
o
- IntSet
instance that represents the right
operandpublic ByteBuffer toByteBuffer()
public int[] getWords()
public int get(int i)
i
th element of the setget
in interface IntSet
get
in class AbstractIntSet
i
- position of the element in the sorted seti
th element of the setpublic int indexOf(int e)
It returns -1 if the element does not exist within the set.
indexOf
in interface IntSet
indexOf
in class AbstractIntSet
e
- element of the setpublic ConciseSet intersection(IntSet other)
intersection
in interface IntSet
intersection
in class AbstractIntSet
other
- IntSet
instance that represents the right
operandIntSet.retainAll(IntSet)
public ConciseSet union(IntSet other)
union
in interface IntSet
union
in class AbstractIntSet
other
- IntSet
instance that represents the right
operandIntSet.addAll(IntSet)
public ConciseSet difference(IntSet other)
difference
in interface IntSet
difference
in class AbstractIntSet
other
- IntSet
instance that represents the right
operandIntSet.removeAll(IntSet)
public ConciseSet symmetricDifference(IntSet other)
symmetricDifference
in interface IntSet
symmetricDifference
in class AbstractIntSet
other
- IntSet
instance that represents the right
operandIntSet.flip(int)
public ConciseSet complemented()
IntSet.last()
that do not exist in the
current set.complemented
in interface IntSet
complemented
in class AbstractIntSet
IntSet.complement()
public void complement()
IntSet.last()
that do not exist in the
current set.complement
in interface IntSet
complement
in class AbstractIntSet
IntSet.complemented()
public IntSet.IntIterator iterator()
iterator
in interface IntSet
iterator
in class AbstractIntSet
IntSet.IntIterator
instance to iterate over the setpublic IntSet.IntIterator descendingIterator()
descendingIterator
in interface IntSet
descendingIterator
in class AbstractIntSet
IntSet.IntIterator
instance to iterate over the set in
descending orderpublic void clear()
clear
in interface IntSet
clear
in class AbstractIntSet
public int last()
last
in interface IntSet
last
in class AbstractIntSet
public ConciseSet convert(int... a)
convert
in interface IntSet
convert
in class AbstractIntSet
a
- array to use to generate the new instancepublic ConciseSet convert(Collection<Integer> c)
convert
in interface IntSet
convert
in class AbstractIntSet
c
- array to use to generate the new instancepublic boolean add(int e)
add
in interface IntSet
add
in class AbstractIntSet
e
- element to be added to this setpublic boolean remove(int o)
remove
in interface IntSet
remove
in class AbstractIntSet
o
- object to be removed from this set, if presentpublic boolean contains(int o)
contains
in interface IntSet
contains
in class AbstractIntSet
o
- element whose presence in this set is to be testedpublic boolean containsAll(IntSet c)
containsAll
in interface IntSet
containsAll
in class AbstractIntSet
c
- collection to be checked for containment in this setIntSet.contains(int)
public boolean containsAny(IntSet c)
true
if the specified IntSet
instance contains any elements that are also contained within this
IntSet
instancecontainsAny
in interface IntSet
containsAny
in class AbstractIntSet
c
- IntSet
to intersect withIntSet
intersects the specified IntSet
.public boolean containsAtLeast(IntSet c, int minElements)
true
if the specified IntSet
instance contains at least minElements
elements that are
also contained within this IntSet
instancecontainsAtLeast
in interface IntSet
containsAtLeast
in class AbstractIntSet
c
- IntSet
instance to intersect withminElements
- minimum number of elements to be contained within this
IntSet
instanceIntSet
intersects the specified IntSet
.public boolean isEmpty()
isEmpty
in interface IntSet
isEmpty
in class AbstractIntSet
public boolean retainAll(IntSet c)
retainAll
in interface IntSet
retainAll
in class AbstractIntSet
c
- collection containing elements to be retained in this setIntSet.remove(int)
public boolean addAll(IntSet c)
addAll
in interface IntSet
addAll
in class AbstractIntSet
c
- collection containing elements to be added to this setIntSet.add(int)
public boolean removeAll(IntSet c)
removeAll
in interface IntSet
removeAll
in class AbstractIntSet
c
- collection containing elements to be removed from this setIntSet.remove(int)
,
IntSet.contains(int)
public int size()
size
in interface IntSet
size
in class AbstractIntSet
public ConciseSet empty()
empty
in interface IntSet
empty
in class AbstractIntSet
public int hashCode()
hashCode
in class AbstractIntSet
public boolean equals(Object obj)
equals
in class AbstractIntSet
public int compareTo(IntSet o)
compareTo
in interface Comparable<IntSet>
compareTo
in class AbstractIntSet
public void clear(int from, int to)
first
and
last
, both included.clear
in interface IntSet
clear
in class AbstractIntSet
from
- first elementto
- last elementpublic void fill(int from, int to)
first
and
last
, both included.fill
in interface IntSet
fill
in class AbstractIntSet
from
- first elementto
- last elementpublic void flip(int e)
flip
in interface IntSet
flip
in class AbstractIntSet
e
- element to flipIntSet.symmetricDifference(IntSet)
public double bitmapCompressionRatio()
BitSet
, 2 means twice the size of BitSet
, etc.)bitmapCompressionRatio
in interface IntSet
bitmapCompressionRatio
in class AbstractIntSet
public double collectionCompressionRatio()
ArrayList
, 2 means twice the size of ArrayList
, etc.)collectionCompressionRatio
in interface IntSet
collectionCompressionRatio
in class AbstractIntSet
Copyright © 2011–2017. All rights reserved.