heap.cpp (585B)
1 #include "all_includes.hh" 2 3 Heap::Heap() { 4 } 5 6 void Heap::init(int _factor) { factor = (float)_factor; } 7 8 void Heap::insert(float key, Chose* value) { 9 bst.insert(HeapNode(key * factor, value)); 10 } 11 12 void Heap::remove(float key, Chose* value) { 13 bst.erase(HeapNode(key * factor, value)); 14 } 15 16 bool Heap::lessThan(float a, float b) { 17 return (a * factor < b * factor); 18 } 19 20 Chose* Heap::popIfLessThan(float key) { 21 std::set<HeapNode>::iterator min = bst.begin(); 22 if (min != bst.end() && min->key < key * factor) { 23 Chose* ret = min->value; 24 bst.erase(min); 25 return ret; 26 } 27 return NULL; 28 }