Commit 1dc16918 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Add implementation of Fibonacci heap.

	* headers.mk: add a new header to distribution.

	* mln/util/fibonacci_heap.hh: new file. The implementation.

	* tests/unit_test/Makefile.am,
	* tests/unit_test/mln_util_fibonacci_heap.cc: new unit test.

	* tests/util/Makefile.am,
	* tests/util/fibonacci_heap.cc: new test.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@3165 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 5011b2c1
2009-01-19 Guillaume Lazzara <z@lrde.epita.fr>
Add implementation of Fibonacci heap.
* headers.mk: add a new header to distribution.
* mln/util/fibonacci_heap.hh: new file. The implementation.
* tests/unit_test/Makefile.am,
* tests/unit_test/mln_util_fibonacci_heap.cc: new unit test.
* tests/util/Makefile.am,
* tests/util/fibonacci_heap.cc: new test.
2009-01-19 Thierry Geraud <thierry.geraud@lrde.epita.fr>
 
Cleanup extension with image, forcing it to be const.
......@@ -62,6 +62,7 @@ mln/registration/registration.hh \
mln/registration/essential.hh \
mln/registration/icp.hh \
mln/util/graph.hh \
mln/util/fibonacci_heap.hh \
mln/util/max.hh \
mln/util/lazy_set.hh \
mln/util/soft_heap.hh \
......
This diff is collapsed.
......@@ -62,6 +62,7 @@ mln_registration_registration \
mln_registration_essential \
mln_registration_icp \
mln_util_graph \
mln_util_fibonacci_heap \
mln_util_max \
mln_util_lazy_set \
mln_util_soft_heap \
......@@ -1076,6 +1077,7 @@ mln_registration_registration_SOURCES = mln_registration_registration.cc
mln_registration_essential_SOURCES = mln_registration_essential.cc
mln_registration_icp_SOURCES = mln_registration_icp.cc
mln_util_graph_SOURCES = mln_util_graph.cc
mln_util_fibonacci_heap_SOURCES = mln_util_fibonacci_heap.cc
mln_util_max_SOURCES = mln_util_max.cc
mln_util_lazy_set_SOURCES = mln_util_lazy_set.cc
mln_util_soft_heap_SOURCES = mln_util_soft_heap.cc
......
// Unit test for mln/util/fibonacci_heap.hh.
// Generated by ./build_unit_test.sh, do not modify.
// Include the file twice, so we detect missing inclusion guards.
#include <mln/util/fibonacci_heap.hh>
#include <mln/util/fibonacci_heap.hh>
int main()
{
// Nothing.
}
......@@ -6,32 +6,34 @@ include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
branch_iter \
branch_iter_ind \
line_graph \
eat \
fibonacci_heap \
graph \
lazy_set \
lemmings \
line_graph \
ord_pair \
soft_heap \
tree \
tree_fast \
tree_fast_to_image \
tree_to_image \
tree_to_fast
tree_to_fast \
tree_to_image
branch_iter_SOURCES = branch_iter.cc
branch_iter_ind_SOURCES = branch_iter_ind.cc
line_graph_SOURCES = line_graph.cc
eat_SOURCES = eat.cc
fibonacci_heap_SOURCES = fibonacci_heap.cc
graph_SOURCES = graph.cc
lazy_set_SOURCES = lazy_set.cc
lemmings_SOURCES = lemmings.cc
line_graph_SOURCES = line_graph.cc
ord_pair_SOURCES = ord_pair.cc
soft_heap_SOURCES = soft_heap.cc
tree_SOURCES = tree.cc
tree_fast_SOURCES = tree_fast.cc
tree_fast_to_image_SOURCES = tree_to_image.cc
tree_to_image_SOURCES = tree_to_image.cc
tree_to_fast_SOURCES = tree_to_fast.cc
tree_to_image_SOURCES = tree_to_image.cc
TESTS = $(check_PROGRAMS)
// Copyright (C) 2009 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
/// \file tests/util/fibonacci_heap.cc
///
/// Definition of a generic vector class.
#include <mln/util/fibonacci_heap.hh>
#include <mln/core/alias/point2d.hh>
using mln::point2d;
point2d p[] = { point2d(4,5), point2d(3,4), point2d(3,2),
point2d(1,6), point2d(2,3), point2d(3,5),
point2d(2,4), point2d(7,2), point2d(9,6),
point2d(7,3) };
point2d res_1[] = { point2d(1,6), point2d(2,3), point2d(2,4) };
point2d res_2[] = { point2d(1,4), point2d(3,2), point2d(3,4),
point2d(3,5), point2d(4,5), point2d(5,4),
point2d(7,2), point2d(7,3), point2d(9,6),
point2d(53,4) };
int main()
{
using namespace mln;
/// Init heap
util::fibonacci_heap<point2d> heap;
for (unsigned i = 0; i < 5; ++i)
heap.push(p[i]);
/// Init heap2
util::fibonacci_heap<point2d> heap2;
for (unsigned i = 5; i < 10; ++i)
heap2.push(p[i]);
/*!
**
** | | | | |x| | |
** | | | | |x| | |
** |x| + |x| => |x| + | |
** |x| |x| |x| | |
** - - - -
** heap heap2 heap heap2
**
*/
/// Merge heap and heap2.
heap.push(heap2);
/// Heap2 is now empty
mln_assertion(heap2.is_empty());
mln_assertion(heap2.nelements() == 0);
/// Check if the front() is correct in heap
mln_assertion(heap.front() == res_1[0]);
/*!
**
** |x| | | | | |x|
** |x| | | | | |x|
** |x| + | | => | | + |x|
** |x| | | | | |x|
** - - - -
** heap heap2 heap heap2
**
*/
/// Heap2 is empty and heap is full of elements.
/// Move the content of heap into heap2.
heap2.push(heap);
/// Heap is now empty
mln_assertion(heap.is_empty());
mln_assertion(heap.nelements() == 0);
/// Check if the front() is correct
mln_assertion(heap2.front() == res_1[0]);
/// Extract and delete few front elements.
for (unsigned i = 0; i < 3; ++i)
mln_assertion(heap2.pop_front() == res_1[i]);
/// Re-insert data after deletion...
heap2.push(point2d(53,4));
heap2.push(point2d(1,4));
heap2.push(point2d(5,4));
/// ... and try to extract and delete data again.
unsigned i = 0;
while (heap2.is_valid())
{
mln_assertion(heap2.pop_front() == res_2[i++]);
mln_assertion(heap2.nelements() == (10 - i));
}
/// The heap must be empty.
mln_assertion(heap2.is_empty());
mln_assertion(heap2.nelements() == 0);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment