Commit a56c027c authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Add soft heap implementation.

	* headers.mk: add new headers to distribution.

	* mln/util/soft_heap.hh: new file. New implementation. New members may
	be added later.

	* mln/util/tracked_ptr.hh: Fix an issue while assigning a null
	tracked_ptr to another tracked_ptr. An internal pointer was not
	initialized but dereferenced and led to a segfault.

	* tests/unit_test/Makefile.am,
	* tests/unit_test/mln_util_soft_heap.cc: add a new unit test.

	* tests/util/Makefile.am,
	* tests/util/soft_heap.cc: add a new test.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@3161 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 90ec03ac
2009-01-16 Guillaume Lazzara <z@lrde.epita.fr>
Add soft heap implementation.
* headers.mk: add new headers to distribution.
* mln/util/soft_heap.hh: new file. New implementation. New members may
be added later.
* mln/util/tracked_ptr.hh: Fix an issue while assigning a null
tracked_ptr to another tracked_ptr. An internal pointer was not
initialized but dereferenced and led to a segfault.
* tests/unit_test/Makefile.am,
* tests/unit_test/mln_util_soft_heap.cc: add a new unit test.
* tests/util/Makefile.am,
* tests/util/soft_heap.cc: add a new test.
2009-01-16 Guillaume Lazzara <z@lrde.epita.fr>
 
Rename histo::data as histo::array.
......@@ -64,6 +64,7 @@ mln/registration/icp.hh \
mln/util/graph.hh \
mln/util/max.hh \
mln/util/lazy_set.hh \
mln/util/soft_heap.hh \
mln/util/set.hh \
mln/util/tree_to_image.hh \
mln/util/lemmings.hh \
......
This diff is collapsed.
// Copyright (C) 2006 EPITA Research and Development Laboratory
// Copyright (C) 2006, 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
......@@ -28,12 +29,11 @@
#ifndef MLN_UTIL_TRACKED_PTR_HH
# define MLN_UTIL_TRACKED_PTR_HH
/*! \file mln/util/tracked_ptr.hh
*
* \brief Definition of a smart pointer for shared data with tracking.
*
* \todo Split defs from decls.
*/
/// \file mln/util/tracked_ptr.hh
///
/// Definition of a smart pointer for shared data with tracking.
///
/// \todo Split defs from decls.
# include <set>
# include <iostream>
......@@ -63,16 +63,14 @@ namespace mln
/// Negation (for arithmetical tests).
bool operator !() const;
/*! \brief Mimics the behavior of op-> for a pointer in the const case.
**
** \invariant Pointer proxy exists.
*/
/// Mimics the behavior of op-> for a pointer in the const case.
///
/// \invariant Pointer proxy exists.
const T* operator->() const;
/*! \brief Mimics the behavior of op-> for a pointer in the mutable case.
**
** \invariant Pointer proxy exists.
*/
/// Mimics the behavior of op-> for a pointer in the mutable case.
///
/// \invariant Pointer proxy exists.
T* operator->();
/// Ctor.
......@@ -122,10 +120,9 @@ namespace mln
}
template <typename T>
/*! \brief Mimics the behavior of op-> for a pointer in the const case.
**
** \invariant Pointer proxy exists.
*/
/// Mimics the behavior of op-> for a pointer in the const case.
///
/// \invariant Pointer proxy exists.
inline
const T* tracked_ptr<T>::operator->() const
{
......@@ -135,10 +132,9 @@ namespace mln
}
template <typename T>
/*! \brief Mimics the behavior of op-> for a pointer in the mutable case.
**
** \invariant Pointer proxy exists.
*/
/// \brief Mimics the behavior of op-> for a pointer in the mutable case.
///
/// \invariant Pointer proxy exists.
inline
T* tracked_ptr<T>::operator->()
{
......@@ -201,7 +197,9 @@ namespace mln
clean_();
ptr_ = rhs.ptr_;
holders_ = rhs.holders_;
holders_->insert(this);
// If ptr == 0, holders_ == 0 so we cannot insert anything in it.
if (holders_ != 0)
holders_->insert(this);
return *this;
}
......
......@@ -64,6 +64,7 @@ mln_registration_icp \
mln_util_graph \
mln_util_max \
mln_util_lazy_set \
mln_util_soft_heap \
mln_util_set \
mln_util_tree_to_image \
mln_util_lemmings \
......@@ -1074,6 +1075,7 @@ mln_registration_icp_SOURCES = mln_registration_icp.cc
mln_util_graph_SOURCES = mln_util_graph.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
mln_util_set_SOURCES = mln_util_set.cc
mln_util_tree_to_image_SOURCES = mln_util_tree_to_image.cc
mln_util_lemmings_SOURCES = mln_util_lemmings.cc
......
// Unit test for mln/util/soft_heap.hh.
// Generated by ./build_unit_test.sh, do not modify.
// Include the file twice, so we detect missing inclusion guards.
#include <mln/util/soft_heap.hh>
#include <mln/util/soft_heap.hh>
int main()
{
// Nothing.
}
......@@ -12,6 +12,7 @@ check_PROGRAMS = \
lazy_set \
lemmings \
ord_pair \
soft_heap \
tree \
tree_fast \
tree_fast_to_image \
......@@ -26,6 +27,7 @@ graph_SOURCES = graph.cc
lazy_set_SOURCES = lazy_set.cc
lemmings_SOURCES = lemmings.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
......
// 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 mln/core/site_set/p_soft_heap.hh
///
/// Test for the soft heap (approximate priority queue).
#include <mln/util/soft_heap.hh>
#include <mln/core/alias/point2d.hh>
#include <mln/value/int_u8.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[] = { point2d(1,6), point2d(2,3), point2d(2,4),
point2d(3,2), point2d(3,4), point2d(3,5),
point2d(4,5), point2d(7,2), point2d(7,3),
point2d(9,6) };
int main()
{
using namespace mln;
util::soft_heap<point2d, value::int_u8> fh;
for (unsigned i = 0; i < 5; ++i)
fh.push(p[i]);
util::soft_heap<point2d, value::int_u8> fh2;
for (unsigned i = 5; i < 10; ++i)
fh2.push(p[i]);
// Merge fh in fh2.
fh2.take(fh);
// fh2 now holds both its elements and fh's.
unsigned i = 0;
while (!fh2.is_empty())
mln_assertion(fh2.pop_front() == res[i++]);
// fh must be empty, fh2 now holds its elements.
mln_assertion(fh.is_empty());
for (unsigned i = 5; i < 10; ++i)
fh2.push(p[i]);
fh2.clear();
mln_assertion(fh2.nelements() == 0);
mln_assertion(fh2.is_empty());
}
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