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
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.protectedSparseIntSet(int size)protectedSparseIntSet(int[] backingArray)Subclasses should use this with extreme care.SparseIntSet(IntSet S)protectedSparseIntSet(SparseIntSet S)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SparseIntSetadd(SparseIntSet s, int j)booleancontains(int x)Does this set contain value x?booleancontainsAny(IntSet set)booleancontainsAny(SparseIntSet set)static SparseIntSetdiff(SparseIntSet A, SparseIntSet B)Compute the asymmetric difference of two sets, a \ b.static int[]diffInternal(SparseIntSet A, SparseIntSet B)intelementAt(int idx)voidforeach(IntSetAction action)Invoke an action on each element of the SetvoidforeachExcluding(IntSet X, IntSetAction action)Invoke an action on each element of the Set, excluding elements of Set XintgetIndex(int x)IntSetintersection(IntSet that)This implementation must not despoil the original value of "this"IntIteratorintIterator()booleanisEmpty()booleanisSubset(@Nullable IntSet that)intmax()static SparseIntSetpair(int i, int j)static int[]parseIntArray(String str)Reverse of toString(): "{2,3}" -> [2,3]booleansameValue(IntSet that)static SparseIntSetsingleton(int i)intsize()int[]toIntArray()StringtoString()IntSetunion(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
@NullUnmarked 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?
-
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:
sameValuein interfaceIntSet- Returns:
- true iff
thishas the same value asthat. - Throws:
IllegalArgumentExceptionUnimplementedError
-
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:IntSetThis implementation must not despoil the original value of "this"- Specified by:
intersectionin interfaceIntSet- Returns:
- a new IntSet which is the intersection of this and that
-
union
public IntSet union(IntSet that)
Description copied from interface:IntSetThis implementation must not despoil the original value of "this"
-
intIterator
public IntIterator intIterator()
- Specified by:
intIteratorin interfaceIntSet- Returns:
- a perhaps more efficient iterator
-
max
public final int max() throws IllegalStateException- Specified by:
maxin interfaceIntSet- Returns:
- the largest element in the set
- Throws:
IllegalStateException
-
foreach
public void foreach(IntSetAction action)
Description copied from interface:IntSetInvoke an action on each element of the Set
-
foreachExcluding
public void foreachExcluding(IntSet X, IntSetAction action)
Description copied from interface:IntSetInvoke an action on each element of the Set, excluding elements of Set X- Specified by:
foreachExcludingin interfaceIntSet- See Also:
IntSet.foreach(com.ibm.wala.util.intset.IntSetAction)
-
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(@Nullable IntSet that)
-
containsAny
public boolean containsAny(IntSet set)
- Specified by:
containsAnyin 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[]
-
-