/** * Returns a string showing the contents of the heap formatted as a tree. * Makes no attempt at padding levels or handling wrapping. */ protected String showTree(PriorityBuffer h) { int count = 1; StringBuffer buffer = new StringBuffer(); for (int offset = 1; count < h.size() + 1; offset *= 2) { for (int i = offset; i < offset * 2; i++) { if (i < h.elements.length && h.elements[i] != null) buffer.append(h.elements[i] + " "); count++; } buffer.append('\n'); } return buffer.toString(); }
@VisibleForTesting synchronized boolean seek(WritableComparable<?> key) throws IOException { PriorityBuffer reheap = new PriorityBuffer(heap.size()); boolean result = false; for (Object obj : heap) { Index index = (Index) obj; try { WritableComparable<?> found = index.reader.getClosest(key, index.value, true); if (found != null && found.equals(key)) { result = true; } } catch (EOFException ex) { // thrown if key is beyond all data in the map } index.cached = false; reheap.add(index); } heap = reheap; return result; }
@VisibleForTesting synchronized boolean seek(WritableComparable<?> key) throws IOException { PriorityBuffer reheap = new PriorityBuffer(heap.size()); boolean result = false; for (Object obj : heap) { Index index = (Index) obj; try { WritableComparable<?> found = index.reader.getClosest(key, index.value, true); if (found != null && found.equals(key)) { result = true; } } catch (EOFException ex) { // thrown if key is beyond all data in the map } index.cached = false; reheap.add(index); } heap = reheap; return result; }
public synchronized boolean seek(WritableComparable key) throws IOException { PriorityBuffer reheap = new PriorityBuffer(heap.size()); boolean result = false; for (Object obj : heap) { Index index = (Index) obj; try { WritableComparable found = index.reader.getClosest(key, index.value, true); if (found != null && found.equals(key)) { result = true; } } catch (EOFException ex) { // thrown if key is beyond all data in the map } index.cached = false; reheap.add(index); } heap = reheap; return result; }