Class BasicNaturalRelation
java.lang.Object
com.ibm.wala.util.intset.BasicNaturalRelation
- All Implemented Interfaces:
VerboseAction
,IBinaryNaturalRelation
,Serializable
,Iterable<IntPair>
public final class BasicNaturalRelation
extends Object
implements IBinaryNaturalRelation, Serializable
A relation between non-negative integers
This implementation uses n IntVectors, to hold the first n y's associated with each x, and then 1 extra vector of SparseIntSet to hold the remaining ys.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final byte
Tokens used as enumerated types to control the representationstatic final byte
static final byte
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(int x, int y) Add (x,y) to the relation.boolean
anyRelated
(int x) boolean
contains
(int x, int y) getRelated
(int x) int
getRelatedCount
(int x) iterator()
int
void
optional method used for performance debuggingvoid
remove
(int x, int y) void
removeAll
(int x) toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
SIMPLE
public static final byte SIMPLETokens used as enumerated types to control the representation- See Also:
-
TWO_LEVEL
public static final byte TWO_LEVEL- See Also:
-
SIMPLE_SPACE_STINGY
public static final byte SIMPLE_SPACE_STINGY- See Also:
-
-
Constructor Details
-
BasicNaturalRelation
- Parameters:
implementation
- a set of codes that represent how the first n IntVectors should be implemented.vectorImpl
- a code that indicates how to represent the delegateStore.For example implementation = {SIMPLE_INT_VECTOR,TWO_LEVEL_INT_VECTOR,TWO_LEVEL_INT_VECTOR} will result in an implementation where the first 3 y's associated with each x are represented in IntVectors. The IntVector for the first y will be implemented with a SimpleIntVector, and the 2nd and 3rd are implemented with TwoLevelIntVector
- Throws:
IllegalArgumentException
- if implementation is nullIllegalArgumentException
- if implementation.length == 0
-
BasicNaturalRelation
public BasicNaturalRelation()
-
-
Method Details
-
add
Add (x,y) to the relation.This is performance-critical, so the implementation looks a little ugly in order to help out the compiler with redundancy elimination.
- Specified by:
add
in interfaceIBinaryNaturalRelation
- Returns:
- true iff the relation changes as a result of this call.
- Throws:
IllegalArgumentException
-
iterator
-
anyRelated
public boolean anyRelated(int x) - Specified by:
anyRelated
in interfaceIBinaryNaturalRelation
- Returns:
- true iff there exists pair (x,y) for some y
-
getRelated
- Specified by:
getRelated
in interfaceIBinaryNaturalRelation
- Returns:
- IntSet of y s.t. R(x,y) or null if none.
-
getRelatedCount
- Specified by:
getRelatedCount
in interfaceIBinaryNaturalRelation
- Returns:
- number of y s.t. R(x,y)
- Throws:
IllegalArgumentException
-
remove
public void remove(int x, int y) - Specified by:
remove
in interfaceIBinaryNaturalRelation
-
removeAll
public void removeAll(int x) - Specified by:
removeAll
in interfaceIBinaryNaturalRelation
-
performVerboseAction
public void performVerboseAction()Description copied from interface:VerboseAction
optional method used for performance debugging- Specified by:
performVerboseAction
in interfaceVerboseAction
- See Also:
-
contains
public boolean contains(int x, int y) - Specified by:
contains
in interfaceIBinaryNaturalRelation
- Returns:
- true iff (x,y) \in R
-
maxKeyValue
public int maxKeyValue()- Specified by:
maxKeyValue
in interfaceIBinaryNaturalRelation
-
toString
-