URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-11-27 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add convertion of a tree into tree_fast.
* mln/util/tree_to_fast.hh: Add convertion of tree into tree_fast.
Tests
* tests/util/tree_to_fast.cc: New tests for this.
* tests/util/Makefile.am: Update.
---
mln/util/tree_fast_to_image.hh | 2
mln/util/tree_to_fast.hh | 110 +++++++++++++++++++++++++++++++++++++++++
tests/util/Makefile.am | 4 +
tests/util/tree_to_fast.cc | 74 +++++++++++++++++++++++++++
4 files changed, 188 insertions(+), 2 deletions(-)
Index: trunk/milena/tests/util/tree_to_fast.cc
===================================================================
--- trunk/milena/tests/util/tree_to_fast.cc (revision 0)
+++ trunk/milena/tests/util/tree_to_fast.cc (revision 1553)
@@ -0,0 +1,74 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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/tree_to_fast.cc
+ *
+ * \brief test of mln::util::tree_to_fast
+ *
+ */
+
+#include <mln/util/tree.hh>
+#include <mln/util/tree_to_fast.hh>
+#include <mln/util/tree_fast.hh>
+
+int main ()
+{
+ using namespace mln;
+
+ unsigned elt1 = 1;
+ unsigned elt2 = 2;
+ unsigned elt3 = 3;
+ unsigned elt4 = 4;
+ unsigned elt5 = 5;
+ unsigned elt6= 42;
+
+ util::node<unsigned> node(elt1);
+ util::node<unsigned>* node2 = node.add_child(elt2);
+ node.add_child(elt3);
+ mln_assertion(node2);
+ node2->add_child(elt4);
+ node2->add_child(elt5);
+ util::node<unsigned>* node3 = node.search(elt4);
+ mln_assertion(node3);
+ node3 = node2->search(elt1);
+ mln_assertion(!node3);
+ util::tree<unsigned>* tre = new util::tree<unsigned>(&node);
+ mln_assertion(tre);
+ tre->add_tree_up(elt6);
+ mln_assertion (tre->check_consistency());
+
+
+ util::tree_fast<unsigned> tree_fast = util::tree_to_fast(*tre);
+ mln_assertion(tree_fast.has (elt1));
+ mln_assertion(tree_fast.has (elt2));
+ mln_assertion(tree_fast.has (elt3));
+ mln_assertion(tree_fast.has (elt4));
+ mln_assertion(tree_fast.has (elt5));
+ mln_assertion(tree_fast.has (elt6));
+ mln_assertion(tree_fast.search(elt6) == tree_fast.root_);
+}
Index: trunk/milena/tests/util/Makefile.am
===================================================================
--- trunk/milena/tests/util/Makefile.am (revision 1552)
+++ trunk/milena/tests/util/Makefile.am (revision 1553)
@@ -13,7 +13,8 @@
tree \
tree_fast \
tree_fast_to_image \
- tree_to_image
+ tree_to_image \
+ tree_to_fast
all_headers_SOURCES = all_headers.cc
branch_iter_SOURCES = branch_iter.cc
@@ -25,5 +26,6 @@
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
TESTS = $(check_PROGRAMS)
Index: trunk/milena/mln/util/tree_to_fast.hh
===================================================================
--- trunk/milena/mln/util/tree_to_fast.hh (revision 0)
+++ trunk/milena/mln/util/tree_to_fast.hh (revision 1553)
@@ -0,0 +1,110 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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.
+
+#ifndef MLN_UTIL_TREE_TO_FAST_HH
+# define MLN_UTIL_TREE_TO_FAST_HH
+
+/*!
+ * \file mln/util/tree_to_fast.hh
+ *
+ * \brief Definition of function which converts a tree into tree_fast.
+ *
+ */
+
+# include <mln/util/tree.hh>
+# include <mln/util/tree_fast.hh>
+# include <mln/trace/all.hh>
+
+
+namespace mln
+{
+
+ namespace util
+ {
+
+
+ /*! Convert a tree into an tree_fast.
+ *
+ * \param[in] input The tree to convert.
+ *
+ * \return The tree_fast containing tree informations.
+ *
+ */
+ template<typename T>
+ tree_fast<T>
+ tree_to_fast(tree<T>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace impl
+ {
+
+ template<typename T>
+ void
+ tree_to_fast_(node<T>* input, tree_fast<T>& tree, unsigned p,
unsigned& i)
+ {
+ typename node<T>::children_t child = input->children ();
+ typename node<T>::children_t::iterator it = child.begin ();
+
+ for (; it != child.end (); ++it)
+ {
+ tree.add_child(p, (*it)->elt ());
+ ++i;
+ impl::tree_to_fast_((*it), tree, i, i);
+ }
+ }
+
+ }
+
+ /// Facade.
+
+ template<typename T>
+ tree_fast<T>
+ tree_to_fast(tree<T>& input)
+ {
+ trace::entering("util::tree_to_fast");
+
+ unsigned i = 0;
+ tree_fast<T> tree (input.root ()->elt ());
+
+ impl::tree_to_fast_(input.root (), tree, 0, i);
+
+ trace::exiting("util::tree_to_fast");
+ return tree;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+
+#endif // !MLN_UTIL_TREE_TO_FAST_HH
+
Index: trunk/milena/mln/util/tree_fast_to_image.hh
===================================================================
--- trunk/milena/mln/util/tree_fast_to_image.hh (revision 1552)
+++ trunk/milena/mln/util/tree_fast_to_image.hh (revision 1553)
@@ -89,7 +89,7 @@
trace::exiting("util::impl::tree_fast_to_image");
}
- } // end of mln::util::impl
+ } // end of namespace mln::util::impl