dranges.priorityqueue

A simple priority queue module.

License:
Boost License 1.0.

Authors:
Philippe Sigaud

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

struct PriorityQueue (alias predicate = "a < b",V,P);
Thin wrapper around a BinaryHeap!(predicate, Tuple!(Priority, Value)). Otherwise acts as a bona fide priority queue: you enter value/priority pairs, you can change priority with changePriority(), insert elements with put and output them with foreach() (or empty/front/popFront if you wish).

alias PV ;


BinaryHeap!(predicate,PV)* opDot ();
forward most calls to the underlying binary heap.

PV front ();
Defined so that foreach can infer element type.

void changePriority (V value, P oldPriority, P newPriority);
This will change a value priority.

Throws:
RangeError (Range violation) if the key/value does not exist.

Note:
It cannot just be (V value, P newPriority) and deduce the oldPriority by looking for value in the heap, because there may be many values (of same value...) with different priorities.

PriorityQueue!(predicate,V,P) priorityQueue (alias predicate = "a < b", V, P, R...)(V value, P priority, R rest);
Helper function to infer types and put them in the queue. Data is given in the argument list as value,priority pairs.

PriorityQueue!(predicate,V,P) priorityQueue (alias predicate = "a < b", V, P)(P[V] valuePriorityArray);
Helper function to infer types and put them in the queue. The argument is an associative array of values and priorities: ["a":0, "b":1, "qwerty":-100]

Values are keys, priority are values. It makes for a more readable list IMO, but does not allow the existence of many times the same value, but entered in the queue with varying priorities (it would erase the first pair). Use the preceding version for that.

Page was generated with on Fri Nov 12 11:55:11 2010