milena r1395: Fix tree

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-26 Matthieu Garrigues <garrigues@lrde.epita.fr> Fix tree. * mln/util/branch_iter.hh, * mln/util/tree.hh, * tests/tree.cc: Fix. --- mln/util/branch_iter.hh | 2 +- mln/util/tree.hh | 31 +++++++++++++++++++++++-------- tests/tree.cc | 2 -- 3 files changed, 24 insertions(+), 11 deletions(-) Index: trunk/milena/tests/tree.cc =================================================================== --- trunk/milena/tests/tree.cc (revision 1394) +++ trunk/milena/tests/tree.cc (revision 1395) @@ -60,6 +60,4 @@ util::tree<unsigned>* tre = new util::tree<unsigned>(&node); mln_assertion(tre); tre->add_tree_up(elt6); - util::tree<unsigned>* trees = tre->tree_get(elt5); - mln_assertion(trees); } Index: trunk/milena/mln/util/tree.hh =================================================================== --- trunk/milena/mln/util/tree.hh (revision 1394) +++ trunk/milena/mln/util/tree.hh (revision 1395) @@ -55,6 +55,7 @@ { public: + typedef std::vector< node<T>* > children_t; /// \{ Constructors node(); node(T elt); @@ -66,15 +67,15 @@ /// \} /// Access to the children - const std::vector< node<T>* >& children() const; - std::vector< node<T>* >& children(); + const children_t& children() const; + children_t& children(); /// Access to the parent node. + //node<T>*& parent(); const node<T>* parent() const; node<T>* add_child(T elt); void set_parent(node<T>* parent); - node<T>* get_parent(); void print_rec(int n) const; void print() const; int search_rec(node<T>** res, T& elt); @@ -96,6 +97,7 @@ tree(node<T>* root); node<T>* root(); + branch<T> main_branch(); void add_tree_up (T& elt); void add_tree_down (T& elt); @@ -142,12 +144,19 @@ } template <typename T> + branch<T> + tree<T>::main_branch() + { + return branch<T>(*this, root()); + } + + template <typename T> void tree<T>::add_tree_up(T& elt) { node<T>* n = new node<T> (elt); - root_->parent_ = n; - n->child_.push_back (root_); + root_->set_parent(n); + n->children().push_back (root_); root_ = n; } @@ -222,14 +231,20 @@ parent->child_.push_back(this); } - template <typename T> - node<T>* - node<T>::get_parent() + const node<T>* + node<T>::parent() const { return parent_; } +// template <typename T> +// node<T>*& +// node<T>::parent() +// { +// return parent_; +// } + template <typename T> int node<T>::search_rec(node<T>** res, T& elt) Index: trunk/milena/mln/util/branch_iter.hh =================================================================== --- trunk/milena/mln/util/branch_iter.hh (revision 1394) +++ trunk/milena/mln/util/branch_iter.hh (revision 1395) @@ -49,7 +49,7 @@ branch_iter(branch<T> branch); /// Convertion to node. - operator node<T>&() const; + operator util::node<T>&() const; /// Test the iterator validity. bool is_valid() const;

Matthieu Garrigues <garrigues@lrde.epita.fr> writes:
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog: 2007-10-26 Matthieu Garrigues <garrigues@lrde.epita.fr>
Fix tree. * mln/util/branch_iter.hh, * mln/util/tree.hh, * tests/tree.cc: Fix.
Be more explicit. [...]
Index: trunk/milena/mln/util/tree.hh =================================================================== --- trunk/milena/mln/util/tree.hh (revision 1394) +++ trunk/milena/mln/util/tree.hh (revision 1395) @@ -55,6 +55,7 @@ { public:
+ typedef std::vector< node<T>* > children_t;
It's always a good thing to document the interface of a class. Unless this typedef is solely used by the implementation (in which case, it shall be private), please document it. [...]
@@ -66,15 +67,15 @@ /// \}
/// Access to the children - const std::vector< node<T>* >& children() const; - std::vector< node<T>* >& children(); + const children_t& children() const; + children_t& children();
/// Access to the parent node. + //node<T>*& parent();
Dead code. [...]
@@ -142,12 +144,19 @@ }
template <typename T> + branch<T> + tree<T>::main_branch() + { + return branch<T>(*this, root()); + }
Undocumented function in ChangeLog entry. [...]
@@ -222,14 +231,20 @@ parent->child_.push_back(this); }
- template <typename T> - node<T>* - node<T>::get_parent() + const node<T>* + node<T>::parent() const { return parent_; }
+// template <typename T> +// node<T>*& +// node<T>::parent() +// { +// return parent_; +// }
Dead code. [...]
participants (2)
-
Matthieu Garrigues
-
Roland Levillain