|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
IntQueue.java | 16,7% | 50% | 83,3% | 50% |
|
1 | /* | |
2 | * MiniSAT in Java, a Java based-SAT framework | |
3 | * Copyright (C) 2004 Daniel Le Berre | |
4 | * | |
5 | * Based on the original minisat specification from: | |
6 | * | |
7 | * An extensible SAT solver. Niklas Eï¿œn and Niklas Sï¿œrensson. | |
8 | * Proceedings of the Sixth International Conference on Theory | |
9 | * and Applications of Satisfiability Testing, LNCS 2919, | |
10 | * pp 502-518, 2003. | |
11 | * | |
12 | * This library is free software; you can redistribute it and/or | |
13 | * modify it under the terms of the GNU Lesser General Public | |
14 | * License as published by the Free Software Foundation; either | |
15 | * version 2.1 of the License, or (at your option) any later version. | |
16 | * | |
17 | * This library is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | * Lesser General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU Lesser General Public | |
23 | * License along with this library; if not, write to the Free Software | |
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
25 | * | |
26 | */ | |
27 | ||
28 | package org.sat4j.minisat.core; | |
29 | ||
30 | import java.io.Serializable; | |
31 | ||
32 | /* | |
33 | * Created on 9 oct. 2003 | |
34 | */ | |
35 | ||
36 | /** | |
37 | * @author leberre Implantation d'une queue ᅵ l'aide d'un tableau | |
38 | */ | |
39 | public final class IntQueue implements Serializable { | |
40 | ||
41 | private static final long serialVersionUID = 1L; | |
42 | ||
43 | private static final int INITIAL_QUEUE_CAPACITY = 10; | |
44 | ||
45 | /** | |
46 | * Add an element to the queue. | |
47 | * The queue is supposed to be large enough for that! | |
48 | * @param x the element to add | |
49 | */ | |
50 | 24 | public void insert(final int x) { |
51 | // ensure(size + 1); | |
52 | assert size < myarray.length; | |
53 | 24 | myarray[size++] = x; |
54 | } | |
55 | ||
56 | /** | |
57 | * returns the nexdt element in the queue. | |
58 | * Unexpected results if the queue is empty! | |
59 | * | |
60 | * @return the firsst element on the queue | |
61 | */ | |
62 | 20 | public int dequeue() { |
63 | assert first < size; | |
64 | 20 | return myarray[first++]; |
65 | } | |
66 | ||
67 | /** | |
68 | * Vide la queue | |
69 | */ | |
70 | 1 | public void clear() { |
71 | 1 | size = 0; |
72 | 1 | first = 0; |
73 | } | |
74 | ||
75 | /** | |
76 | * Pour connaï¿œtre la taille de la queue. | |
77 | * | |
78 | * @return le nombre d'ï¿œlï¿œments restant dans la queue | |
79 | */ | |
80 | 11 | public int size() { |
81 | 11 | return size - first; |
82 | } | |
83 | ||
84 | /** | |
85 | * Utilisï¿œe pour accroï¿œtre dynamiquement la taille de la queue. | |
86 | * | |
87 | * @param nsize | |
88 | * la taille maximale de la queue | |
89 | */ | |
90 | 1 | public void ensure(final int nsize) { |
91 | 1 | if (nsize >= myarray.length) { |
92 | 1 | int[] narray = new int[Math.max(nsize, size * 2)]; |
93 | 1 | System.arraycopy(myarray, 0, narray, 0, size); |
94 | 1 | myarray = narray; |
95 | } | |
96 | } | |
97 | ||
98 | 0 | @Override |
99 | public String toString() { | |
100 | 0 | StringBuffer stb = new StringBuffer(); |
101 | 0 | stb.append(">"); |
102 | 0 | for (int i = first; i < size - 1; i++) { |
103 | 0 | stb.append(myarray[i]); |
104 | 0 | stb.append(" "); |
105 | } | |
106 | 0 | if (first != size) { |
107 | 0 | stb.append(myarray[size - 1]); |
108 | } | |
109 | 0 | stb.append("<"); |
110 | 0 | return stb.toString(); |
111 | } | |
112 | ||
113 | private int[] myarray = new int[INITIAL_QUEUE_CAPACITY]; | |
114 | ||
115 | private int size = 0; | |
116 | ||
117 | private int first = 0; | |
118 | ||
119 | } |
|