Exemple #1
0
        private unsafe int Find(UF *uf, int a)
        {
            Debug.Assert(IsInRange(a));
            if (uf[a].Parent != a)
            {
                uf[a].Parent = Find(uf[a].Parent);
            }

            return(uf[a].Parent);
        }
Exemple #2
0
        private unsafe int Find(UF *uf, int a)
        {
            Debug.Assert(IsInRange(a));
            if (s_stack == null)
            {
                s_stack = new Stack <int>();
            }

            while (uf[a].Parent != a)
            {
                s_stack.Push(a);
                a = uf[a].Parent;
            }

            while (s_stack.Count > 0)
            {
                int k = s_stack.Pop();
                uf[k].Parent = a;
            }

            return(a);
        }
Exemple #3
0
        // This version is about 10% faster than recursive
        private unsafe int Find(UF *uf, int a)
        {
            Debug.Assert(IsInRange(a));

            step *s = null;

            while (uf[a].Parent != a)
            {
                step *c = stackalloc step[1];
                c->Element = a;
                c->Prev    = s;
                s          = c;

                a = uf[a].Parent;
            }

            while (s != null)
            {
                uf[s->Element].Parent = a;
                s = s->Prev;
            }

            return(a);
        }