org.sat4j.core
Class Vec<T>

java.lang.Object
  extended by org.sat4j.core.Vec<T>
All Implemented Interfaces:
Serializable, IVec<T>

public final class Vec<T>
extends Object
implements IVec<T>

Simple but efficient vector implementation, based on the vector implementation available in MiniSAT. Note that the elements are compared using their references, not using the equals method.

Author:
leberre
See Also:
Serialized Form

Constructor Summary
Vec()
          Create a Vector with an initial capacity of 5 elements.
Vec(int size)
          Create a Vector with a given capacity.
Vec(int size, T pad)
          Construit un vecteur contenant de taille size rempli a l'aide de size pad.
Vec(T[] elts)
          Adapter method to translate an array of int into an IVec.
 
Method Summary
 void clear()
           
 boolean contains(T e)
           
<E> void
copyTo(E[] dest)
           
 void copyTo(IVec<T> copy)
          Ces operations devraient se faire en temps constant.
 T delete(int index)
          Delete the ith element of the vector.
 void ensure(int nsize)
           
 boolean equals(Object obj)
           
 T get(int index)
           
 void growTo(int newsize, T pad)
           
 int hashCode()
           
 int indexOf(T element)
           
 void insertFirst(T elem)
          Insert an element at the very beginning of the vector.
 void insertFirstWithShifting(T elem)
           
 boolean isEmpty()
          To know if a vector is empty
 Iterator<T> iterator()
           
 T last()
          return the latest element on the stack.
 void moveTo(int dest, int source)
          Move elements inside the vector.
 void moveTo(IVec<T> dest)
          Move the content of the vector into dest.
 void pop()
          Pop the last element on the stack.
 IVec<T> push(T elem)
           
 void remove(T elem)
          Remove an element that belongs to the Vector.
 void set(int index, T elem)
           
 void shrink(int nofelems)
          Remove nofelems from the Vector.
 void shrinkTo(int newsize)
          reduce the Vector to exactly newsize elements
 int size()
           
 void sort(Comparator<T> comparator)
           
 void sortUnique(Comparator<T> cmp)
           
 T[] toArray()
          Allow to access the internal representation of the vector as an array.
 String toString()
           
 void unsafePush(T elem)
          To push an element in the vector when you know you have space for it.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vec

public Vec()
Create a Vector with an initial capacity of 5 elements.


Vec

public Vec(T[] elts)
Adapter method to translate an array of int into an IVec. The array is used inside the Vec, so the elements may be modified outside the Vec. But it should not take much memory. The size of the created Vec is the length of the array.

Parameters:
elts - a filled array of T.

Vec

public Vec(int size)
Create a Vector with a given capacity.

Parameters:
size - the capacity of the vector.

Vec

public Vec(int size,
           T pad)
Construit un vecteur contenant de taille size rempli a l'aide de size pad.

Parameters:
size - la taille du vecteur
pad - l'objet servant a remplir le vecteur
Method Detail

size

public int size()
Specified by:
size in interface IVec<T>
Returns:
the number of elements contained in the vector

shrink

public void shrink(int nofelems)
Remove nofelems from the Vector. It is assumed that the number of elements to remove is smaller or equals to the current number of elements in the vector

Specified by:
shrink in interface IVec<T>
Parameters:
nofelems - the number of elements to remove.

shrinkTo

public void shrinkTo(int newsize)
reduce the Vector to exactly newsize elements

Specified by:
shrinkTo in interface IVec<T>
Parameters:
newsize - the new size of the vector.

pop

public void pop()
Pop the last element on the stack. It is assumed that the stack is not empty!

Specified by:
pop in interface IVec<T>

growTo

public void growTo(int newsize,
                   T pad)
Specified by:
growTo in interface IVec<T>

ensure

public void ensure(int nsize)
Specified by:
ensure in interface IVec<T>

push

public IVec<T> push(T elem)
Specified by:
push in interface IVec<T>

unsafePush

public void unsafePush(T elem)
Description copied from interface: IVec
To push an element in the vector when you know you have space for it.

Specified by:
unsafePush in interface IVec<T>

insertFirst

public void insertFirst(T elem)
Insert an element at the very beginning of the vector. The former first element is appended to the end of the vector in order to have a constant time operation.

Specified by:
insertFirst in interface IVec<T>
Parameters:
elem - the element to put first in the vector.

insertFirstWithShifting

public void insertFirstWithShifting(T elem)
Specified by:
insertFirstWithShifting in interface IVec<T>

clear

public void clear()
Specified by:
clear in interface IVec<T>

last

public T last()
return the latest element on the stack. It is assumed that the stack is not empty!

Specified by:
last in interface IVec<T>
Returns:
the last element on the stack (the one on the top)

get

public T get(int index)
Specified by:
get in interface IVec<T>

set

public void set(int index,
                T elem)
Specified by:
set in interface IVec<T>

remove

public void remove(T elem)
Remove an element that belongs to the Vector. The method will break if the element does not belong to the vector.

Specified by:
remove in interface IVec<T>
Parameters:
elem - an element from the vector.

delete

public T delete(int index)
Delete the ith element of the vector. The latest element of the vector replaces the removed element at the ith indexer.

Specified by:
delete in interface IVec<T>
Parameters:
index - the indexer of the element in the vector
Returns:
the former ith element of the vector that is now removed from the vector

copyTo

public void copyTo(IVec<T> copy)
Ces operations devraient se faire en temps constant. Ce n'est pas le cas ici.

Specified by:
copyTo in interface IVec<T>
Parameters:
copy -

copyTo

public <E> void copyTo(E[] dest)
Specified by:
copyTo in interface IVec<T>
Parameters:
dest -

moveTo

public void moveTo(IVec<T> dest)
Description copied from interface: IVec
Move the content of the vector into dest. Note that the vector become empty. The content of the vector is appended to dest.

Specified by:
moveTo in interface IVec<T>
Parameters:
dest - the vector where top put the content of this vector

moveTo

public void moveTo(int dest,
                   int source)
Description copied from interface: IVec
Move elements inside the vector. The content of the method is equivalent to: vec[dest] = vec[source]

Specified by:
moveTo in interface IVec<T>
Parameters:
dest - the index of the destination
source - the index of the source

toArray

public T[] toArray()
Description copied from interface: IVec
Allow to access the internal representation of the vector as an array. Note that only the content of index 0 to size() should be taken into account. USE WITH CAUTION

Specified by:
toArray in interface IVec<T>
Returns:
the internal representation of the Vector as an array.

toString

public String toString()
Overrides:
toString in class Object

sort

public void sort(Comparator<T> comparator)
Specified by:
sort in interface IVec<T>
Parameters:
comparator -

sortUnique

public void sortUnique(Comparator<T> cmp)
Specified by:
sortUnique in interface IVec<T>

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface IVec<T>

isEmpty

public boolean isEmpty()
Description copied from interface: IVec
To know if a vector is empty

Specified by:
isEmpty in interface IVec<T>
Returns:
true iff the vector is empty.

contains

public boolean contains(T e)
Specified by:
contains in interface IVec<T>
Parameters:
e - an object
Returns:
true iff element is found in the vector.
Since:
2.1

indexOf

public int indexOf(T element)
Specified by:
indexOf in interface IVec<T>
Parameters:
element - an object
Returns:
the index of the element if it is found in the vector, else -1.
Since:
2.2


Copyright © 2012 Centre de Recherche en Informatique de Lens (CRIL). All Rights Reserved.