$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fibonacci_heap.cc
1 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 
30 
31 #include <mln/util/fibonacci_heap.hh>
32 #include <mln/core/alias/point2d.hh>
33 
34 
35 using mln::point2d;
36 
37 point2d p[] = { point2d(4,5), point2d(3,4), point2d(3,2),
38  point2d(1,6), point2d(2,3), point2d(3,5),
39  point2d(2,4), point2d(7,2), point2d(9,6),
40  point2d(7,3) };
41 
42 point2d res_1[] = { point2d(1,6), point2d(2,3), point2d(2,4) };
43 
44 point2d res_2[] = { point2d(53,4), point2d(5,4), point2d(1,4),
45  point2d(3,2), point2d(3,4), point2d(3,5),
46  point2d(4,5), point2d(7,2), point2d(7,3),
47  point2d(9,6) };
48 
49 
50 int main()
51 {
52  using namespace mln;
53 
56  for (unsigned i = 0; i < 5; ++i)
57  heap.push(3, p[i]);
58 
61  for (unsigned i = 5; i < 10; ++i)
62  heap2.push(3, p[i]);
63 
64 
75 
76  heap.push(heap2);
77 
79  mln_assertion(heap2.is_empty());
80  mln_assertion(heap2.nelements() == 0);
81 
83 // mln_assertion(heap.front() == res_1[0]);
84 
85 
96 
97 
98  heap2.push(heap);
99 
101  mln_assertion(heap.is_empty());
102  mln_assertion(heap.nelements() == 0);
103 
105  mln_assertion(heap2.front() == res_1[0]);
106 
107 
109  for (unsigned i = 0; i < 3; ++i)
110  mln_assertion(heap2.pop_front() == res_1[i]);
111 
112 
114  heap2.push(1, point2d(53,4));
115  heap2.push(3, point2d(1,4));
116  heap2.push(2, point2d(5,4));
117 
119  unsigned i = 0;
120  while (heap2.is_valid())
121  {
122  mln_assertion(heap2.pop_front() == res_2[i++]);
123  mln_assertion(heap2.nelements() == (10 - i));
124  }
125 
127  mln_assertion(heap2.is_empty());
128  mln_assertion(heap2.nelements() == 0);
129 
130 
131 
133  heap.push(3, point2d(2,4));
134  heap2.push(3, point2d(53,4));
136  heap = heap2;
137  heap2 = tmp;
138 
139  mln_assertion(heap2.nelements() == 1);
140  mln_assertion(heap.nelements() == 1);
141  mln_assertion(tmp.nelements() == 0);
142 
143 
146 
147  mln_assertion(tmp2.nelements() == 1);
148  mln_assertion(heap.nelements() == 0);
149 
150 }