Package jflex.state
Class StateSet
java.lang.Object
jflex.state.StateSet
A set of NFA states (= ints).
Similar to BitSet
, but tuned for sets of states. Can hold at most
2^64
elements, but is only useful for much smaller sets (ideally not more than tens of
thousands).
Provides an Integer iterator and a native int enumerator.
- Version:
- JFlex 1.8.2
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) long[]
Content of theStateSet
, one bit per int, i.e.(package private) static final int
2^BITS
per wordprivate final boolean
Compile timeDEBUG
setting, local toStateSet
static final StateSet
The empty set of states(package private) static final int
-
Constructor Summary
ConstructorsConstructorDescriptionStateSet()
Construct an empty StateSet with default memory backing.StateSet
(int size) Construct an empty StateSet with specified memory backing.StateSet
(int size, int state) Construct an StateSet with specified initial element and memory backing.Copy the specified StateSet to create a new one. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add all elements of the specified StateSet to this one.void
addState
(int state) Add an element (a state) to the set.void
clear()
Remove all elements from this set.complement
(StateSet univ) Returns the complement of this set with respect to the specified set, that is, the set of elements that are contained in the specified set but are not contained in this set.boolean
Determine if the given set is a subset of this set.boolean
Determine if the State set contains elements.copy()
Return a copy of this StateSet.void
Copy specified StateSet into this.static StateSet
emptySet
(int length) Return a new StateSet of the specified length.boolean
int
Returns an element of the set and removes it.boolean
hasElement
(int state) Determine if a given state is an element of the set.int
hashCode()
void
Remove all states fromthis
that are not contained in the providedStateSet
.iterator()
Construct an Integer iterator for this StateSet.(package private) static int
nbits2size
(int length) Compute a set size that will lead to an array of the given length.void
remove
(int state) Remove a given state from the set.private void
resize
(int size) Resize this set so it can hold at leastsize
elements.(package private) static int
size2nbits
(int size) Compute the array size for a given set size.states()
Construct an enumerator for this set.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEBUG
private final boolean DEBUGCompile timeDEBUG
setting, local toStateSet
- See Also:
-
EMPTY
The empty set of states -
BITS
static final int BITS2^BITS
per word- See Also:
-
MASK
static final int MASK- See Also:
-
bits
long[] bitsContent of theStateSet
, one bit per int, i.e. bit 0 ofbits[0]
stands for 0, bit 1 ofbits[0]
stands for 1, bit 1 ofbits[1]
stands for 65, etc.
-
-
Constructor Details
-
StateSet
public StateSet()Construct an empty StateSet with default memory backing. -
StateSet
public StateSet(int size) Construct an empty StateSet with specified memory backing.- Parameters:
size
- an int specifying the largest number this set will store. The StateSet will automatically resize of a larger number is added; specifying the size avoids re-allocation.
-
StateSet
public StateSet(int size, int state) Construct an StateSet with specified initial element and memory backing.- Parameters:
size
- an int specifying the largest number this set will store. The StateSet will automatically resize of a larger number is added; specifying the size avoids re-allocation.state
- the element the set should contain.
-
StateSet
Copy the specified StateSet to create a new one.- Parameters:
set
- theStateSet
object to copy.
-
-
Method Details
-
emptySet
Return a new StateSet of the specified length. -
addState
public void addState(int state) Add an element (a state) to the set. Will automatically resize the set representation if necessary.- Parameters:
state
- the element to add.
-
size2nbits
static int size2nbits(int size) Compute the array size for a given set size.- Parameters:
size
- the desired size of the set.- Returns:
- an array size such that the set can hold at least
size
elements.
-
nbits2size
static int nbits2size(int length) Compute a set size that will lead to an array of the given length.Precondition: length > 0 invalid input: '&'invalid input: '&' length invalid input: '<'= 2^58 (58=64-BITS)
- Parameters:
length
- desired length of the StateSet array- Returns:
- an int
val
such thatsize2nbits(val) = length
-
resize
private void resize(int size) Resize this set so it can hold at leastsize
elements.- Parameters:
size
- new maximum element
-
clear
public void clear()Remove all elements from this set. -
hasElement
public boolean hasElement(int state) Determine if a given state is an element of the set.- Parameters:
state
- the element to check for.- Returns:
- true iff this set has the element
state
.
-
getAndRemoveElement
public int getAndRemoveElement()Returns an element of the set and removes it.Precondition: the set is not empty.
- Returns:
- an element of the set.
-
remove
public void remove(int state) Remove a given state from the set.- Parameters:
state
- the element to remove.
-
intersect
Remove all states fromthis
that are not contained in the providedStateSet
.- Parameters:
set
- theStateSet
object to intersect with.
-
complement
Returns the complement of this set with respect to the specified set, that is, the set of elements that are contained in the specified set but are not contained in this set.Does not change this set.
-
add
Add all elements of the specified StateSet to this one.- Parameters:
set
- aStateSet
object to be added.
-
equals
-
hashCode
public int hashCode() -
states
Construct an enumerator for this set.- Returns:
- a
StateSetEnumerator
object for this set.
-
containsElements
public boolean containsElements()Determine if the State set contains elements.- Returns:
- true iff the set is not empty.
-
contains
Determine if the given set is a subset of this set.- Parameters:
set
- the set to check containment of- Returns:
- true iff
set
is contained in this set.
-
copy
Return a copy of this StateSet.- Returns:
- a
StateSet
object with the same content as this.
-
copy
Copy specified StateSet into this.- Parameters:
set
- the state set to copy.
-
toString
-
iterator
Construct an Integer iterator for this StateSet.
-