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_CANVAS_MORPHO_INTERNAL_FIND_ROOT_HH
00027 # define MLN_CANVAS_MORPHO_INTERNAL_FIND_ROOT_HH
00028 
00034 
00035 # include <mln/core/concept/image.hh>
00036 
00037 namespace mln
00038 {
00039 
00040   namespace canvas
00041   {
00042 
00043     namespace morpho
00044     {
00045 
00046       namespace internal
00047       {
00048 
00049           template <typename I>
00050           inline
00051           mln_psite(I)
00052           find_root(I& parent, const mln_psite(I)& x);
00053 
00054 
00055           template <typename I>
00056           inline
00057           unsigned
00058           find_root_fastest(I& parent, unsigned x);
00059 
00060 
00061 # ifndef MLN_INCLUDE_ONLY
00062 
00063 
00064           template <typename I>
00065           inline
00066           mln_psite(I)
00067           find_root(I& parent, const mln_psite(I)& x)
00068           {
00069             if (parent(x) == x)
00070               return x;
00071             else
00072               return parent(x) = find_root(parent, parent(x));
00073           }
00074 
00075 
00076           template <typename I>
00077           inline
00078           unsigned
00079           find_root_fastest(I& parent, unsigned x)
00080           {
00081             if (parent.element(x) == 0)
00082               return x;
00083             else
00084               return parent.element(x) = find_root_fastest(parent,
00085                                                            parent.element(x));
00086           }
00087 
00088 
00089 # endif // ! MLN_INCLUDE_ONLY
00090 
00091       } 
00092 
00093     } 
00094 
00095   } 
00096 
00097 } 
00098 
00099 #endif // ! MLN_CANVAS_MORPHO_INTERNAL_FIND_ROOT_HH