예제 #1
0
        protected static void StampFill(Id i, Event e)
        {
            if (i.IsLeaf
                && i.Value == 0)
            {
                return;
            }

            if (i.IsLeaf
                && i.Value == 1)
            {
                e.Height();
                return;
            }

            if (e.IsLeaf)
            {
                return;
            }

            if (i.IsLeaf == false
                && i.Left.IsLeaf
                && i.Left.Value == 1)
            {
                StampFill(i.Right, e.Right);
                e.Left.Height();
                e.Left.SetMaxValue(e.Left, e.Right);
                e.Normalize();
                return;
            }

            if (i.IsLeaf == false
                && i.Right.IsLeaf
                && i.Right.Value == 1)
            {
                StampFill(i.Left, e.Left);
                e.Right.Height();
                e.Right.SetMaxValue(e.Right, e.Left);
                e.Normalize();
                return;
            }

            if (i.IsLeaf == false)
            {
                StampFill(i.Left, e.Left);
                StampFill(i.Right, e.Right);
                e.Normalize();
                return;
            }

            throw new StampOperationException(string.Format("Fill failed: id: {0}, event: {1}", i, e));
        }