org.sat4j.core
Class Vec<T>

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

public class Vec<T>
extends java.lang.Object
implements java.io.Serializable, IVec<T>

Simple but efficient vector implementation, based on the vector implementation available in MiniSAT.

Author:
leberre
See Also:
Serialized Form

Constructor Summary
Vec()
           
Vec(int size)
           
Vec(int size, T pad)
          Construit un vecteur contenant de taille size rempli � l'aide de size pad.
 
Method Summary
 void clear()
           
<E> void
copyTo(E[] dest)
           
 void copyTo(IVec<T> copy)
          Ces op�rations devraient se faire en temps constant.
static
<A extends java.lang.Comparable<A>>
java.util.Comparator<A>
defaultComparator()
           
 T delete(int i)
          Delete the ith element of the vector.
 void ensure(int nsize)
           
 boolean equals(java.lang.Object obj)
           
 T get(int i)
           
 void growTo(int newsize, T pad)
           
 int hashCode()
           
 void insertFirst(T elem)
          Insert an element at the very begining of the vector.
 void insertFirstWithShifting(T elem)
           
 java.util.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)
          Enleve un element qui se trouve dans le vecteur!!!
 void set(int i, T o)
           
 void shrink(int nofelems)
          Remove nofelems from the Vector.
 void shrinkTo(int newsize)
          reduce the Vector to exactly newsize elements
 int size()
           
 void sort(java.util.Comparator<T> comparator)
           
 void sortUnique(java.util.Comparator<T> cmp)
           
 java.lang.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
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vec

public Vec()

Vec

public Vec(int size)

Vec

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

Parameters:
size - la taille du vecteur
pad - l'objet servant � 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 final 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 begining 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 i)
Specified by:
get in interface IVec<T>

set

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

remove

public void remove(T elem)
Enleve un element qui se trouve dans le vecteur!!!

Specified by:
remove in interface IVec<T>
Parameters:
elem - un element du vecteur

delete

public T delete(int i)
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:
i - 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 op�rations 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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

sort

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

sortUnique

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

defaultComparator

public static final <A extends java.lang.Comparable<A>> java.util.Comparator<A> defaultComparator()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

iterator

public java.util.Iterator<T> iterator()
Specified by:
iterator in interface java.lang.Iterable<T>