Package com.ibm.wala.util.intset
Class SparseLongSet
- java.lang.Object
-
- com.ibm.wala.util.intset.SparseLongSet
-
- All Implemented Interfaces:
LongSet
- Direct Known Subclasses:
MutableSparseLongSet
public class SparseLongSet extends java.lang.Object implements LongSet
A sparse ordered, duplicate-free, fully-encapsulated set of longs; not necessary mutable
-
-
Constructor Summary
Constructors Modifier Constructor Description SparseLongSet()
Subclasses should use this with extreme care.protected
SparseLongSet(int size)
protected
SparseLongSet(long[] backingArray)
Subclasses should use this with extreme care.SparseLongSet(IntSet S)
protected
SparseLongSet(SparseLongSet S)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SparseLongSet
add(SparseLongSet s, int j)
boolean
contains(long x)
Does this set contain value x?boolean
containsAny(LongSet set)
boolean
containsAny(SparseLongSet set)
static SparseLongSet
diff(SparseLongSet A, SparseLongSet B)
Compute the asymmetric difference of two sets, a \ b.long
elementAt(int idx)
void
foreach(LongSetAction action)
Invoke an action on each element of the Setvoid
foreachExcluding(LongSet X, LongSetAction action)
Invoke an action on each element of the Set, excluding elements of Set Xint
getIndex(long x)
LongSet
intersection(LongSet that)
This implementation must not despoil the original value of "this"boolean
isEmpty()
boolean
isSubset(LongSet that)
LongIterator
longIterator()
long
max()
static SparseLongSet
pair(long i, long j)
static long[]
parseLongArray(java.lang.String str)
Reverse of toString(): "{2,3}" -> [2,3]boolean
sameValue(LongSet that)
static SparseLongSet
singleton(int i)
int
size()
java.lang.String
toString()
-
-
-
Constructor Detail
-
SparseLongSet
protected SparseLongSet(int size)
- Parameters:
size
-
-
SparseLongSet
protected SparseLongSet(long[] backingArray)
Subclasses should use this with extreme care. Do not allow the backing array to escape elsewhere.- Parameters:
backingArray
-
-
SparseLongSet
public SparseLongSet()
Subclasses should use this with extreme care.
-
SparseLongSet
protected SparseLongSet(SparseLongSet S)
-
SparseLongSet
public SparseLongSet(IntSet S) throws java.lang.IllegalArgumentException
- Throws:
java.lang.IllegalArgumentException
-
-
Method Detail
-
contains
public final boolean contains(long x)
Does this set contain value x?- Specified by:
contains
in interfaceLongSet
- Returns:
- true iff this set contains long i
- See Also:
IntSet.contains(int)
-
getIndex
public final int getIndex(long x)
- Parameters:
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 long elementAt(int idx) throws java.util.NoSuchElementException
- Throws:
java.util.NoSuchElementException
-
sameValue
public boolean sameValue(LongSet that) throws java.lang.IllegalArgumentException, UnimplementedError
- Specified by:
sameValue
in interfaceLongSet
- Returns:
- true iff
this
has the same value asthat
. - Throws:
java.lang.IllegalArgumentException
UnimplementedError
-
diff
public static SparseLongSet diff(SparseLongSet A, SparseLongSet B)
Compute the asymmetric difference of two sets, a \ b.- Throws:
java.lang.IllegalArgumentException
- if A is null
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
parseLongArray
public static long[] parseLongArray(java.lang.String str) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException
Reverse of toString(): "{2,3}" -> [2,3]- Throws:
java.lang.IllegalArgumentException
- if str is nulljava.lang.NumberFormatException
-
singleton
public static SparseLongSet singleton(int i)
-
pair
public static SparseLongSet pair(long i, long j)
-
intersection
public LongSet intersection(LongSet that) throws java.lang.IllegalArgumentException, UnimplementedError
Description copied from interface:LongSet
This implementation must not despoil the original value of "this"- Specified by:
intersection
in interfaceLongSet
- Returns:
- a new IntSet which is the intersection of this and that
- Throws:
java.lang.IllegalArgumentException
UnimplementedError
-
longIterator
public LongIterator longIterator()
- Specified by:
longIterator
in interfaceLongSet
- Returns:
- a perhaps more efficient iterator
-
foreach
public void foreach(LongSetAction action)
Description copied from interface:LongSet
Invoke an action on each element of the Set
-
foreachExcluding
public void foreachExcluding(LongSet X, LongSetAction action)
Description copied from interface:LongSet
Invoke an action on each element of the Set, excluding elements of Set X- Specified by:
foreachExcluding
in interfaceLongSet
-
max
public final long max() throws java.lang.IllegalStateException
-
add
public static SparseLongSet add(SparseLongSet s, int j)
- Returns:
- a new sparse int set which adds j to s
-
isSubset
public boolean isSubset(LongSet that) throws java.lang.IllegalArgumentException, UnimplementedError
- Specified by:
isSubset
in interfaceLongSet
- Returns:
- true iff
this
is a subset ofthat
. - Throws:
java.lang.IllegalArgumentException
UnimplementedError
-
containsAny
public boolean containsAny(LongSet set)
- Specified by:
containsAny
in interfaceLongSet
- Returns:
- true iff this set contains integer i
-
containsAny
public boolean containsAny(SparseLongSet set) throws java.lang.IllegalArgumentException
- Throws:
java.lang.IllegalArgumentException
-
-