00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MLN_UTIL_TREE_TO_FAST_HH
00027 # define MLN_UTIL_TREE_TO_FAST_HH
00028
00036 # include <mln/util/tree.hh>
00037 # include <mln/util/tree_fast.hh>
00038 # include <mln/trace/all.hh>
00039
00040
00041 namespace mln
00042 {
00043
00044 namespace util
00045 {
00046
00047
00055 template<typename T>
00056 tree_fast<T>
00057 tree_to_fast(tree<T>& input);
00058
00059
00060 # ifndef MLN_INCLUDE_ONLY
00061
00062
00063 namespace impl
00064 {
00065
00066 template<typename T>
00067 inline
00068 void
00069 tree_to_fast_(tree_node<T>* input, tree_fast<T>& tree,
00070 unsigned p, unsigned& i)
00071 {
00072 typename tree_node<T>::children_t child = input->children ();
00073 typename tree_node<T>::children_t::iterator it = child.begin ();
00074
00075 for (; it != child.end (); ++it)
00076 {
00077 tree.add_child(p, (*it)->elt ());
00078 ++i;
00079 impl::tree_to_fast_((*it), tree, i, i);
00080 }
00081 }
00082
00083 }
00084
00086
00087 template<typename T>
00088 inline
00089 tree_fast<T>
00090 tree_to_fast(tree<T>& input)
00091 {
00092 trace::entering("util::tree_to_fast");
00093
00094 unsigned i = 0;
00095 tree_fast<T> tree (input.root ()->elt ());
00096
00097 impl::tree_to_fast_(input.root (), tree, 0, i);
00098
00099 trace::exiting("util::tree_to_fast");
00100 return tree;
00101 }
00102
00103 # endif // ! MLN_INCLUDE_ONLY
00104
00105 }
00106
00107 }
00108
00109
00110 #endif // ! MLN_UTIL_TREE_TO_FAST_HH