Class PriorityQueue<K,A>
java.lang.Object
fj.data.PriorityQueue<K,A>
A priority queue implementation backed by a
FingerTree. The finger tree nodes are
annotated with type K, are combined using a monoid of K and both the
key and value are stored in the leaf. Priorities of the same value
are returned FIFO (first in, first out).-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanDoes the priority k exist already?dequeue()Removes the node with the highest priority.dequeue(int n) Removes the top n elements with the highest priority.static <K,A> PriorityQueue <K, A> Creates an empty priority queue.static <A> PriorityQueue<Integer, A> emptyInt()An empty priority queue with integer priorities.Adds nodes using the list of products with priority k and value a.Adds a node with priority k and value a.Adds nodes using the iterable of products with priority k and value a.Adds a node with priority k and value a.filterKeys(F<K, Boolean> f) Filters the nodes based on the annotation of each node.filterValues(F<A, Boolean> f) Filters nodes based on the value inside each node.booleanisEmpty()Is the tree empty?booleanbooleanisGreaterThan(Ord<K> ok, K k) booleanisLessThan(Ord<K> ok, K k) Does the top of the queue have lower priority than k?<B> PriorityQueue<K, B> Maps the values in each node with function f.static <K,A> PriorityQueue <K, A> priorityQueue(Equal<K> e, FingerTree<K, P2<K, A>> ft) Creates a priority queue from a finger tree.toList()Returns a list of products with priority k and value a.top()If the tree is not empty, returns the node with highest priority otherwise returns nothing.Returns a tuple of the node with the highest priority and the rest of the priority queue.topN()Returns all the elements of the queue with the highest (same) priority.toStream()Returns a stream of products with priority k and value a.toString()<B> BPerforms a reduction on this priority queue using the given arguments.
-
Field Details
-
ftree
-
equal
-
-
Constructor Details
-
PriorityQueue
-
-
Method Details
-
priorityQueue
Creates a priority queue from a finger tree. -
empty
Creates an empty priority queue.- Parameters:
m- A monoid to combine node annotations.e- A value to compare key equality.
-
emptyInt
An empty priority queue with integer priorities. -
map
Maps the values in each node with function f. -
filterValues
-
filterKeys
-
isEmpty
public boolean isEmpty()Is the tree empty? -
top
-
topN
-
enqueue
Adds a node with priority k and value a. This operation take O(1). -
enqueue
-
contains
Does the priority k exist already? -
enqueue
-
enqueue
-
dequeue
Removes the node with the highest priority. -
topDequeue
-
unqueue
Performs a reduction on this priority queue using the given arguments.- Parameters:
empty- The value to return if this queue is empty.topDequeue- The function to apply to the top priority element and the tail of the queue (without its top element).- Returns:
- A reduction on this queue.
-
dequeue
Removes the top n elements with the highest priority. -
isLessThan
-
isGreaterThan
-
isEqual
-
toStream
-
toList
-
toString
-