2 pqueue.hh -- declare PQueue_ent and PQueue
4 source file of the Flower Library
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 template < class K, class T>
20 template < class K, class T>
21 int compare (PQueue_ent < K, T> const &e1, PQueue_ent < K, T> const &e2)
23 return compare (e1.key, e2.key);
27 Priority queue using a (variable size) in-situ heap.
31 TODO: add increase/decrease operations,
40 return heap_array_[i - 1];
42 T const &elt (int i) const
44 return heap_array_[i - 1];
47 /** acces an heap element. Careful with this, as changing the
48 priority might fuck up the invariants
50 @param 1 <= i < size () */
51 T &operator[] (int i) { return heap_array_[i]; }
52 T operator[] (int i) const { return heap_array_[i]; }
56 for (int i =2; i <= size (); i++)
57 assert (compare (elt (i / 2), elt (i)) <= 0);
60 T front () const { return elt (1); }
61 int size () const { return heap_array_.size (); }
65 int i = heap_array_.size ();
69 if (compare (elt (j), v) > 0)
86 //int first_leaf_i = size ();
93 T last = heap_array_.top ();
98 while (mini < size ())
100 if (compare (elt (mini + 1), elt (mini)) <0)
102 if (compare (last, elt (mini)) < 0)
104 elt (lasti) = elt (mini);