Class LongPriorityQueue
- java.lang.Object
-
- org.neo4j.graphalgo.core.utils.queue.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 Summary
Fields Modifier and Type Field Description protected com.carrotsearch.hppc.LongDoubleScatterMap
costs
protected static int
DEFAULT_CAPACITY
protected long[]
heap
protected int
size
-
Constructor Summary
Constructors Constructor Description LongPriorityQueue()
LongPriorityQueue(int initialCapacity)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description long
add(long element, double cost)
Adds an int associated with the given weight to a queue in log(size) time.void
clear()
Removes all entries from the queue.protected void
downHeap(int i)
protected void
ensureCapacityForInsert()
double
getCost(long element)
boolean
isEmpty()
PrimitiveLongIterator
iterator()
protected abstract boolean
lessThan(long a, long b)
static LongPriorityQueue
max()
static LongPriorityQueue
max(int capacity)
static MemoryEstimation
memoryEstimation(int capacity)
static LongPriorityQueue
min()
static LongPriorityQueue
min(int capacity)
boolean
nonEmpty()
long
pop()
Removes and returns the least element of the queue in log(size) time.void
release()
Removes all entries from the queue, releases all buffers.int
size()
long
top()
double
topCost()
protected boolean
upHeap(int origPos)
-
-
-
Field Detail
-
DEFAULT_CAPACITY
protected static final int DEFAULT_CAPACITY
- See Also:
- Constant Field Values
-
size
protected int size
-
heap
protected long[] heap
-
costs
protected final com.carrotsearch.hppc.LongDoubleScatterMap costs
-
-
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()
-
iterator
public PrimitiveLongIterator iterator()
- Specified by:
iterator
in interfacePrimitiveLongIterable
-
min
public static LongPriorityQueue min(int capacity)
-
max
public static LongPriorityQueue max(int capacity)
-
min
public static LongPriorityQueue min()
-
max
public static LongPriorityQueue max()
-
-