/** * Pops all elements from the heap and verifies that the elements come off * in the correct order. NOTE: this method empties the heap. */ protected void checkOrder(PriorityBuffer h) { Integer lastNum = null; Integer num = null; while (!h.isEmpty()) { num = (Integer) h.remove(); if (h.ascendingOrder) { assertTrue(lastNum == null || num.intValue() >= lastNum.intValue()); } else { // max heap assertTrue(lastNum == null || num.intValue() <= lastNum.intValue()); } lastNum = num; num = null; } }
h.remove(new Integer(r)); h.add(new Integer(randGenerator.nextInt(heapSize)));
/** * Illustrates bad internal heap state reported in Bugzilla PR #235818. */ public void testAddRemove() { resetEmpty(); PriorityBuffer heap = (PriorityBuffer) collection; heap.add(new Integer(0)); heap.add(new Integer(2)); heap.add(new Integer(4)); heap.add(new Integer(3)); heap.add(new Integer(8)); heap.add(new Integer(10)); heap.add(new Integer(12)); heap.add(new Integer(3)); confirmed.addAll(heap); // System.out.println(heap); Object obj = new Integer(10); heap.remove(obj); confirmed.remove(obj); // System.out.println(heap); verify(); }
heap.remove(); fail("NoSuchElementException should be thrown if remove is called before any elements are added"); } catch (BufferUnderflowException ex) {} "remove using default constructor should return minimum value in the binary heap", String.valueOf((char) ('n' - i)), heap.remove()); heap.remove(); fail("NoSuchElementException should be thrown if remove is called after all elements are removed"); } catch (BufferUnderflowException ex) {}
@VisibleForTesting synchronized boolean next(WritableComparable<?> key, Writable val) throws IOException { Index elt = (Index) heap.remove(); try { elt.cache(); if (elt.cached) { copy(elt.key, key); copy(elt.value, val); elt.cached = false; } else { return false; } } finally { heap.add(elt); } return true; }
@VisibleForTesting synchronized boolean next(WritableComparable<?> key, Writable val) throws IOException { Index elt = (Index) heap.remove(); try { elt.cache(); if (elt.cached) { copy(elt.key, key); copy(elt.value, val); elt.cached = false; } else { return false; } } finally { heap.add(elt); } return true; }
public synchronized boolean next(WritableComparable key, Writable val) throws IOException { Index elt = (Index) heap.remove(); try { elt.cache(); if (elt.cached) { copy(elt.key, key); copy(elt.value, val); elt.cached = false; } else { return false; } } finally { heap.add(elt); } return true; }