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 import java.util.Comparator; 34 import java.util.Iterator; 35 36 /** 37 * An abstraction on the type of vector used in the library. 38 * 39 * @author leberre 40 */ 41 public interface IVec<T> extends Serializable { 42 43 /** 44 * @return the number of elements contained in the vector 45 */ 46 int size(); 47 48 /** 49 * Remove nofelems from the Vector. It is assumed that the number of 50 * elements to remove is smaller or equals to the current number of elements 51 * in the vector 52 * 53 * @param nofelems 54 * the number of elements to remove. 55 */ 56 void shrink(int nofelems); 57 58 /** 59 * reduce the Vector to exactly newsize elements 60 * 61 * @param newsize 62 * the new size of the vector. 63 */ 64 void shrinkTo(final int newsize); 65 66 /** 67 * Pop the last element on the stack. It is assumed that the stack is not 68 * empty! 69 */ 70 void pop(); 71 72 void growTo(final int newsize, final T pad); 73 74 void ensure(final int nsize); 75 76 IVec<T> push(final T elem); 77 78 /** 79 * To push an element in the vector when you know you have space for it. 80 * 81 * @param elem 82 */ 83 void unsafePush(T elem); 84 85 /** 86 * Insert an element at the very begining of the vector. The former first 87 * element is appended to the end of the vector in order to have a constant 88 * time operation. 89 * 90 * @param elem 91 * the element to put first in the vector. 92 */ 93 void insertFirst(final T elem); 94 95 void insertFirstWithShifting(final T elem); 96 97 void clear(); 98 99 /** 100 * return the latest element on the stack. It is assumed that the stack is 101 * not empty! 102 * 103 * @return the last (top) element on the stack 104 */ 105 T last(); 106 107 T get(int i); 108 109 void set(int i, T o); 110 111 /** 112 * Enleve un element qui se trouve dans le vecteur!!! 113 * 114 * @param elem 115 * un element du vecteur 116 */ 117 void remove(T elem); 118 119 /** 120 * Delete the ith element of the vector. The latest element of the vector 121 * replaces the removed element at the ith indexer. 122 * 123 * @param i 124 * the indexer of the element in the vector 125 * @return the former ith element of the vector that is now removed from the 126 * vector 127 */ 128 T delete(int i); 129 130 /** 131 * Ces operations devraient se faire en temps constant. Ce n'est pas le cas 132 * ici. 133 * 134 * @param copy 135 */ 136 void copyTo(IVec<T> copy); 137 138 <E> void copyTo(E[] dest); 139 140 /** 141 * Allow to access the internal representation of the vector as an array. 142 * Note that only the content of index 0 to size() should be taken into 143 * account. USE WITH CAUTION 144 * 145 * @return the internal representation of the Vector as an array. 146 */ 147 T[] toArray(); 148 149 /** 150 * Move the content of the vector into dest. Note that the vector become 151 * empty. The content of the vector is appended to dest. 152 * 153 * @param dest 154 * the vector where top put the content of this vector 155 */ 156 void moveTo(IVec<T> dest); 157 158 /** 159 * Move elements inside the vector. The content of the method is equivalent 160 * to: <code>vec[dest] = vec[source]</code> 161 * 162 * @param dest 163 * the index of the destination 164 * @param source 165 * the index of the source 166 */ 167 void moveTo(int dest, int source); 168 169 /* 170 * @param comparator 171 */ 172 void sort(Comparator<T> comparator); 173 174 void sortUnique(Comparator<T> comparator); 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 Iterator<T> iterator(); 185 186 /** 187 * 188 * @param element 189 * an object 190 * @return true iff element is found in the vector. 191 * @since 2.1 192 */ 193 boolean contains(T element); 194 195 /** 196 * @param element 197 * an object 198 * @return the index of the element if it is found in the vector, else -1. 199 * @since 2.2 200 */ 201 int indexOf(T element); 202 }