org.sat4j.core
Class VecInt

java.lang.Object
  extended by org.sat4j.core.VecInt
All Implemented Interfaces:
Serializable, IVecInt

public final class VecInt
extends Object
implements IVecInt

A vector specific for primitive integers, widely used in the solver. Note that if the vector has a sort method, the operations on the vector DO NOT preserve sorting.

Author:
leberre
See Also:
Serialized Form

Field Summary
static IVecInt EMPTY
           
 
Constructor Summary
VecInt()
           
VecInt(int size)
           
VecInt(int[] lits)
          Adapter method to translate an array of int into an IVecInt.
VecInt(int size, int pad)
          Build a vector of a given initial size filled with an integer.
 
Method Summary
 void clear()
           
 boolean contains(int e)
           
 int containsAt(int e)
          returns the index of the first occurrence of e, else -1.
 int containsAt(int e, int from)
          returns the index of the first occurence of e occurring after from (excluded), else -1.
 void copyTo(int[] is)
          Copy the content of this vector into an array of integer.
 void copyTo(IVecInt copy)
          Copy the content of this vector into another one.
 int delete(int i)
          Delete the ith element of the vector.
 void ensure(int nsize)
           
 boolean equals(Object obj)
          Two vectors are equals iff they have the very same elements in the order.
 int get(int i)
           
 void growTo(int newsize, int pad)
           
 int hashCode()
           
 int indexOf(int e)
           
 void insertFirst(int elem)
          Insert an element at the very begining of the vector.
 boolean isEmpty()
          To know if a vector is empty
 boolean isSubsetOf(VecInt vec)
          to detect that the vector is a subset of another one.
 IteratorInt iterator()
           
 int last()
           
 void moveTo(int[] dest)
           
 void moveTo(int dest, int source)
          Move elements inside the vector.
 void moveTo(IVecInt dest)
           
 void moveTo2(IVecInt dest)
           
 IVecInt pop()
          depile le dernier element du vecteur.
 IVecInt push(int elem)
           
 void pushAll(IVecInt vec)
           
 void remove(int elem)
          Enleve un element qui se trouve dans le vecteur!!!
 void set(int i, int o)
           
 void shrink(int nofelems)
          Remove the latest nofelems elements from the vector
 void shrinkTo(int newsize)
           
 int size()
           
 void sort()
          sort the vector using a custom quicksort.
 void sortUnique()
           
 int[] toArray()
          Allow to access the internal representation of the vector as an array.
 String toString()
           
 int unsafeGet(int i)
           
 void unsafePush(int elem)
          Push the element in the Vector without verifying if there is room for it.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final IVecInt EMPTY
Constructor Detail

VecInt

public VecInt()

VecInt

public VecInt(int size)

VecInt

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

Parameters:
lits - a filled array of int.

VecInt

public VecInt(int size,
              int pad)
Build a vector of a given initial size filled with an integer.

Parameters:
size - the initial size of the vector
pad - the integer to fill the vector with
Method Detail

size

public int size()
Specified by:
size in interface IVecInt

shrink

public void shrink(int nofelems)
Remove the latest nofelems elements from the vector

Specified by:
shrink in interface IVecInt
Parameters:
nofelems -

shrinkTo

public void shrinkTo(int newsize)
Specified by:
shrinkTo in interface IVecInt

pop

public IVecInt pop()
depile le dernier element du vecteur. Si le vecteur est vide, ne fait rien.

Specified by:
pop in interface IVecInt

growTo

public void growTo(int newsize,
                   int pad)
Specified by:
growTo in interface IVecInt

ensure

public void ensure(int nsize)
Specified by:
ensure in interface IVecInt

push

public IVecInt push(int elem)
Specified by:
push in interface IVecInt

unsafePush

public void unsafePush(int elem)
Description copied from interface: IVecInt
Push the element in the Vector without verifying if there is room for it. USE WITH CAUTION!

Specified by:
unsafePush in interface IVecInt

clear

public void clear()
Specified by:
clear in interface IVecInt

last

public int last()
Specified by:
last in interface IVecInt

get

public int get(int i)
Specified by:
get in interface IVecInt

unsafeGet

public int unsafeGet(int i)
Specified by:
unsafeGet in interface IVecInt

set

public void set(int i,
                int o)
Specified by:
set in interface IVecInt

contains

public boolean contains(int e)
Specified by:
contains in interface IVecInt

indexOf

public int indexOf(int e)
Specified by:
indexOf in interface IVecInt
Returns:
Since:
2.2

containsAt

public int containsAt(int e)
Description copied from interface: IVecInt
returns the index of the first occurrence of e, else -1.

Specified by:
containsAt in interface IVecInt
Parameters:
e - an integer
Returns:
the index i such that get(i)==e, else -1.

containsAt

public int containsAt(int e,
                      int from)
Description copied from interface: IVecInt
returns the index of the first occurence of e occurring after from (excluded), else -1.

Specified by:
containsAt in interface IVecInt
Parameters:
e - an integer
from - the index to start from (excluded).
Returns:
the index i such that i>from and get(i)==e, else -1

copyTo

public void copyTo(IVecInt copy)
Copy the content of this vector into another one. Non constant time operation.

Specified by:
copyTo in interface IVecInt
Parameters:
copy -

copyTo

public void copyTo(int[] is)
Copy the content of this vector into an array of integer. Non constant time operation.

Specified by:
copyTo in interface IVecInt
Parameters:
is -

moveTo

public void moveTo(IVecInt dest)
Specified by:
moveTo in interface IVecInt

moveTo2

public void moveTo2(IVecInt dest)
Specified by:
moveTo2 in interface IVecInt

moveTo

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

Specified by:
moveTo in interface IVecInt
Parameters:
dest - the index of the destination
source - the index of the source

moveTo

public void moveTo(int[] dest)
Specified by:
moveTo in interface IVecInt

insertFirst

public void insertFirst(int 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 IVecInt
Parameters:
elem - the element to put first in the vector.

remove

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

Specified by:
remove in interface IVecInt
Parameters:
elem - un element du vecteur

delete

public int 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 IVecInt
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

toString

public String toString()
Overrides:
toString in class Object

sort

public void sort()
sort the vector using a custom quicksort.

Specified by:
sort in interface IVecInt

sortUnique

public void sortUnique()
Specified by:
sortUnique in interface IVecInt

equals

public boolean equals(Object obj)
Two vectors are equals iff they have the very same elements in the order.

Overrides:
equals in class Object
Parameters:
obj - an object
Returns:
true iff obj is a VecInt and has the same elements as this vector at each index.
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

pushAll

public void pushAll(IVecInt vec)

isSubsetOf

public boolean isSubsetOf(VecInt vec)
to detect that the vector is a subset of another one. Note that the method assumes that the two vectors are sorted!

Parameters:
vec - a vector
Returns:
true iff the current vector is a subset of vec

iterator

public IteratorInt iterator()
Specified by:
iterator in interface IVecInt

isEmpty

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

Specified by:
isEmpty in interface IVecInt
Returns:
true iff the vector is empty.

toArray

public int[] toArray()
Description copied from interface: IVecInt
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 IVecInt
Returns:
the internal representation of the Vector as an array.
Since:
2.1


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