private void heapify() { pQueueSize = 0; while (pQueueSize < pQueue.length) { pQueueSize++; ObjectHeaps.upHeap(pQueue, pQueueSize, pQueueSize - 1, ROW_ITERATOR_COMPARATOR); } }
@Override public void changed() { ObjectHeaps.downHeap(heap, size, 0, c); } @Override
/** * Wraps a given array in a queue using a given comparator. * * <p> * The queue returned by this method will be backed by the given array. The * first {@code size} element of the array will be rearranged so to form a heap * (this is more efficient than enqueing the elements of {@code a} one by one). * * @param a * an array. * @param size * the number of elements to be included in the queue. * @param c * the comparator used in this queue, or {@code null} for the natural * order. */ public ObjectHeapPriorityQueue(final K[] a, int size, final Comparator<? super K> c) { this(c); this.heap = a; this.size = size; ObjectHeaps.makeHeap(a, size, c); } /**
/** * Makes an array into a heap. * * @param heap * the heap (starting at 0). * @param size * the number of elements in the heap. * @param c * a type-specific comparator, or {@code null} for the natural order. */ public static <K> void makeHeap(final K[] heap, final int size, final Comparator<K> c) { int i = size >>> 1; while (i-- != 0) downHeap(heap, size, i, c); } }
private void heapify() { pQueueSize = 0; while (pQueueSize < pQueue.length) { pQueueSize++; ObjectHeaps.upHeap(pQueue, pQueueSize, pQueueSize - 1, ROW_ITERATOR_COMPARATOR); } }
@Override public K dequeue() { if (size == 0) throw new NoSuchElementException(); final K result = heap[0]; heap[0] = heap[--size]; heap[size] = null; if (size != 0) ObjectHeaps.downHeap(heap, size, 0, c); return result; } @Override
@Override public void enqueue(K x) { if (size == heap.length) heap = ObjectArrays.grow(heap, size + 1); heap[size++] = x; ObjectHeaps.upHeap(heap, size, size - 1, c); } @Override