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