Feluton az uj map stilus fele.
Nehany const javitas.
1.1 --- a/src/include/bin_heap.hh Sat Mar 20 11:32:44 2004 +0000
1.2 +++ b/src/include/bin_heap.hh Sat Mar 20 13:48:04 2004 +0000
1.3 @@ -108,7 +108,7 @@
1.4 private:
1.5 static int parent(int i) { return (i-1)/2; }
1.6 static int second_child(int i) { return 2*i+2; }
1.7 - bool less(const PairType &p1, const PairType &p2) {
1.8 + bool less(const PairType &p1, const PairType &p2) const {
1.9 return comp(p1.second, p2.second);
1.10 }
1.11
1.12 @@ -156,10 +156,13 @@
1.13 rmidx(iim.get(i));
1.14 }
1.15
1.16 - const Prio get(const Item &i) const {
1.17 + Prio get(const Item &i) const {
1.18 int idx = iim.get(i);
1.19 return data[idx].second;
1.20 }
1.21 + Prio operator[](const Item &i) const {
1.22 + return get(i);
1.23 + }
1.24 void set(const Item &i, const Prio &p) {
1.25 int idx = iim.get(i);
1.26 if( idx < 0 ) {
2.1 --- a/src/work/bin_heap_demo.cc Sat Mar 20 11:32:44 2004 +0000
2.2 +++ b/src/work/bin_heap_demo.cc Sat Mar 20 13:48:04 2004 +0000
2.3 @@ -16,17 +16,21 @@
2.4 typedef BinHeap<string, double, string_int_map> StrDoubleHeap;
2.5
2.6 class string_int_map : public map<string,int> {
2.7 + typedef map<string,int> parent;
2.8 public:
2.9 int get(const string &s) {
2.10 // Bocs, ez igy gaaaany, de nem volt kedvem utananezni, hogy
2.11 // hogy is mukodik ez a map :)
2.12 if( count(s) == 0 ) {
2.13 - operator[](s) = StrDoubleHeap::PRE_HEAP;
2.14 + parent::operator[](s) = StrDoubleHeap::PRE_HEAP;
2.15 }
2.16 - return operator[](s);
2.17 + return parent::operator[](s);
2.18 + }
2.19 + int operator[](const string &s) {
2.20 + return get(s);
2.21 }
2.22 void set(const string &s, int i) {
2.23 - operator[](s) = i;
2.24 + parent::operator[](s) = i;
2.25 }
2.26 };
2.27
2.28 @@ -37,7 +41,8 @@
2.29
2.30
2.31 cout << "testing string_int_map default value:\n";
2.32 - cout << " alma: " << sim.get("alma") << endl;
2.33 + cout << " sim.get(\"alma\"): " << sim.get("alma") << endl;
2.34 + cout << " sim[\"alma\"]: " << sim["alma"] << endl;
2.35
2.36 cout << "creating the heap\n";
2.37 StrDoubleHeap heap(sim);
2.38 @@ -51,6 +56,9 @@
2.39 cout << "heap.get(\"alma\") = "
2.40 << heap.get("alma")
2.41 << endl;
2.42 + cout << "heap[\"alma\"] = "
2.43 + << heap["alma"]
2.44 + << endl;
2.45
2.46 cout << "heap.top() = "
2.47 << heap.top() << endl;