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