[Lemon-commits] [lemon_svn] klao: r309 - in hugo/trunk/src: include work

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:38:39 CET 2006


Author: klao
Date: Sat Mar 20 14:48:04 2004
New Revision: 309

Modified:
   hugo/trunk/src/include/bin_heap.hh
   hugo/trunk/src/work/bin_heap_demo.cc

Log:
Feluton az uj map stilus fele.
Nehany const javitas.


Modified: hugo/trunk/src/include/bin_heap.hh
==============================================================================
--- hugo/trunk/src/include/bin_heap.hh	(original)
+++ hugo/trunk/src/include/bin_heap.hh	Sat Mar 20 14:48:04 2004
@@ -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 ) {

Modified: hugo/trunk/src/work/bin_heap_demo.cc
==============================================================================
--- hugo/trunk/src/work/bin_heap_demo.cc	(original)
+++ hugo/trunk/src/work/bin_heap_demo.cc	Sat Mar 20 14:48:04 2004
@@ -16,17 +16,21 @@
 typedef BinHeap<string, double, string_int_map> StrDoubleHeap;
 
 class string_int_map : public map<string,int> {
+  typedef map<string,int> 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;



More information about the Lemon-commits mailing list