klao@37: #include klao@258: #include klao@37: #include klao@37: #include klao@37: alpar@105: using namespace hugo; klao@37: using namespace std; klao@37: klao@37: class string_int_map; klao@37: klao@39: // Egy binaris kupac, ami stringekhez rendelt double ertekeket tarol, klao@39: // azaz mindig az a string van a tetejen, amihez a legkisebb szam tartozik. klao@39: // A kupac egy string_int_map tipusu property_map segitsegevel tarolja klao@39: // a stringek aktualis helyet sajatmagan belul. klao@39: // Egy olyan stringhez, ami meg nincsen a kupac -1 -et kell rendelnunk. klao@37: typedef BinHeap StrDoubleHeap; klao@37: klao@37: class string_int_map : public map { klao@214: typedef map parent; klao@37: public: klao@37: int get(const string &s) { klao@37: // Bocs, ez igy gaaaany, de nem volt kedvem utananezni, hogy klao@37: // hogy is mukodik ez a map :) klao@37: if( count(s) == 0 ) { klao@214: parent::operator[](s) = StrDoubleHeap::PRE_HEAP; klao@37: } klao@214: return parent::operator[](s); klao@214: } klao@214: int operator[](const string &s) { klao@214: return get(s); klao@37: } klao@172: void set(const string &s, int i) { klao@214: parent::operator[](s) = i; klao@37: } klao@37: }; klao@37: klao@37: klao@37: int main() klao@37: { klao@37: string_int_map sim; klao@37: klao@37: klao@37: cout << "testing string_int_map default value:\n"; klao@214: cout << " sim.get(\"alma\"): " << sim.get("alma") << endl; klao@214: cout << " sim[\"alma\"]: " << sim["alma"] << endl; klao@37: klao@37: cout << "creating the heap\n"; klao@37: StrDoubleHeap heap(sim); klao@37: klao@37: cout << "heap.push(\"alma\", 15);\n"; klao@37: heap.push("alma", 15); klao@37: klao@172: cout << "heap.set(\"korte\", 3.4);\n"; klao@172: heap.set("korte", 3.4); klao@37: klao@37: cout << "heap.get(\"alma\") = " klao@37: << heap.get("alma") klao@37: << endl; klao@214: cout << "heap[\"alma\"] = " klao@214: << heap["alma"] klao@214: << endl; klao@37: klao@37: cout << "heap.top() = " klao@37: << heap.top() << endl; klao@172: cout << "heap.topPrio() = " klao@172: << heap.topPrio() << endl; klao@37: klao@37: cout << "heap.decrease(\"alma\", 1.2);\n"; klao@172: heap.set("alma", 1.2); klao@37: klao@37: cout << "heap.top() = " klao@37: << heap.top() << endl; klao@172: cout << "heap.topPrio() = " klao@172: << heap.topPrio() << endl; klao@37: klao@172: cout << "heap.set(\"alma\", 22);\n"; klao@172: heap.set("alma", 22); klao@37: klao@37: cout << "heap.top() = " klao@37: << heap.top() << endl; klao@172: cout << "heap.topPrio() = " klao@172: << heap.topPrio() << endl; klao@37: klao@37: cout << "heap.size() = " klao@37: << heap.size() << endl; klao@37: cout << "heap.pop();\n"; klao@37: heap.pop(); klao@37: klao@37: cout << "heap.top() = " klao@37: << heap.top() << endl; klao@172: cout << "heap.topPrio() = " klao@172: << heap.topPrio() << endl; klao@37: klao@39: cout << "heap.state(\"szilva\") = " klao@39: << heap.state("szilva") << endl; klao@172: cout << "heap.set(\"szilva\", 0.5);\n"; klao@172: heap.set("szilva", 0.5); klao@39: cout << "heap.state(\"szilva\") = " klao@39: << heap.state("szilva") << endl; klao@39: cout << "heap.top() = " klao@39: << heap.top() << endl; klao@39: cout << "heap.pop();\n"; klao@39: heap.pop(); klao@39: cout << "heap.state(\"szilva\") = " klao@39: << heap.state("szilva") << endl; klao@39: klao@37: cout << "heap.size() = " klao@37: << heap.size() << endl; klao@37: cout << "heap.pop();\n"; klao@37: heap.pop(); klao@37: klao@37: cout << "heap.size() = " klao@37: << heap.size() << endl; klao@37: cout << "heap.empty() = " klao@37: << (heap.empty()?"true":"false") << endl; klao@37: }