1 /******************************************************************************* 2 * SAT4J: a SATisfiability library for Java Copyright (C) 2004, 2012 Artois University and CNRS 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 * Contributors: 28 * CRIL - initial API and implementation 29 *******************************************************************************/ 30 package org.sat4j.specs; 31 32 import java.io.Serializable; 33 34 /** 35 * An abstraction for the vector of int used on the library. 36 * 37 * @author leberre 38 */ 39 public interface IVecInt extends Serializable { 40 41 int size(); 42 43 /** 44 * Remove the latest nofelems elements from the vector 45 * 46 * @param nofelems 47 */ 48 void shrink(int nofelems); 49 50 void shrinkTo(int newsize); 51 52 /** 53 * depile le dernier element du vecteur. Si le vecteur est vide, ne fait 54 * rien. 55 */ 56 IVecInt pop(); 57 58 void growTo(int newsize, final int pad); 59 60 void ensure(int nsize); 61 62 IVecInt push(int elem); 63 64 /** 65 * Push the element in the Vector without verifying if there is room for it. 66 * USE WITH CAUTION! 67 * 68 * @param elem 69 */ 70 void unsafePush(int elem); 71 72 int unsafeGet(int eleem); 73 74 void clear(); 75 76 int last(); 77 78 int get(int i); 79 80 void set(int i, int o); 81 82 boolean contains(int e); 83 84 /** 85 * @since 2.2 86 * @param e 87 * @return 88 */ 89 int indexOf(int e); 90 91 /** 92 * returns the index of the first occurrence of e, else -1. 93 * 94 * @param e 95 * an integer 96 * @return the index i such that get(i)==e, else -1. 97 */ 98 int containsAt(int e); 99 100 /** 101 * returns the index of the first occurence of e occurring after from 102 * (excluded), else -1. 103 * 104 * @param e 105 * an integer 106 * @param from 107 * the index to start from (excluded). 108 * @return the index i such that i>from and get(i)==e, else -1 109 */ 110 int containsAt(int e, int from); 111 112 /** 113 * C'est operations devraient se faire en temps constant. Ce n'est pas le 114 * cas ici. 115 * 116 * @param copy 117 */ 118 void copyTo(IVecInt copy); 119 120 /** 121 * @param is 122 */ 123 void copyTo(int[] is); 124 125 /* 126 * Copie un vecteur dans un autre (en vidant le premier), en temps constant. 127 */ 128 void moveTo(IVecInt dest); 129 130 void moveTo(int sourceStartingIndex, int[] dest); 131 132 void moveTo2(IVecInt dest); 133 134 void moveTo(int[] dest); 135 136 /** 137 * Move elements inside the vector. The content of the method is equivalent 138 * to: <code>vec[dest] = vec[source]</code> 139 * 140 * @param dest 141 * the index of the destination 142 * @param source 143 * the index of the source 144 */ 145 void moveTo(int dest, int source); 146 147 /** 148 * Insert an element at the very begining of the vector. The former first 149 * element is appended to the end of the vector in order to have a constant 150 * time operation. 151 * 152 * @param elem 153 * the element to put first in the vector. 154 */ 155 void insertFirst(final int elem); 156 157 /** 158 * Enleve un element qui se trouve dans le vecteur!!! 159 * 160 * @param elem 161 * un element du vecteur 162 */ 163 void remove(int elem); 164 165 /** 166 * Delete the ith element of the vector. The latest element of the vector 167 * replaces the removed element at the ith indexer. 168 * 169 * @param i 170 * the indexer of the element in the vector 171 * @return the former ith element of the vector that is now removed from the 172 * vector 173 */ 174 int delete(int i); 175 176 void sort(); 177 178 void sortUnique(); 179 180 /** 181 * To know if a vector is empty 182 * 183 * @return true iff the vector is empty. 184 * @since 1.6 185 */ 186 boolean isEmpty(); 187 188 IteratorInt iterator(); 189 190 /** 191 * Allow to access the internal representation of the vector as an array. 192 * Note that only the content of index 0 to size() should be taken into 193 * account. USE WITH CAUTION 194 * 195 * @return the internal representation of the Vector as an array. 196 * @since 2.1 197 */ 198 int[] toArray(); 199 200 /** 201 * Compute all subsets of cardinal k of the vector. 202 * 203 * @param k 204 * a cardinal (k<= vec.size()) 205 * @return an array of IVectInt representing each a k-subset of this vector. 206 * @author sroussel 207 * @since 2.3.1 208 */ 209 IVecInt[] subset(int k); 210 }