|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectde.unidu.is.pdatalog.ds.SubSet
A subset of a given set {0,...,n-1}. Every number i can be
present (flags[i] is true) or absent (flags[i]
is false). n is the cardinality of the superset.
The SubSet can be represented as reverse binary string (by
toString()) or a corresponding integer (by getValue()).
E.g.: The superset may be {1,2,3,4}, and the SubSet may be {1,3,4}. Then the
binary string is "1011" and the integer value is 13.
| Field Summary | |
protected boolean[] |
flags
The flags indicating if a number is present of absent. |
protected int |
max
The maximum number of any corresponding integer value plus one. |
| Constructor Summary | |
SubSet(int card)
Creates a new SubSet of a set {0,... |
|
SubSet(int card,
int value)
Creates a new SubSet of a set {0,... |
|
SubSet(int card,
java.lang.String value)
Creates a new SubSet of a set {0,... |
|
| Method Summary | |
void |
add(int num)
Adds the specified number to this SubSet if it is not already present. |
boolean |
contains(int num)
Tests is the specified number num is in this SubSet. |
int |
count()
Returns the cardinality of in this SubSet. |
static int |
count(int value,
int card)
Returns the cardinality of in the SubSet created by new
SubSet(card,value).
|
boolean |
equals(java.lang.Object o)
Compares the specified Object with this SubSet for equality. |
int |
getCard()
Returns the cardinality of the superset. |
int |
getMax()
Returns the maximum number of any corresponding integer value plus one. |
SubSet |
getNext()
Returns the next subset corresponding to the integer value. |
SubSet |
getPrev()
Returns the next subset corresponding to the integer value. |
int |
getValue()
Returns the integer value corresponding to this SubSet. |
static boolean |
isSubSetFrom(int value1,
int value2)
Tests if the SubSet corresponding to the first specified integer is a subset of the SubSet corresponding to the second specified integer. |
boolean |
isSubSetFrom(SubSet subSet)
Tests if this SubSet is a subset of the specified SubSet. |
void |
minus(SubSet subSet)
Removes all numbers in the specified SubSet from this SubSet if they are present. |
void |
next()
Sets this SubSet to the next subset corresponding to the integer value. |
static int |
pow2(int exp)
An auxiliary method returning 2^ exp. |
void |
prev()
Sets this SubSet to the previous subset corresponding to the integer value. |
void |
remove(int num)
Removes the specified number to this SubSet if it is present. |
void |
setCard(int card)
Sets the cardinality of the superset and clears this SubSet. |
void |
setValue(int value)
Sets this SubSet corresponding to an integer value. |
void |
setValue(java.lang.String value)
Sets this SubSet corresponding to a reverse binary string. |
java.lang.String |
toString()
Returns a string representation of this SubSet as a reverse binary string. |
static java.lang.String |
toString(int value,
int card)
Returns a string representation of the SubSet created by new
SubSet(card,value). |
protected int |
trim(int value)
An auxiliary method calculating value % max. |
protected static int |
trim(int value,
int card)
An auxiliary method calculating value % 2^card. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected boolean[] flags
flags[i] is true if i is present in this
SubSet.
protected int max
max == 2^(flags.length).
| Constructor Detail |
public SubSet(int card)
card - the cardinality of the supersetSubSet(int,int),
SubSet(int,String)
public SubSet(int card,
int value)
value.
card - the cardinality of the supersetvalue - the value describing this SubSetSubSet(int),
SubSet(int,String)
public SubSet(int card,
java.lang.String value)
value.
card - the cardinality of the supersetvalue - the value describing this SubSetSubSet(int),
SubSet(int,int)| Method Detail |
public static int pow2(int exp)
exp.
exp - the exponent
exppublic int getCard()
public void setCard(int card)
card - the cardinality of the supersetpublic int getMax()
public int getValue()
toString().
protected int trim(int value)
value % max.
value - the value to be trimmed
value % max
protected static int trim(int value,
int card)
value % 2^card.
value - the value to be trimmedcard - the cardinality
value % 2^cardpublic void setValue(int value)
value - the integer value describing the new content of this SubSetpublic void setValue(java.lang.String value)
value - the reverse binary string describing the new content of this
SubSetpublic boolean contains(int num)
num is in this SubSet.
num - the number to be testes
flags[num]
is truepublic void add(int num)
num - the number to be addedpublic void remove(int num)
num - the number to be removedpublic void next()
public void prev()
public SubSet getNext()
public SubSet getPrev()
public int count()
public static int count(int value,
int card)
new
SubSet(card,value).
I.e. the number of elements in the specified SubSet.
value - the value of the specified SubSetcard - the cardinality of the superset of the specified SubSet
count()public boolean isSubSetFrom(SubSet subSet)
A SubSet A is a subset of another SubSet B if
subSet - the SubSet to be tested
public static boolean isSubSetFrom(int value1,
int value2)
A SubSet A is a subset of another SubSet B if
value1 - the integer corresponding to the first SubSet to be testedvalue2 - the integer corresponding to the second SubSet to be tested
public void minus(SubSet subSet)
this = this \ subSet
operation.
subSet - the subSet containing all numbers to be removed from this
SubSetpublic boolean equals(java.lang.Object o)
Two SubSets A and B are equal iff
o - the Object to be compared for equality with this SubSet
public java.lang.String toString()
E.g.: The superset may be {1,2,3,4}, and the SubSet may be {1,3,4}. Then the binary string returned by this method is "1011".
public static java.lang.String toString(int value,
int card)
new
SubSet(card,value).
value - the value of the specified SubSetcard - the cardinality of the superset of the specified SubSet
toString()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||