Lines 34-39
import java.util.concurrent.ExecutionException;
Link Here
|
34 |
import java.util.concurrent.ExecutorService; |
34 |
import java.util.concurrent.ExecutorService; |
35 |
import java.util.concurrent.Executors; |
35 |
import java.util.concurrent.Executors; |
36 |
import java.util.concurrent.Future; |
36 |
import java.util.concurrent.Future; |
|
|
37 |
import java.util.concurrent.RecursiveAction; |
38 |
import java.util.concurrent.SynchronousQueue; |
39 |
import java.util.concurrent.ThreadPoolExecutor; |
37 |
import java.util.concurrent.TimeUnit; |
40 |
import java.util.concurrent.TimeUnit; |
38 |
import java.util.function.Supplier; |
41 |
import java.util.function.Supplier; |
39 |
|
42 |
|
Lines 82-236
public abstract class IndexWriter
Link Here
|
82 |
// integer based indices |
85 |
// integer based indices |
83 |
// ////////////////////////////////////////////////////////////// |
86 |
// ////////////////////////////////////////////////////////////// |
84 |
|
87 |
|
85 |
public static class Identifier implements IIndexReader.IOne2LongIndex |
88 |
public static class Identifier extends MemoryMappedLongArray implements IIndexReader.IOne2LongIndex |
86 |
{ |
89 |
{ |
87 |
long[] identifiers; |
90 |
// all implementations in extended class |
88 |
int size; |
91 |
public Identifier() { |
89 |
|
92 |
super(null, 0, Integer.MAX_VALUE); |
90 |
public void add(long id) |
|
|
91 |
{ |
92 |
if (identifiers == null) |
93 |
{ |
94 |
identifiers = new long[10000]; |
95 |
size = 0; |
96 |
} |
97 |
|
98 |
if (size + 1 > identifiers.length) |
99 |
{ |
100 |
int minCapacity = size + 1; |
101 |
int newCapacity = newCapacity(identifiers.length, minCapacity); |
102 |
if (newCapacity < minCapacity) |
103 |
{ |
104 |
// Avoid strange exceptions later |
105 |
throw new OutOfMemoryError(MessageUtil.format(Messages.IndexWriter_Error_ArrayLength, minCapacity, newCapacity)); |
106 |
} |
107 |
identifiers = copyOf(identifiers, newCapacity); |
108 |
} |
109 |
|
110 |
identifiers[size++] = id; |
111 |
} |
112 |
|
113 |
public void sort() |
114 |
{ |
115 |
Arrays.parallelSort(identifiers, 0, size); |
116 |
} |
117 |
|
118 |
public int size() |
119 |
{ |
120 |
return size; |
121 |
} |
122 |
|
123 |
public long get(int index) |
124 |
{ |
125 |
if (index < 0 || index >= size) |
126 |
throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size); //$NON-NLS-1$//$NON-NLS-2$ |
127 |
|
128 |
return identifiers[index]; |
129 |
} |
93 |
} |
130 |
|
94 |
|
131 |
public int reverse(long val) |
95 |
public int reverse(long val) { |
132 |
{ |
96 |
return super.indexOf(val); |
133 |
int a, c; |
|
|
134 |
for (a = 0, c = size; a < c;) |
135 |
{ |
136 |
// Avoid overflow problems by using unsigned divide by 2 |
137 |
int b = (a + c) >>> 1; |
138 |
long probeVal = get(b); |
139 |
if (val < probeVal) |
140 |
{ |
141 |
c = b; |
142 |
} |
143 |
else if (probeVal < val) |
144 |
{ |
145 |
a = b + 1; |
146 |
} |
147 |
else |
148 |
{ |
149 |
return b; |
150 |
} |
151 |
} |
152 |
// Negative index indicates not found (and where to insert) |
153 |
return -1 - a; |
154 |
} |
155 |
|
156 |
public IteratorLong iterator() |
157 |
{ |
158 |
return new IteratorLong() |
159 |
{ |
160 |
|
161 |
int index = 0; |
162 |
|
163 |
public boolean hasNext() |
164 |
{ |
165 |
return index < size; |
166 |
} |
167 |
|
168 |
public long next() |
169 |
{ |
170 |
return identifiers[index++]; |
171 |
} |
172 |
|
173 |
}; |
174 |
} |
175 |
|
176 |
public long[] getNext(int index, int length) |
177 |
{ |
178 |
long answer[] = new long[length]; |
179 |
for (int ii = 0; ii < length; ii++) |
180 |
answer[ii] = identifiers[index + ii]; |
181 |
return answer; |
182 |
} |
183 |
|
184 |
public void close() throws IOException |
185 |
{} |
186 |
|
187 |
public void delete() |
188 |
{ |
189 |
identifiers = null; |
190 |
} |
191 |
|
192 |
public void unload() throws IOException |
193 |
{ |
194 |
throw new UnsupportedOperationException(); |
195 |
} |
97 |
} |
196 |
} |
98 |
} |
197 |
|
99 |
|
198 |
public static class IntIndexCollectorUncompressed |
100 |
public static class SizeIndexCollectorUncompressed { |
199 |
{ |
101 |
final MemoryMappedIntArray wrapped; |
200 |
int[] dataElements; |
102 |
public SizeIndexCollectorUncompressed(int size) { |
201 |
|
103 |
wrapped = new MemoryMappedIntArray(null, size, size); |
202 |
public IntIndexCollectorUncompressed(int size) |
|
|
203 |
{ |
204 |
dataElements = new int[size]; |
205 |
} |
206 |
|
207 |
public void set(int index, int value) |
208 |
{ |
209 |
dataElements[index] = value; |
210 |
} |
211 |
|
212 |
public int get(int index) |
213 |
{ |
214 |
return dataElements[index]; |
215 |
} |
216 |
|
217 |
public IIndexReader.IOne2OneIndex writeTo(File indexFile) throws IOException |
218 |
{ |
219 |
return new IntIndexStreamer().writeTo(indexFile, dataElements); |
220 |
} |
221 |
} |
222 |
|
223 |
/** |
224 |
* Store sizes of objects by |
225 |
* compressing the size to a 32-bit int. |
226 |
* @since 1.0 |
227 |
*/ |
228 |
public static class SizeIndexCollectorUncompressed extends IntIndexCollectorUncompressed |
229 |
{ |
230 |
|
231 |
public SizeIndexCollectorUncompressed(int size) |
232 |
{ |
233 |
super(size); |
234 |
} |
104 |
} |
235 |
|
105 |
|
236 |
/** |
106 |
/** |
Lines 280-297
public abstract class IndexWriter
Link Here
|
280 |
|
150 |
|
281 |
public void set(int index, long value) |
151 |
public void set(int index, long value) |
282 |
{ |
152 |
{ |
283 |
set(index, compress(value)); |
153 |
wrapped.set(index, compress(value)); |
|
|
154 |
} |
155 |
|
156 |
public int get(int index) |
157 |
{ |
158 |
return wrapped.get(index); |
284 |
} |
159 |
} |
285 |
|
160 |
|
286 |
public long getSize(int index) |
161 |
public long getSize(int index) |
287 |
{ |
162 |
{ |
288 |
int v = get(index); |
163 |
return expand(wrapped.get(index)); |
289 |
return expand(v); |
|
|
290 |
} |
164 |
} |
291 |
|
165 |
|
292 |
public IIndexReader.IOne2SizeIndex writeTo(File indexFile) throws IOException |
166 |
public IIndexReader.IOne2SizeIndex writeTo(File indexFile) throws IOException |
293 |
{ |
167 |
{ |
294 |
return new SizeIndexReader(new IntIndexStreamer().writeTo(indexFile, dataElements)); |
168 |
return new SizeIndexReader(new IntIndexStreamer().writeTo(indexFile, wrapped.iterator())); |
295 |
} |
169 |
} |
296 |
} |
170 |
} |
297 |
|
171 |
|