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 fait
52 * 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 e, else -1.
84 *
85 * @param e
86 * an integer
87 * @return the index i such that get(i)==e, else -1.
88 */
89 public abstract int containsAt(int e);
90
91 /**
92 * returns the index of the first occurence of e occurring after from
93 * (excluded), else -1.
94 *
95 * @param e
96 * an integer
97 * @param from
98 * the index to start from (excluded).
99 * @return the index i such that i>from and get(i)==e, else -1
100 */
101 public abstract int containsAt(int e, int from);
102
103 /**
104 * C'est operations devraient se faire en temps constant. Ce n'est pas le
105 * cas ici.
106 *
107 * @param copy
108 */
109 public abstract void copyTo(IVecInt copy);
110
111 /**
112 * @param is
113 */
114 public abstract void copyTo(int[] is);
115
116 /*
117 * Copie un vecteur dans un autre (en vidant le premier), en temps constant.
118 */
119 public abstract void moveTo(IVecInt dest);
120
121 public abstract void moveTo2(IVecInt dest);
122
123 public abstract void moveTo(int[] dest);
124
125 /**
126 * Move elements inside the vector. The content of the method is equivalent
127 * to: <code>vec[dest] = vec[source]</code>
128 *
129 * @param dest
130 * the index of the destination
131 * @param source
132 * the index of the source
133 */
134 void moveTo(int dest, int source);
135
136 /**
137 * Insert an element at the very begining of the vector. The former first
138 * element is appended to the end of the vector in order to have a constant
139 * time operation.
140 *
141 * @param elem
142 * the element to put first in the vector.
143 */
144 public abstract void insertFirst(final int elem);
145
146 /**
147 * Enleve un element qui se trouve dans le vecteur!!!
148 *
149 * @param elem
150 * un element du vecteur
151 */
152 public abstract void remove(int elem);
153
154 /**
155 * Delete the ith element of the vector. The latest element of the vector
156 * replaces the removed element at the ith indexer.
157 *
158 * @param i
159 * the indexer of the element in the vector
160 * @return the former ith element of the vector that is now removed from the
161 * vector
162 */
163 public abstract int delete(int i);
164
165 public abstract void sort();
166
167 public abstract void sortUnique();
168
169 /**
170 * To know if a vector is empty
171 *
172 * @return true iff the vector is empty.
173 * @since 1.6
174 */
175 boolean isEmpty();
176
177 IteratorInt iterator();
178
179 /**
180 * Allow to access the internal representation of the vector as an array.
181 * Note that only the content of index 0 to size() should be taken into
182 * account. USE WITH CAUTION
183 *
184 * @return the internal representation of the Vector as an array.
185 * @since 2.1
186 */
187 int[] toArray();
188 }