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
FieldsModifier and TypeFieldDescriptionstatic final byteTokens used as enumerated types to control the representationstatic final bytestatic final byte -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(int x, int y) Add (x,y) to the relation.booleananyRelated(int x) booleancontains(int x, int y) getRelated(int x) intgetRelatedCount(int x) iterator()intvoidoptional method used for performance debuggingvoidremove(int x, int y) voidremoveAll(int x) toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface 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:
addin interfaceIBinaryNaturalRelation- Returns:
- true iff the relation changes as a result of this call.
- Throws:
IllegalArgumentException
-
iterator
-
anyRelated
public boolean anyRelated(int x) - Specified by:
anyRelatedin interfaceIBinaryNaturalRelation- Returns:
- true iff there exists pair (x,y) for some y
-
getRelated
- Specified by:
getRelatedin interfaceIBinaryNaturalRelation- Returns:
- IntSet of y s.t. R(x,y) or null if none.
-
getRelatedCount
- Specified by:
getRelatedCountin interfaceIBinaryNaturalRelation- Returns:
- number of y s.t. R(x,y)
- Throws:
IllegalArgumentException
-
remove
public void remove(int x, int y) - Specified by:
removein interfaceIBinaryNaturalRelation
-
removeAll
public void removeAll(int x) - Specified by:
removeAllin interfaceIBinaryNaturalRelation
-
performVerboseAction
public void performVerboseAction()Description copied from interface:VerboseActionoptional method used for performance debugging- Specified by:
performVerboseActionin interfaceVerboseAction- See Also:
-
contains
public boolean contains(int x, int y) - Specified by:
containsin interfaceIBinaryNaturalRelation- Returns:
- true iff (x,y) \in R
-
maxKeyValue
public int maxKeyValue()- Specified by:
maxKeyValuein interfaceIBinaryNaturalRelation
-
toString
-