Package jflex.state

Class StateSet

  • All Implemented Interfaces:
    Iterable<Integer>

    public final class StateSet
    extends Object
    implements Iterable<Integer>
    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.1
    Author:
    Gerwin Klein
    See Also:
    StateSetEnumerator
    • Field Detail

      • EMPTY

        public static final StateSet EMPTY
        The empty set of states
    • Constructor Detail

      • 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

        public StateSet​(StateSet set)
        Copy the specified StateSet to create a new one.
        Parameters:
        set - the StateSet object to copy.
    • Method Detail

      • emptySet

        public static StateSet emptySet​(int length)
        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.
      • 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

        public void intersect​(StateSet set)
        Remove all states from this that are not contained in the provided StateSet.
        Parameters:
        set - the StateSet object to intersect with.
      • complement

        public StateSet 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.

        Does not change this set.

        Parameters:
        univ - the StateSet that determines which elements can at most be returned.
        Returns:
        the StateSet that contains all elements of univ that are not in this set.
      • add

        public void add​(StateSet set)
        Add all elements of the specified StateSet to this one.
        Parameters:
        set - a StateSet object to be added.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • containsElements

        public boolean containsElements()
        Determine if the State set contains elements.
        Returns:
        true iff the set is not empty.
      • contains

        public boolean contains​(StateSet set)
        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

        public StateSet copy()
        Return a copy of this StateSet.
        Returns:
        a StateSet object with the same content as this.
      • copy

        public void copy​(StateSet set)
        Copy specified StateSet into this.
        Parameters:
        set - the state set to copy.
      • iterator

        public Iterator<Integer> iterator()
        Construct an Integer iterator for this StateSet.
        Specified by:
        iterator in interface Iterable<Integer>
        Returns:
        an iterator for this StateSet.