/** * Query the value of a single bit. Relying on this method when speed is * needed is discouraged. The complexity is linear with the size of the * bitmap. * * (This implementation is based on zhenjl's Go version of JavaEWAH.) * * The current bitmap is not modified. * * @param i the bit we are interested in * @return whether the bit is set to true */ publicbooleanget(finalint i){ ... }
privatevoidon_ewah(int[] arrays, int[] query){ for (int c = 0; c < 16; c ++) { executorService.execute(() -> { EWAHCompressedBitmap bitmap = new EWAHCompressedBitmap(); for (int i = 0; i < totalSize; i++) { bitmap.set(query[i]); } long startTime = System.currentTimeMillis(); Set<Integer> data = new HashSet<Integer>(bitmap.toList()); for (int i = 0; i < totalSize; i++) { int index = arrays[i]; if (data.contains(index)) { bitmap.clear(index); } } System.out.println("spend ewah [" + (System.currentTimeMillis() - startTime) + "] ms"); LATCH.countDown(); }); } }
@Override publicbooleancontains(char x){ int index = unsignedInterleavedBinarySearch(valueslength, 0, nbrruns, x); if (index >= 0) { returntrue; } index = -index - 2; // points to preceding value, possibly -1 if (index != -1) {// possible match int offset = (x) - (getValue(index)); int le = (getLength(index)); return offset <= le; } returnfalse; }