Module logicng

Class LNGBooleanVector


  • public final class LNGBooleanVector
    extends Object
    A simple vector for boolean elements implementation (inspired by MiniSat and CleaneLing).

    In theory one could use the LNGVector also for boolean. But Java's auto-boxing comes with such a large performance penalty that for the mission critical data structures of the SAT solvers we use this specialized implementation.

    Since:
    1.0
    Version:
    1.0
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean back()
      Returns the last element of the vector and leaves it on the vector.
      void clear()
      Clears the vector.
      boolean empty()
      Returns whether the vector is empty or not.
      boolean get​(int position)
      Returns the element at a given position in the vector.
      void growTo​(int size, boolean pad)
      Grows the vector to a new size and initializes the new elements with a given value.
      void pop()
      Removes the last element of the vector.
      void push​(boolean element)
      Pushes an element at the end of the vector.
      void removeElements​(int num)
      Removes a given number of elements from the vector.
      void reverseInplace()
      Reverses the content of this vector in-place.
      void set​(int position, boolean element)
      Sets an element at a given position in the vector.
      void shrinkTo​(int newSize)
      Shrinks the vector to a given size if the new size is less than the current size.
      int size()
      Returns the size of the vector.
      boolean[] toArray()
      Returns this vector's contents as an array.
      String toString()  
      void unsafePush​(boolean element)
      Pushes an element and assumes that there is enough space on the vector.
    • Constructor Detail

      • LNGBooleanVector

        public LNGBooleanVector()
        Creates a vector with an initial capacity of 5 elements.
      • LNGBooleanVector

        public LNGBooleanVector​(int size)
        Creates a vector with a given capacity.
        Parameters:
        size - the capacity of the vector.
      • LNGBooleanVector

        public LNGBooleanVector​(int size,
                                boolean pad)
        Creates a vector with a given capacity and a given initial element.
        Parameters:
        size - the capacity of the vector
        pad - the initial element
      • LNGBooleanVector

        public LNGBooleanVector​(LNGBooleanVector other)
        Copy constructor.
        Parameters:
        other - the other byte vector.
      • LNGBooleanVector

        public LNGBooleanVector​(boolean... elems)
        Creates a vector with the given elements.
        Parameters:
        elems - the elements
    • Method Detail

      • empty

        public boolean empty()
        Returns whether the vector is empty or not.
        Returns:
        true if the vector is empty, false otherwise
      • size

        public int size()
        Returns the size of the vector.
        Returns:
        the size of the vector
      • back

        public boolean back()
        Returns the last element of the vector and leaves it on the vector.
        Returns:
        the last element of the vector
      • push

        public void push​(boolean element)
        Pushes an element at the end of the vector.
        Parameters:
        element - the element to push
      • unsafePush

        public void unsafePush​(boolean element)
        Pushes an element and assumes that there is enough space on the vector.
        Parameters:
        element - the element to push
        Throws:
        ArrayIndexOutOfBoundsException - if there was not enough space on the vector
      • get

        public boolean get​(int position)
        Returns the element at a given position in the vector.
        Parameters:
        position - the position
        Returns:
        the element at the position
        Throws:
        ArrayIndexOutOfBoundsException - if the position is not found in the vector
      • set

        public void set​(int position,
                        boolean element)
        Sets an element at a given position in the vector.
        Parameters:
        position - the position
        element - the element
        Throws:
        ArrayIndexOutOfBoundsException - if the position is not found in the vector
      • pop

        public void pop()
        Removes the last element of the vector.
      • shrinkTo

        public void shrinkTo​(int newSize)
        Shrinks the vector to a given size if the new size is less than the current size. Otherwise, the size remains the same.
        Parameters:
        newSize - the new size
      • growTo

        public void growTo​(int size,
                           boolean pad)
        Grows the vector to a new size and initializes the new elements with a given value.
        Parameters:
        size - the new size
        pad - the value for new elements
      • removeElements

        public void removeElements​(int num)
        Removes a given number of elements from the vector.
        Parameters:
        num - the number of elements to remove.
        Throws:
        ArrayIndexOutOfBoundsException - if the number of elements to remove is larger than the size of the vector
      • reverseInplace

        public void reverseInplace()
        Reverses the content of this vector in-place.
      • clear

        public void clear()
        Clears the vector.
      • toArray

        public boolean[] toArray()
        Returns this vector's contents as an array.
        Returns:
        the array