[Click] Priority queue

Ruben Merz ruben at net.t-labs.tu-berlin.de
Wed Feb 24 09:56:09 EST 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Eddie,

Excellent! I missed the heap code. Thanks for the suggestion.

Ruben

On 2/23/10 17:26 , Eddie Kohler wrote:
> Hi Ruben,
> 
> Click's heap algorithms work great to implement a priority queue.
> 
> See include/click/algorithm.hh for the functions.  They are STL
> compatible with extensions.
> 
> An STL-compatible PriorityQueue class might look something like this
> (code untested):
> 
> template <typename T, typename Compare = less<T> >
> class priority_queue { public:
> 
> priority_queue() : _compare() { }
> priority_queue(const Compare &c) : _compare(c) { }
> 
> bool empty() const { return _v.empty(); }
> int size() const { return _v.size(); }
> const T &top() const { return _v.front(); }
> void push(const T &v) const {
>    _v.push_back(v);
>    push_heap(_v.begin(), _v.end(), _compare);
> }
> void pop() const {
>    pop_heap(_v.begin(), _v.end(), _compare);
>    _v.pop_back();
> }
> 
> private:
> 
> Vector<T> _v;
> Compare _compare;
> 
> };
> 
> 
> E
> 
> 
> 
> Ruben Merz wrote:
> 
> Hello,
> 
> I need the functionality of a priority queue. I checked the source code
> and did not find anything. Hence, if anyone has something similar or if
> I missed it, please let me know. Otherwise, I'll just implement it
> myself.
> 
> Best,
> Ruben
> 
> -- Ruben Merz                   Deutsche Telekom Laboratories
> http://www.net.t-labs.tu-berlin.de/people/ruben_merz.shtml
_______________________________________________
click mailing list
click at amsterdam.lcs.mit.edu
https://amsterdam.lcs.mit.edu/mailman/listinfo/click

- -- 
Ruben Merz                   Deutsche Telekom Laboratories
http://www.net.t-labs.tu-berlin.de/people/ruben_merz.shtml
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJLhT4JAAoJEIem9YkUyRjtWj0H/3FBkSaO42dZ1+gNwSq1NTvY
X5QJfhmGSeAOuLEvJ4KhC6DmhpU2NnsAjed/3JrAwIKJ7tWp8LMEwbv0ZitmqEdo
4n3cTFbdVf1aftya8Y6PhlD22Pxos0+RVsejo0WFROh9tF/53Zdhwdzyn/epHYL6
BbNVG+aUQOzegsZMCZOFN4u6pZIPzk1awADHol5/VeVZj+RMIMBwUo3Xz25C4nbt
jGWaCPV3o1VI2ZuqTb4wDcyBLILc3qisVM9uhAdH0oO+TSlaZuN6c4aHJvpxeY7C
AZdfi8SViFEZmkneungz1tntOfFGU13qdDLpRPp9rN/n3vd63cMYlpwH7Sjr+Hc=
=EbRz
-----END PGP SIGNATURE-----


More information about the click mailing list