Exemplo n.º 1
0
        private HeapNode CombineNodes(HeapNode first, HeapNode add)
        {
            int comp = Comparer.Compare(first.Key, add.Key);

            HeapNode smaller = first;
            HeapNode other   = add;

            if (comp > 0)
            {
                Swap(ref smaller, ref other);
            }

            Debug.Assert(smaller.Order == other.Order);
            other.Cut();
            smaller.AddChild(other);
            smaller.Order++;
            LastConsolidateDepth++;

            Debug.Assert(smaller.ChildrenCount <= smaller.Order);

#if VERBOSE
            Console.WriteLine("Merging tree under another: {0} (under {1})", other, smaller);
            Console.WriteLine("All siblings ({0}): ", smaller.ChildrenCount);
            foreach (var siblingNode in smaller.FirstChild.GetSiblings().Take(4))
            {
                Console.WriteLine(siblingNode);
            }
#endif

            return(smaller);
        }