I am fine with leaving it recursive, but just ensure that it works well ;)
On 6 Aug 2013 20:44, "Shell Hu" <notifications@github.com> wrote:
>
> In src/shogun/structure/FactorGraph.cpp:
>
> > +void CDisjointSet::make_sets()
> > +{
> > + REQUIRE(m_num_elements > 0, "%s::make_sets(): m_num_elements <=
0.\n", get_name());
> > +
> > + m_parent.range_fill();
> > + m_rank.zero();
> > +}
> > +
> > +// TODO: no recursion, make funcs const
> > +int32_t CDisjointSet::find_set(int32_t x)
> > +{
> > + ASSERT(x >= 0 && x < m_num_elements);
> > +
> > + // path compression
> > + if (x != m_parent[x])
> > + m_parent[x] = find_set(m_parent[x]);
>
> In theory, after calling make_set(), in which set the parent of each
element to itself, the recursion will be ended after at most O(num_element)
steps. I am agree to rewrite it with no recursion and add some unit-tests.
>
> —
> Reply to this email directly or view it on GitHub.