View Javadoc

1   /*
2    * SAT4J: a SATisfiability library for Java Copyright (C) 2004-2006 Daniel Le Berre
3    * 
4    * Based on the original minisat specification from:
5    * 
6    * An extensible SAT solver. Niklas E?n and Niklas S?rensson. Proceedings of the
7    * Sixth International Conference on Theory and Applications of Satisfiability
8    * Testing, LNCS 2919, pp 502-518, 2003.
9    * 
10   * This library is free software; you can redistribute it and/or modify it under
11   * the terms of the GNU Lesser General Public License as published by the Free
12   * Software Foundation; either version 2.1 of the License, or (at your option)
13   * any later version.
14   * 
15   * This library is distributed in the hope that it will be useful, but WITHOUT
16   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18   * details.
19   * 
20   * You should have received a copy of the GNU Lesser General Public License
21   * along with this library; if not, write to the Free Software Foundation, Inc.,
22   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23   * 
24   */
25  
26  package org.sat4j.specs;
27  
28  import java.util.Comparator;
29  
30  /**
31   * An abstraction on the type of vector used in the library.
32   * 
33   * @author leberre
34   */
35  public interface IVec<T> extends Iterable<T> {
36      /**
37       * @return the number of elements contained in the vector
38       */
39      int size();
40  
41      /**
42       * Remove nofelems from the Vector. It is assumed that the number of
43       * elements to remove is smaller or equals to the current number of elements
44       * in the vector
45       * 
46       * @param nofelems
47       *            the number of elements to remove.
48       */
49      void shrink(int nofelems);
50  
51      /**
52       * reduce the Vector to exactly newsize elements
53       * 
54       * @param newsize
55       *            the new size of the vector.
56       */
57      void shrinkTo(final int newsize);
58  
59      /**
60       * Pop the last element on the stack. It is assumed that the stack is not
61       * empty!
62       */
63      void pop();
64  
65      void growTo(final int newsize, final T pad);
66  
67      void ensure(final int nsize);
68  
69      IVec<T> push(final T elem);
70  
71      /**
72       * To push an element in the vector when you know you have space for it.
73       * 
74       * @param elem
75       */
76      void unsafePush(T elem);
77  
78      /**
79       * Insert an element at the very begining of the vector. The former first
80       * element is appended to the end of the vector in order to have a constant
81       * time operation.
82       * 
83       * @param elem
84       *            the element to put first in the vector.
85       */
86      void insertFirst(final T elem);
87  
88      void insertFirstWithShifting(final T elem);
89  
90      void clear();
91  
92      /**
93       * return the latest element on the stack. It is assumed that the stack is
94       * not empty!
95       * 
96       * @return the last (top) element on the stack
97       */
98      T last();
99  
100     T get(int i);
101 
102     void set(int i, T o);
103 
104     /**
105      * Enleve un element qui se trouve dans le vecteur!!!
106      * 
107      * @param elem
108      *            un element du vecteur
109      */
110     void remove(T elem);
111 
112     /**
113      * Delete the ith element of the vector. The latest element of the vector
114      * replaces the removed element at the ith indexer.
115      * 
116      * @param i
117      *            the indexer of the element in the vector
118      * @return the former ith element of the vector that is now removed from the
119      *         vector
120      */
121     T delete(int i);
122 
123     /**
124      * Ces operations devraient se faire en temps constant. Ce n'est pas le
125      * cas ici.
126      * 
127      * @param copy
128      */
129     void copyTo(IVec<T> copy);
130 
131     <E> void copyTo(E[] dest);
132 
133     /**
134      * Allow to access the internal representation of the vector as an array.
135      * Note that only the content of index 0 to size() should be taken into
136      * account. USE WITH CAUTION
137      * 
138      * @return the internal represnetation of the Vector as an array.
139      */
140     T[] toArray();
141 
142     /**
143      * Move the content of the vector into dest. Note that the vector become
144      * empty. The content of the vector is appended to dest.
145      * 
146      * @param dest
147      *            the vector where top put the content of this vector
148      */
149     void moveTo(IVec<T> dest);
150 
151     /**
152      * Move elements inside the vector. The content of the method is equivalent
153      * to: <code>vec[dest] = vec[source]</code>
154      * 
155      * @param dest
156      *            the index of the destination
157      * @param source
158      *            the index of the source
159      */
160     void moveTo(int dest, int source);
161 
162     /*
163      * @param comparator
164      */
165     void sort(Comparator<T> comparator);
166 
167     void sortUnique(Comparator<T> comparator);
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 }