- java.lang.Object
-
- org.logicng.collections.LNGDoubleVector
-
public final class LNGDoubleVector extends Object
A simple vector for double elements implementation (inspired by MiniSat, CleaneLing, Sat4J).In theory one could use the
LNGVectoralso for doubles. 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.1
-
-
Constructor Summary
Constructors Constructor Description LNGDoubleVector()Creates a vector with an initial capacity of 5 elements.LNGDoubleVector(double... elems)Creates a vector with the given elements.LNGDoubleVector(int size)Creates a vector with a given capacity.LNGDoubleVector(int size, double pad)Creates a vector with a given capacity and a given initial element.LNGDoubleVector(LNGDoubleVector other)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doubleback()Returns the last element of the vector and leaves it on the vector.voidclear()Clears the vector.booleanempty()Returns whether the vector is empty or not.doubleget(int position)Returns the element at a given position in the vector.voidgrowTo(int size, double pad)Grows the vector to a new size and initializes the new elements with a given value.voidpop()Removes the last element of the vector.voidpush(double element)Pushes an element at the end of the vector.voidremoveElements(int num)Removes a given number of elements from the vector.voidset(int position, double element)Sets an element at a given position in the vector.voidshrinkTo(int newSize)Shrinks the vector to a given size.intsize()Returns the size of the vector.voidsort()Sorts this vector.voidsortReverse()Sorts this vector in reverse order.double[]toArray()Returns this vector's contents as an array.StringtoString()voidunsafePush(double element)Pushes an element and assumes that there is enough space on the vector.
-
-
-
Constructor Detail
-
LNGDoubleVector
public LNGDoubleVector()
Creates a vector with an initial capacity of 5 elements.
-
LNGDoubleVector
public LNGDoubleVector(int size)
Creates a vector with a given capacity.- Parameters:
size- the capacity of the vector.
-
LNGDoubleVector
public LNGDoubleVector(int size, double pad)Creates a vector with a given capacity and a given initial element.- Parameters:
size- the capacity of the vectorpad- the initial element
-
LNGDoubleVector
public LNGDoubleVector(LNGDoubleVector other)
Copy constructor.- Parameters:
other- the other byte vector.
-
LNGDoubleVector
public LNGDoubleVector(double... 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:
trueif the vector is empty,falseotherwise
-
size
public int size()
Returns the size of the vector.- Returns:
- the size of the vector
-
back
public double 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(double element)
Pushes an element at the end of the vector.- Parameters:
element- the element to push
-
unsafePush
public void unsafePush(double 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 double 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, double element)Sets an element at a given position in the vector.- Parameters:
position- the positionelement- 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.- Parameters:
newSize- the new size
-
growTo
public void growTo(int size, double pad)Grows the vector to a new size and initializes the new elements with a given value.- Parameters:
size- the new sizepad- 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
-
clear
public void clear()
Clears the vector.
-
sort
public void sort()
Sorts this vector.
-
sortReverse
public void sortReverse()
Sorts this vector in reverse order.
-
toArray
public double[] toArray()
Returns this vector's contents as an array.- Returns:
- the array
-
-