# HG changeset patch # User klao # Date 1079790484 0 # Node ID 44f01e580f16ca2f1628a91a68a4f6c955b715b8 # Parent e308e429bdc9865a19b0507b0166866234ab1fcd Feluton az uj map stilus fele. Nehany const javitas. diff -r e308e429bdc9 -r 44f01e580f16 src/include/bin_heap.hh --- a/src/include/bin_heap.hh Sat Mar 20 11:32:44 2004 +0000 +++ b/src/include/bin_heap.hh Sat Mar 20 13:48:04 2004 +0000 @@ -108,7 +108,7 @@ private: static int parent(int i) { return (i-1)/2; } static int second_child(int i) { return 2*i+2; } - bool less(const PairType &p1, const PairType &p2) { + bool less(const PairType &p1, const PairType &p2) const { return comp(p1.second, p2.second); } @@ -156,10 +156,13 @@ rmidx(iim.get(i)); } - const Prio get(const Item &i) const { + Prio get(const Item &i) const { int idx = iim.get(i); return data[idx].second; } + Prio operator[](const Item &i) const { + return get(i); + } void set(const Item &i, const Prio &p) { int idx = iim.get(i); if( idx < 0 ) { diff -r e308e429bdc9 -r 44f01e580f16 src/work/bin_heap_demo.cc --- a/src/work/bin_heap_demo.cc Sat Mar 20 11:32:44 2004 +0000 +++ b/src/work/bin_heap_demo.cc Sat Mar 20 13:48:04 2004 +0000 @@ -16,17 +16,21 @@ typedef BinHeap StrDoubleHeap; class string_int_map : public map { + typedef map parent; public: int get(const string &s) { // Bocs, ez igy gaaaany, de nem volt kedvem utananezni, hogy // hogy is mukodik ez a map :) if( count(s) == 0 ) { - operator[](s) = StrDoubleHeap::PRE_HEAP; + parent::operator[](s) = StrDoubleHeap::PRE_HEAP; } - return operator[](s); + return parent::operator[](s); + } + int operator[](const string &s) { + return get(s); } void set(const string &s, int i) { - operator[](s) = i; + parent::operator[](s) = i; } }; @@ -37,7 +41,8 @@ cout << "testing string_int_map default value:\n"; - cout << " alma: " << sim.get("alma") << endl; + cout << " sim.get(\"alma\"): " << sim.get("alma") << endl; + cout << " sim[\"alma\"]: " << sim["alma"] << endl; cout << "creating the heap\n"; StrDoubleHeap heap(sim); @@ -51,6 +56,9 @@ cout << "heap.get(\"alma\") = " << heap.get("alma") << endl; + cout << "heap[\"alma\"] = " + << heap["alma"] + << endl; cout << "heap.top() = " << heap.top() << endl;