heap.hh (708B)
1 #ifndef _HEAP_HH_ 2 #define _HEAP_HH_ 3 4 #include "all_includes.hh" 5 6 class HeapNode { 7 public: 8 HeapNode(float _key, Chose* _value) : key(_key), value(_value) {}; 9 float key; 10 Chose* value; 11 friend bool operator< (const HeapNode &a, const HeapNode &b) { 12 return (a.key < b.key || (a.key >= b.key && a.key <= b.key && a.value < b.value)); 13 } 14 }; 15 16 class Heap { 17 private: 18 std::set<HeapNode> bst; 19 float factor; // -1.f ou +1.f 20 public: 21 Heap(); 22 void insert(float key, Chose* value); 23 void remove(float key, Chose* value); 24 Chose* popIfLessThan(float key); 25 bool lessThan(float a, float b); // Renvoie true ssi a < b dans l'ordre du tas. 26 void init(int factor); // factor = -1 pour tas Min, 1 pour tas max 27 }; 28 29 #endif