Package com.ibm.wala.util.intset
Class BasicNaturalRelation
- java.lang.Object
-
- com.ibm.wala.util.intset.BasicNaturalRelation
-
- All Implemented Interfaces:
VerboseAction
,IBinaryNaturalRelation
,java.io.Serializable
,java.lang.Iterable<IntPair>
public final class BasicNaturalRelation extends java.lang.Object implements IBinaryNaturalRelation, java.io.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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static byte
SIMPLE
Tokens used as enumerated types to control the representationstatic byte
SIMPLE_SPACE_STINGY
static byte
TWO_LEVEL
-
Constructor Summary
Constructors Constructor Description BasicNaturalRelation()
BasicNaturalRelation(byte[] implementation, byte vectorImpl)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(int x, int y)
Add (x,y) to the relation.boolean
anyRelated(int x)
boolean
contains(int x, int y)
IntSet
getRelated(int x)
int
getRelatedCount(int x)
java.util.Iterator<IntPair>
iterator()
int
maxKeyValue()
void
performVerboseAction()
optional method used for performance debuggingvoid
remove(int x, int y)
void
removeAll(int x)
java.lang.String
toString()
-
-
-
Field Detail
-
SIMPLE
public static final byte SIMPLE
Tokens used as enumerated types to control the representation- See Also:
- Constant Field Values
-
TWO_LEVEL
public static final byte TWO_LEVEL
- See Also:
- Constant Field Values
-
SIMPLE_SPACE_STINGY
public static final byte SIMPLE_SPACE_STINGY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BasicNaturalRelation
public BasicNaturalRelation(byte[] implementation, byte vectorImpl) throws java.lang.IllegalArgumentException
- 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:
java.lang.IllegalArgumentException
- if implementation is nulljava.lang.IllegalArgumentException
- if implementation.length == 0
-
BasicNaturalRelation
public BasicNaturalRelation()
-
-
Method Detail
-
add
public boolean add(int x, int y) throws java.lang.IllegalArgumentException
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:
java.lang.IllegalArgumentException
-
iterator
public java.util.Iterator<IntPair> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<IntPair>
-
anyRelated
public boolean anyRelated(int x)
- Specified by:
anyRelated
in interfaceIBinaryNaturalRelation
- Parameters:
x
-- Returns:
- true iff there exists pair (x,y) for some y
-
getRelated
public IntSet getRelated(int x)
- Specified by:
getRelated
in interfaceIBinaryNaturalRelation
- Returns:
- IntSet of y s.t. R(x,y) or null if none.
-
getRelatedCount
public int getRelatedCount(int x) throws java.lang.IllegalArgumentException
- Specified by:
getRelatedCount
in interfaceIBinaryNaturalRelation
- Returns:
- number of y s.t. R(x,y)
- Throws:
java.lang.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
-
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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-