Package com.ibm.wala.util.intset
Class SparseIntSet
- java.lang.Object
-
- com.ibm.wala.util.intset.SparseIntSet
-
- All Implemented Interfaces:
IntSet
,Serializable
- Direct Known Subclasses:
MutableSparseIntSet
public class SparseIntSet extends Object implements IntSet, Serializable
A sparse ordered, duplicate-free, fully-encapsulated set of integers; not necessary mutable- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description SparseIntSet()
Subclasses should use this with extreme care.protected
SparseIntSet(int size)
protected
SparseIntSet(int[] backingArray)
Subclasses should use this with extreme care.SparseIntSet(IntSet S)
protected
SparseIntSet(SparseIntSet S)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SparseIntSet
add(SparseIntSet s, int j)
boolean
contains(int x)
Does this set contain value x?boolean
containsAny(IntSet set)
boolean
containsAny(SparseIntSet set)
static SparseIntSet
diff(SparseIntSet A, SparseIntSet B)
Compute the asymmetric difference of two sets, a \ b.static int[]
diffInternal(SparseIntSet A, SparseIntSet B)
int
elementAt(int idx)
void
foreach(IntSetAction action)
Invoke an action on each element of the Setvoid
foreachExcluding(IntSet X, IntSetAction action)
Invoke an action on each element of the Set, excluding elements of Set Xint
getIndex(int x)
IntSet
intersection(IntSet that)
This implementation must not despoil the original value of "this"IntIterator
intIterator()
boolean
isEmpty()
boolean
isSubset(IntSet that)
int
max()
static SparseIntSet
pair(int i, int j)
static int[]
parseIntArray(String str)
Reverse of toString(): "{2,3}" -> [2,3]boolean
sameValue(IntSet that)
static SparseIntSet
singleton(int i)
int
size()
int[]
toIntArray()
String
toString()
IntSet
union(IntSet that)
This implementation must not despoil the original value of "this"
-
-
-
Constructor Detail
-
SparseIntSet
protected SparseIntSet(int size)
-
SparseIntSet
protected SparseIntSet(int[] backingArray)
Subclasses should use this with extreme care. Do not allow the backing array to escape elsewhere.
-
SparseIntSet
public SparseIntSet()
Subclasses should use this with extreme care.
-
SparseIntSet
protected SparseIntSet(SparseIntSet S)
-
SparseIntSet
public SparseIntSet(IntSet S) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
-
Method Detail
-
contains
public final boolean contains(int x)
Does this set contain value x?- Specified by:
contains
in interfaceIntSet
- Returns:
- true iff this set contains integer i
- See Also:
IntSet.contains(int)
-
getIndex
public final int getIndex(int x)
- Returns:
- index i s.t. elements[i] == x, or -1 if not found.
-
size
public final int size()
-
isEmpty
public final boolean isEmpty()
-
elementAt
public final int elementAt(int idx) throws NoSuchElementException
- Throws:
NoSuchElementException
-
sameValue
public boolean sameValue(IntSet that) throws IllegalArgumentException, UnimplementedError
- Specified by:
sameValue
in interfaceIntSet
- Returns:
- true iff
this
has the same value asthat
. - Throws:
IllegalArgumentException
UnimplementedError
-
diff
public static SparseIntSet diff(SparseIntSet A, SparseIntSet B)
Compute the asymmetric difference of two sets, a \ b.
-
diffInternal
public static int[] diffInternal(SparseIntSet A, SparseIntSet B)
-
parseIntArray
public static int[] parseIntArray(String str)
Reverse of toString(): "{2,3}" -> [2,3]- Throws:
IllegalArgumentException
- if str is null
-
singleton
public static SparseIntSet singleton(int i)
-
pair
public static SparseIntSet pair(int i, int j)
-
intersection
public IntSet intersection(IntSet that)
Description copied from interface:IntSet
This implementation must not despoil the original value of "this"- Specified by:
intersection
in interfaceIntSet
- Returns:
- a new IntSet which is the intersection of this and that
-
union
public IntSet union(IntSet that)
Description copied from interface:IntSet
This implementation must not despoil the original value of "this"
-
intIterator
public IntIterator intIterator()
- Specified by:
intIterator
in interfaceIntSet
- Returns:
- a perhaps more efficient iterator
-
max
public final int max() throws IllegalStateException
- Specified by:
max
in interfaceIntSet
- Returns:
- the largest element in the set
- Throws:
IllegalStateException
-
foreach
public void foreach(IntSetAction action)
Description copied from interface:IntSet
Invoke an action on each element of the Set
-
foreachExcluding
public void foreachExcluding(IntSet X, IntSetAction action)
Description copied from interface:IntSet
Invoke an action on each element of the Set, excluding elements of Set X- Specified by:
foreachExcluding
in interfaceIntSet
-
add
public static SparseIntSet add(SparseIntSet s, int j)
- Returns:
- a new sparse int set which adds j to s
- Throws:
IllegalArgumentException
- if s is null
-
isSubset
public boolean isSubset(IntSet that)
-
containsAny
public boolean containsAny(IntSet set)
- Specified by:
containsAny
in interfaceIntSet
- Returns:
- true iff this set contains integer i
-
containsAny
public boolean containsAny(SparseIntSet set) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
toIntArray
public int[] toIntArray()
- Returns:
- contents as an int[]
-
-