33#include < CGAL/Modifiable_priority_queue.h>
44#include < boost/unordered_map.hpp>
55#include < iostream>
6- #include < functional>
6+ #include < functional>
77
8- // first is the index (id) and second the value compared,
8+ // first is the index (id) and second the value compared,
99typedef std::pair<std::size_t ,int > Type;
1010
1111// property map
@@ -43,87 +43,87 @@ int main()
4343 Heap_map h;
4444 assert ( queue_size (h,45 ) == 0 );
4545 assert ( q.empty () );
46-
46+
4747 std::vector<Type> data;
48-
48+
4949 data.push_back (Type (0 ,10 ));
5050 data.push_back (Type (1 ,20 ));
5151 data.push_back (Type (2 ,30 ));
5252 data.push_back (Type (3 ,40 ));
5353 data.push_back (Type (4 ,1 ));
5454 data.push_back (Type (5 ,2 ));
55-
55+
5656 h[&data[0 ]] = q.push (&data[0 ]);
5757 h[&data[0 ]+1 ] = q.push (&data[0 ]+1 );
5858 h[&data[0 ]+2 ] = q.push (&data[0 ]+2 );
5959 h[&data[0 ]+3 ] = q.push (&data[0 ]+3 );
60-
60+
6161 assert ( q.top ()->first == 0 );
6262 assert ( queue_size (h,45 ) == 4 );
63-
63+
6464 Type *top = q.top ();
6565 q.pop ();
6666 h.erase (top);
6767 assert ( q.top ()->first == 1 );
6868 assert ( queue_size (h,45 ) == 3 );
69-
69+
7070 h[&data[0 ]+4 ] = q.push (&data[0 ]+4 );
71-
71+
7272 assert ( q.top ()->first == 4 );
7373 assert ( queue_size (h,45 ) == 4 );
7474
7575 q.erase (&data[0 ]+4 , h[&data[0 ]+4 ]);
7676 h.erase (&data[0 ]+4 );
77-
77+
7878 assert ( q.top ()->first == 1 );
79- assert ( queue_size (h,45 ) == 3 );
80-
79+ assert ( queue_size (h,45 ) == 3 );
80+
8181 h[&data[0 ]+5 ] = q.push (&data[0 ]+5 );
82-
82+
8383 assert ( q.top ()->first == 5 );
8484 assert ( queue_size (h,45 ) == 4 );
85-
85+
8686 Queue::handle ex_h = h[&data[0 ]+5 ];
8787 data[5 ].second =43 ;
8888 q.update (&data[0 ]+5 ,ex_h);
8989 h[&data[0 ]+5 ] = ex_h;
90-
90+
9191 assert ( q.top ()->first == 1 );
92- assert ( queue_size (h,45 ) == 4 );
93-
92+ assert ( queue_size (h,45 ) == 4 );
93+
9494 top = q.top ();
9595 q.pop ();
9696 h.erase (top);
97-
97+
9898 assert ( q.top ()->first == 2 );
99- assert ( queue_size (h,45 ) == 3 );
99+ assert ( queue_size (h,45 ) == 3 );
100100
101101 top=q.top ();
102102 q.pop ();
103103 h.erase (top);
104104 assert ( q.top ()->first == 3 );
105- assert ( queue_size (h,45 ) == 2 );
105+ assert ( queue_size (h,45 ) == 2 );
106106
107107 top = q.top ();
108108 q.pop ();
109109 h.erase (top);
110110 assert ( q.top ()->first == 5 );
111- assert ( queue_size (h,45 ) == 1 );
112-
111+ assert ( queue_size (h,45 ) == 1 );
112+
113113 top=q.top ();
114114 q.pop ();
115115 h.erase (top);
116116 assert ( queue_size (h,45 ) == 0 );
117117 assert ( q.empty () );
118-
118+
119119 h[&data[0 ]] = q.push (&data[0 ]);
120120 h[&data[0 ]+1 ] = q.push (&data[0 ]+1 );
121121 h[&data[0 ]+2 ] = q.push (&data[0 ]+2 );
122122 h[&data[0 ]+3 ] = q.push (&data[0 ]+3 );
123-
123+
124124 assert ( q.top ()->first == 0 );
125125 assert ( queue_size (h,45 ) == 4 );
126-
126+
127127 q.erase (&data[0 ]+1 ,h[&data[0 ]+1 ]);
128128 h.erase (&data[0 ]+1 );
129129 assert ( q.top ()->first == 0 );
@@ -138,11 +138,11 @@ int main()
138138 h.erase (&data[0 ]);
139139 assert ( q.top ()->first == 3 );
140140 assert ( queue_size (h,45 ) == 1 );
141-
141+
142142 q.erase (&data[0 ]+3 ,h[&data[0 ]+3 ]);
143143 h.erase (&data[0 ]+3 );
144144 assert ( queue_size (h,45 ) == 0 );
145- assert ( q.empty () );
145+ assert ( q.empty () );
146146
147147// testing correctness of the order
148148 int array[10 ] = {0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 };
@@ -153,23 +153,23 @@ int main()
153153 data.push_back (Type (i,array[i]));
154154 h[&data[0 ]+i] = q.push (&data[0 ]+i);
155155 }
156-
156+
157157 for (int i=0 ;i<10 ;++i){
158158 top = q.top ();
159159 assert (top->second ==i);
160160 q.pop ();
161161 h.erase (top);
162162 }
163163 assert ( q.empty () );
164-
164+
165165// testing update (increase key)
166166 data.clear ();
167167 data.reserve (10 );
168168 for (int i=0 ;i<10 ;++i){
169169 data.push_back (Type (i,10 +i));
170170 h[&data[0 ]+i] = q.push (&data[0 ]+i);
171171 }
172-
172+
173173 for (unsigned int i=0 ;i<10 ;++i){
174174 ex_h = h[&data[0 ]+i];
175175 data[i].second =9 -i;
@@ -184,7 +184,7 @@ int main()
184184 h.erase (&data[0 ]+i);
185185 assert (queue_size (h,45 )==9 -i);
186186 }
187-
187+
188188// testing update (decrease key of top)
189189 data.clear ();
190190 data.reserve (10 );
@@ -200,31 +200,31 @@ int main()
200200 h[&data[0 ]+i] = ex_h;
201201 assert (q.top ()->first ==i+1 );
202202 }
203-
203+
204204// revert order
205205 for (unsigned int i=0 ;i<10 ;++i){
206206 ex_h = h[&data[0 ]+9 -i];
207207 data[9 -i].second =i;
208208 q.update (&data[0 ]+9 -i,ex_h);
209209 h[&data[0 ]+9 -i] = ex_h;
210210 assert (q.top ()->first ==9 );
211- }
212- // testing remove (emulate pop)
211+ }
212+ // testing remove (emulate pop)
213213 for (std::size_t i=0 ;i<10 ;++i){
214214 assert (q.top ()->first ==9 -i);
215215 q.erase (&data[0 ]-i+9 ,h[&data[0 ]+9 -i]);
216216 h.erase (&data[0 ]+9 -i);
217217 }
218218 assert ( q.empty () );
219-
219+
220220 // testing remove+contains
221221 data.clear ();
222222 data.reserve (10 );
223223 for (int i=0 ;i<10 ;++i){
224224 data.push_back (Type (i,i));
225225 h[&data[0 ]+i] = q.push (&data[0 ]+i);
226226 }
227-
227+
228228 for (std::size_t i=0 ;i<10 ;++i){
229229 assert (q.top ()->first ==0 );
230230 q.erase (&data[0 ]-i+9 ,h[&data[0 ]-i+9 ]);
@@ -235,9 +235,9 @@ int main()
235235 assert (h.find (&data[0 ]+9 -k) == h.end ());
236236 }
237237 assert ( q.empty () );
238-
238+
239239 std::cout << " OK" << std::endl;
240-
240+
241241 return 0 ;
242242 #else
243243 std::cerr << " ERROR: Nothing is tested" << std::endl;
0 commit comments