|
1 #include <iostream> |
|
2 #include <bin_heap.hh> |
|
3 #include <string> |
|
4 #include <map> |
|
5 |
|
6 using namespace marci; |
|
7 using namespace std; |
|
8 |
|
9 class string_int_map; |
|
10 |
|
11 typedef BinHeap<string, double, string_int_map> StrDoubleHeap; |
|
12 |
|
13 class string_int_map : public map<string,int> { |
|
14 public: |
|
15 int get(const string &s) { |
|
16 // Bocs, ez igy gaaaany, de nem volt kedvem utananezni, hogy |
|
17 // hogy is mukodik ez a map :) |
|
18 if( count(s) == 0 ) { |
|
19 operator[](s) = StrDoubleHeap::PRE_HEAP; |
|
20 } |
|
21 return operator[](s); |
|
22 } |
|
23 void put(const string &s, int i) { |
|
24 operator[](s) = i; |
|
25 } |
|
26 }; |
|
27 |
|
28 |
|
29 int main() |
|
30 { |
|
31 string_int_map sim; |
|
32 |
|
33 |
|
34 cout << "testing string_int_map default value:\n"; |
|
35 cout << " alma: " << sim.get("alma") << endl; |
|
36 |
|
37 cout << "creating the heap\n"; |
|
38 StrDoubleHeap heap(sim); |
|
39 |
|
40 cout << "heap.push(\"alma\", 15);\n"; |
|
41 heap.push("alma", 15); |
|
42 |
|
43 cout << "heap.put(\"korte\", 3.4);\n"; |
|
44 heap.put("korte", 3.4); |
|
45 |
|
46 cout << "heap.get(\"alma\") = " |
|
47 << heap.get("alma") |
|
48 << endl; |
|
49 |
|
50 cout << "heap.top() = " |
|
51 << heap.top() << endl; |
|
52 cout << "heap.topValue() = " |
|
53 << heap.topValue() << endl; |
|
54 |
|
55 cout << "heap.decrease(\"alma\", 1.2);\n"; |
|
56 heap.put("alma", 1.2); |
|
57 |
|
58 cout << "heap.top() = " |
|
59 << heap.top() << endl; |
|
60 cout << "heap.topValue() = " |
|
61 << heap.topValue() << endl; |
|
62 |
|
63 cout << "heap.put(\"alma\", 22);\n"; |
|
64 heap.put("alma", 22); |
|
65 |
|
66 cout << "heap.top() = " |
|
67 << heap.top() << endl; |
|
68 cout << "heap.topValue() = " |
|
69 << heap.topValue() << endl; |
|
70 |
|
71 cout << "heap.size() = " |
|
72 << heap.size() << endl; |
|
73 cout << "heap.pop();\n"; |
|
74 heap.pop(); |
|
75 |
|
76 cout << "heap.top() = " |
|
77 << heap.top() << endl; |
|
78 cout << "heap.topValue() = " |
|
79 << heap.topValue() << endl; |
|
80 |
|
81 cout << "heap.size() = " |
|
82 << heap.size() << endl; |
|
83 cout << "heap.pop();\n"; |
|
84 heap.pop(); |
|
85 |
|
86 cout << "heap.size() = " |
|
87 << heap.size() << endl; |
|
88 cout << "heap.empty() = " |
|
89 << (heap.empty()?"true":"false") << endl; |
|
90 } |
|
91 |