Package org.neo4j.gds.core.utils.queue
Class HugeLongPriorityQueue
- java.lang.Object
-
- org.neo4j.gds.core.utils.queue.HugeLongPriorityQueue
-
- All Implemented Interfaces:
org.neo4j.gds.collections.primitive.PrimitiveLongIterable
public abstract class HugeLongPriorityQueue extends java.lang.Object implements org.neo4j.gds.collections.primitive.PrimitiveLongIterable
A PriorityQueue specialized for longs that maintains a partial ordering of its elements such that the smallest value can always be found in constant time. The definition of what small means is up to the implementing subclass.Put()'s and pop()'s require log(size) time but the remove() cost implemented here is linear.
NOTE: Iteration order is not specified. Implementation has been copied from https://issues.apache.org/jira/browse/SOLR-2092 and slightly adapted to our needs.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.neo4j.gds.collections.ha.HugeDoubleArray
costValues
-
Constructor Summary
Constructors Modifier Constructor Description protected
HugeLongPriorityQueue(long capacity)
Creates a new priority queue with the given capacity.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
add(long element, double cost)
Adds an element associated with a cost to the queue in log(size) time.void
clear()
Removes all entries from the queue.boolean
containsElement(long element)
Returns true, iff the element is contained in the queue.double
cost(long element)
Returns the cost associated with the given element.long
getIth(int i)
Returns the element in the i-th position of the heapboolean
isEmpty()
java.util.PrimitiveIterator.OfLong
iterator()
protected abstract boolean
lessThan(long a, long b)
Defines the ordering of the queue.static HugeLongPriorityQueue
max(long capacity)
Returns a non growing max priority queue, i.e.static org.neo4j.gds.core.utils.mem.MemoryEstimation
memoryEstimation()
static HugeLongPriorityQueue
min(long capacity)
Returns a non growing min priority queue, i.e.long
pop()
Removes and returns the element with the minimum cost from the queue in log(size) time.void
release()
Removes all entries from the queue, releases all buffers.void
set(long element, double cost)
Adds an element associated with a cost to the queue in log(size) time.long
size()
Returns the number of elements currently stored in the queue.long
top()
Returns the element with the minimum cost from the queue in constant time.
-
-
-
Method Detail
-
memoryEstimation
public static org.neo4j.gds.core.utils.mem.MemoryEstimation memoryEstimation()
-
add
public void add(long element, double cost)
Adds an element associated with a cost to the queue in log(size) time.
-
set
public void set(long element, double cost)
Adds an element associated with a cost to the queue in log(size) time. If the element was already in the queue, it's cost are updated and the heap is reordered in log(size) time.
-
cost
public double cost(long element)
Returns the cost associated with the given element. If the element has been popped from the queue, its latest cost value is being returned.- Returns:
- The double cost value for the element. 0.0D if the element is not found.
-
containsElement
public boolean containsElement(long element)
Returns true, iff the element is contained in the queue.
-
top
public long top()
Returns the element with the minimum cost from the queue in constant time.
-
pop
public long pop()
Removes and returns the element with the minimum cost from the queue in log(size) time.
-
size
public long size()
Returns the number of elements currently stored in the queue.
-
release
public void release()
Removes all entries from the queue, releases all buffers. The queue can no longer be used afterwards.
-
lessThan
protected abstract boolean lessThan(long a, long b)
Defines the ordering of the queue. Returns true iffa
is strictly less thanb
.The default behavior assumes a min queue, where the value with smallest cost is on top. To implement a max queue, return
b < a
. The resulting order is not stable.
-
isEmpty
public boolean isEmpty()
- Returns:
- true iff there are currently no elements stored in the queue.
-
clear
public void clear()
Removes all entries from the queue.
-
iterator
public java.util.PrimitiveIterator.OfLong iterator()
- Specified by:
iterator
in interfaceorg.neo4j.gds.collections.primitive.PrimitiveLongIterable
-
min
public static HugeLongPriorityQueue min(long capacity)
Returns a non growing min priority queue, i.e. the element with the lowest priority is always on top.
-
max
public static HugeLongPriorityQueue max(long capacity)
Returns a non growing max priority queue, i.e. the element with the highest priority is always on top.
-
getIth
public long getIth(int i)
Returns the element in the i-th position of the heap
-
-