View Javadoc

1   /*******************************************************************************
2   * SAT4J: a SATisfiability library for Java Copyright (C) 2004-2008 Daniel Le Berre
3   *
4   * All rights reserved. This program and the accompanying materials
5   * are made available under the terms of the Eclipse Public License v1.0
6   * which accompanies this distribution, and is available at
7   * http://www.eclipse.org/legal/epl-v10.html
8   *
9   * Alternatively, the contents of this file may be used under the terms of
10  * either the GNU Lesser General Public License Version 2.1 or later (the
11  * "LGPL"), in which case the provisions of the LGPL are applicable instead
12  * of those above. If you wish to allow use of your version of this file only
13  * under the terms of the LGPL, and not to allow others to use your version of
14  * this file under the terms of the EPL, indicate your decision by deleting
15  * the provisions above and replace them with the notice and other provisions
16  * required by the LGPL. If you do not delete the provisions above, a recipient
17  * may use your version of this file under the terms of the EPL or the LGPL.
18  * 
19  * Based on the original MiniSat specification from:
20  * 
21  * An extensible SAT solver. Niklas Een and Niklas Sorensson. Proceedings of the
22  * Sixth International Conference on Theory and Applications of Satisfiability
23  * Testing, LNCS 2919, pp 502-518, 2003.
24  *
25  * See www.minisat.se for the original solver in C++.
26  * 
27  *******************************************************************************/
28  package org.sat4j.specs;
29  
30  import java.io.Serializable;
31  
32  /**
33   * An abstraction for the vector of int used on the library.
34   * 
35   * @author leberre
36   */
37  public interface IVecInt extends Serializable {
38  
39      public abstract int size();
40  
41      /**
42       * Remove the latest nofelems elements from the vector
43       * 
44       * @param nofelems
45       */
46      public abstract void shrink(int nofelems);
47  
48      public abstract void shrinkTo(int newsize);
49  
50      /**
51       * depile le dernier element du vecteur. Si le vecteur est vide, ne
52       * fait rien.
53       */
54      public abstract IVecInt pop();
55  
56      public abstract void growTo(int newsize, final int pad);
57  
58      public abstract void ensure(int nsize);
59  
60      public abstract IVecInt push(int elem);
61  
62      /**
63       * Push the element in the Vector without verifying if there is room for it.
64       * USE WITH CAUTION!
65       * 
66       * @param elem
67       */
68      void unsafePush(int elem);
69  
70      int unsafeGet(int eleem);
71  
72      public abstract void clear();
73  
74      public abstract int last();
75  
76      public abstract int get(int i);
77  
78      public abstract void set(int i, int o);
79  
80      public abstract boolean contains(int e);
81  
82      /**
83       * returns the index of the first occurrence of
84       * e, else -1.
85       * @param e an integer
86       * @return the index i such that get(i)==e, else -1.
87       */
88      public abstract int containsAt(int e);
89      
90      /**
91       * returns the index of the first occurence of e
92       * occurring after from (excluded), else -1.
93       * @param e an integer
94       * @param from the index to start from (excluded).
95       * @return the index i such that i>from and get(i)==e, else -1
96       */
97      public abstract int containsAt(int e, int from);
98      
99      /**
100      * C'est operations devraient se faire en temps constant. Ce n'est pas le
101      * cas ici.
102      * 
103      * @param copy
104      */
105     public abstract void copyTo(IVecInt copy);
106 
107     /**
108      * @param is
109      */
110     public abstract void copyTo(int[] is);
111 
112     /*
113      * Copie un vecteur dans un autre (en vidant le premier), en temps constant.
114      */
115     public abstract void moveTo(IVecInt dest);
116 
117     public abstract void moveTo2(IVecInt dest);
118 
119     public abstract void moveTo(int[] dest);
120 
121     /**
122      * Move elements inside the vector. The content of the method is equivalent
123      * to: <code>vec[dest] = vec[source]</code>
124      * 
125      * @param dest
126      *            the index of the destination
127      * @param source
128      *            the index of the source
129      */
130     void moveTo(int dest, int source);
131 
132     /**
133      * Insert an element at the very begining of the vector. The former first
134      * element is appended to the end of the vector in order to have a constant
135      * time operation.
136      * 
137      * @param elem
138      *            the element to put first in the vector.
139      */
140     public abstract void insertFirst(final int elem);
141 
142     /**
143      * Enleve un element qui se trouve dans le vecteur!!!
144      * 
145      * @param elem
146      *            un element du vecteur
147      */
148     public abstract void remove(int elem);
149 
150     /**
151      * Delete the ith element of the vector. The latest element of the vector
152      * replaces the removed element at the ith indexer.
153      * 
154      * @param i
155      *            the indexer of the element in the vector
156      * @return the former ith element of the vector that is now removed from the
157      *         vector
158      */
159     public abstract int delete(int i);
160 
161     public abstract void sort();
162 
163     public abstract void sortUnique();
164 
165     /**
166      * To know if a vector is empty
167      * 
168      * @return true iff the vector is empty.
169      * @since 1.6
170      */
171     boolean isEmpty();
172     
173     IteratorInt iterator();
174     
175     /**
176      * Allow to access the internal representation of the vector as an array.
177      * Note that only the content of index 0 to size() should be taken into
178      * account. USE WITH CAUTION
179      * 
180      * @return the internal representation of the Vector as an array.
181      */
182     int [] toArray();
183 }