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 moveTo2(IVecInt dest);
129 
130 	public abstract void moveTo(int[] dest);
131 
132 	/**
133 	 * Move elements inside the vector. The content of the method is equivalent
134 	 * to: <code>vec[dest] = vec[source]</code>
135 	 * 
136 	 * @param dest
137 	 *            the index of the destination
138 	 * @param source
139 	 *            the index of the source
140 	 */
141 	void moveTo(int dest, int source);
142 
143 	/**
144 	 * Insert an element at the very begining of the vector. The former first
145 	 * element is appended to the end of the vector in order to have a constant
146 	 * time operation.
147 	 * 
148 	 * @param elem
149 	 *            the element to put first in the vector.
150 	 */
151 	public abstract void insertFirst(final int elem);
152 
153 	/**
154 	 * Enleve un element qui se trouve dans le vecteur!!!
155 	 * 
156 	 * @param elem
157 	 *            un element du vecteur
158 	 */
159 	public abstract void remove(int elem);
160 
161 	/**
162 	 * Delete the ith element of the vector. The latest element of the vector
163 	 * replaces the removed element at the ith indexer.
164 	 * 
165 	 * @param i
166 	 *            the indexer of the element in the vector
167 	 * @return the former ith element of the vector that is now removed from the
168 	 *         vector
169 	 */
170 	public abstract int delete(int i);
171 
172 	public abstract void sort();
173 
174 	public abstract void sortUnique();
175 
176 	/**
177 	 * To know if a vector is empty
178 	 * 
179 	 * @return true iff the vector is empty.
180 	 * @since 1.6
181 	 */
182 	boolean isEmpty();
183 
184 	IteratorInt iterator();
185 
186 	/**
187 	 * Allow to access the internal representation of the vector as an array.
188 	 * Note that only the content of index 0 to size() should be taken into
189 	 * account. USE WITH CAUTION
190 	 * 
191 	 * @return the internal representation of the Vector as an array.
192 	 * @since 2.1
193 	 */
194 	int[] toArray();
195 }