private NodeMeta SwapWithAdjacent(NodeMeta meta, Side side)
        {
            Side     otherSide    = OtherSide(side);
            NodeMeta adjacentMeta = Adjacent(side, meta);
            Node     adjacent     = adjacentMeta.Node;
            Node     toBeReplaced = meta.Node;


            Node adjacentParent = adjacentMeta.ParentMeta.Node;

            adjacentParent[otherSide] = adjacent[side];

            // Swap the nodes.
            // Cache the children of item to be replaced.
            Node child = adjacent[side];

            // Adjacent takes place of node to be removed.
            meta.ReplaceNode(adjacent);
            meta.ParentMeta.Node[meta.SideFromParent] = adjacent;
            adjacent[side]      = toBeReplaced[side];
            adjacent[otherSide] = toBeReplaced[otherSide];

            // Put node to be replaced in adjacent spot
            adjacentParent[otherSide] = toBeReplaced;
            toBeReplaced[side]        = child;
            toBeReplaced[otherSide]   = null; // This is null, that is how we know it is the leaf
            adjacentMeta.ReplaceNode(toBeReplaced);

            // Swap the color
            Color temp = toBeReplaced.Color;

            toBeReplaced.Color = adjacent.Color;
            adjacent.Color     = temp;

            if (child == null)
            {
                // We have found the node to remove. Replace it with a sentinal
                SentinelNode sentinel = new SentinelNode(toBeReplaced.Color);
                adjacentParent[otherSide] = sentinel;
                return(new NodeMeta(adjacentMeta.ParentMeta, sentinel, adjacentMeta.SideFromParent, adjacentMeta.Sibling));
            }
            else
            {
                return(SwapWithAdjacent(adjacentMeta, side));
            }
        }
        private NodeMeta SwapWithAdjacent(NodeMeta meta, Side side)
        {
            Side     otherSide      = OtherSide(side);
            NodeMeta adjacentMeta   = Adjacent(side, meta);
            Node     adjacent       = adjacentMeta.Node;
            Node     toBeReplaced   = meta.Node;
            Node     adjacentParent = adjacentMeta.ParentMeta.Node;

            // Swap the nodes.
            // Cache the children of item to be replaced.
            Node child = adjacent[side];

            bool parentChildSwap = toBeReplaced[side] == adjacent;

            // Adjacent takes place of node to be removed.
            meta.ReplaceNode(adjacent);
            if (meta.ParentMeta == null)
            {
                root = adjacent;
            }
            else
            {
                meta.ParentMeta.Node[meta.SideFromParent] = adjacent;
            }
            if (!parentChildSwap)
            {
                adjacent[side] = toBeReplaced[side];
            }
            adjacent[otherSide] = toBeReplaced[otherSide];

            // Put node to be replaced in adjacent spot
            if (parentChildSwap)
            {
                adjacent[otherSide] = toBeReplaced;
            }
            else
            {
                adjacentParent[otherSide] = toBeReplaced;
            }
            toBeReplaced[side]      = child;
            toBeReplaced[otherSide] = null; // This is null, that is how we know it is the leaf
            adjacentMeta.ReplaceNode(toBeReplaced);

            // Swap the color
            Color temp = toBeReplaced.Color;

            toBeReplaced.Color = adjacent.Color;
            adjacent.Color     = temp;
            if (meta.ParentMeta == null)
            {
                adjacent.Color = Color.Black;
            }

            if (child == null)
            {
                // We have found the node to remove. Replace it with a sentinal
                return(adjacentMeta);
            }
            else
            {
                return(SwapWithAdjacent(adjacentMeta, side));
            }
        }