Class LongPriorityQueue

  • All Implemented Interfaces:
    PrimitiveLongIterable

    public abstract class LongPriorityQueue
    extends java.lang.Object
    implements PrimitiveLongIterable
    A PriorityQueue specialized for ints that maintains a partial ordering of its elements such that the smallest value can always be found in constant time. Put()'s and pop()'s require log(size) time but the remove() cost implemented here is linear.

    NOTE: Iteration order is not specified.

    • Field Detail

      • size

        protected int size
      • heap

        protected long[] heap
      • costs

        protected final com.carrotsearch.hppc.LongDoubleScatterMap costs
    • Constructor Detail

      • LongPriorityQueue

        public LongPriorityQueue()
      • LongPriorityQueue

        public LongPriorityQueue​(int initialCapacity)
    • Method Detail

      • memoryEstimation

        public static MemoryEstimation memoryEstimation​(int capacity)
      • lessThan

        protected abstract boolean lessThan​(long a,
                                            long b)
      • add

        public long add​(long element,
                        double cost)
        Adds an int associated with the given weight to a queue in log(size) time.
        Returns:
        the new 'top' element in the queue.
      • getCost

        public double getCost​(long element)
      • top

        public long top()
        Returns:
        the least element of the queue in constant time.
      • topCost

        public double topCost()
      • pop

        public long pop()
        Removes and returns the least element of the queue in log(size) time.
        Returns:
        the least element of the queue in log(size) time while removing it.
      • size

        public int size()
        Returns:
        the number of elements currently stored in the queue.
      • isEmpty

        public boolean isEmpty()
        Returns:
        true iff there are currently no elements stored in the queue.
      • nonEmpty

        public boolean nonEmpty()
        Returns:
        true iff there is currently at least one element stored in the queue.
      • clear

        public void clear()
        Removes all entries from the queue.
      • release

        public void release()
        Removes all entries from the queue, releases all buffers. The queue can no longer be used afterwards.
      • upHeap

        protected boolean upHeap​(int origPos)
      • downHeap

        protected void downHeap​(int i)
      • ensureCapacityForInsert

        protected void ensureCapacityForInsert()