示例#1
0
        protected void FillBuffer(ParsingNode node, int depth, int marginGlobal)
        {
            if (node is null)
            {
                return;
            }

            int marginKey         = marginGlobal + node.MarginKey;
            int marginLeft        = marginGlobal + node.MarginLeftChild;
            int marginRight       = marginGlobal + node.MarginRightChild;
            int marginGlobalRight = marginKey + 1 + node.SizeRightLine;

            this.Buffer.Fill(marginKey, depth * 3 - 3, node.Key);

            if (node.Left is not null || node.Right is not null)
            {
                this.Buffer.Fill(marginKey, depth * 3 - 2, "|");
            }

            if (node.Left is not null)
            {
                FillLine(FillDirection.LEFT, node.Left.Key, depth * 3 - 1, marginLeft, marginKey);
                FillBuffer(node.Left, depth + 1, marginGlobal);
            }

            if (node.Right is not null)
            {
                FillLine(FillDirection.RIGHT, node.Right.Key, depth * 3 - 1, marginKey, marginRight);
                FillBuffer(node.Right, depth + 1, marginGlobalRight);
            }
        }
示例#2
0
        //////////////////////////////////////////////////////////////
        //                        METHODS (PROTECTED)
        //////////////////////////////////////////////////////////////



        protected void process <TKey, TNode>(TNode inputRoot)
            where TKey : IComparable where TNode : BinNode <TKey, TNode>, new()
        {
            int heightInpRoot = this.Parser.GetHeight <TKey, TNode>(inputRoot);
            int height        = heightInpRoot * 3 - 2;

            ParsingNode parsingTree = this.Parser.BuildTree <TKey, TNode>(inputRoot);

            this.Buffer = new MatrixBuffer(parsingTree.Width + this.MarginLeft, height);

            FillBuffer(parsingTree, 1, this.MarginLeft);

            this.Parser.DestroyTree(ref parsingTree);
        }
        public void DestroyTree(ref ParsingNode node)
        {
            if (node is null)
            {
                return;
            }

            DestroyTree(ref node.Left);
            node.Left = null;

            DestroyTree(ref node.Right);
            node.Right = null;

            node.Key = null;
            node     = null;
        }
        public ParsingNode BuildTree <TKey, TNode>(TNode inputRoot)
            where TKey : IComparable where TNode : BinNode <TKey, TNode>, new()
        {
            if (inputRoot is null)
            {
                return(null);
            }

            var node   = new ParsingNode(this.ValueUtil.GetStr(inputRoot.Key));
            int lenKey = node.Key.Length;

            node.Left  = BuildTree <TKey, TNode>(inputRoot.Left);
            node.Right = BuildTree <TKey, TNode>(inputRoot.Right);

            bool nodeLeftNull  = (node.Left is null);
            bool nodeRightNull = (node.Right is null);

            int widthLeftBranch  = nodeLeftNull ? 0 : node.Left.Width;
            int widthRightBranch = nodeRightNull ? 0 : node.Right.Width;

            int sizeLeftLine  = nodeLeftNull ? 0 : this.LineBrsp;
            int sizeRightLine = nodeRightNull ? 0 : this.LineBrsp;

            int fullWidth = widthLeftBranch + widthRightBranch + sizeLeftLine + sizeRightLine;

            int sizeRightOverflow = lenKey - (widthRightBranch + sizeRightLine);

            fullWidth += Math.Max(1, sizeRightOverflow);

            int marginKey        = widthLeftBranch + sizeLeftLine;
            int marginLeftChild  = nodeLeftNull ? 0 : node.Left.MarginKey;
            int marginRightChild = nodeRightNull ? 0 : marginKey + node.Right.MarginKey + sizeRightLine + 1;

            node.Width            = fullWidth;
            node.WidthLeftBranch  = widthLeftBranch;
            node.WidthRightBranch = widthRightBranch;
            node.SizeLeftLine     = sizeLeftLine;
            node.SizeRightLine    = sizeRightLine;

            node.MarginKey        = marginKey;
            node.MarginLeftChild  = marginLeftChild;
            node.MarginRightChild = marginRightChild;

            return(node);
        }