コード例 #1
0
        internal void MergeChild(int childIndex)
        {
            TrieSegment old = this.children[childIndex];

            if (old.CanMerge)
            {
                TrieSegment   replace = old.children[0];
                StringBuilder builder = new StringBuilder();
                builder.Append(old.segmentTail);
                builder.Append(replace.segmentFirstChar);
                builder.Append(replace.segmentTail);
                replace.SetSegment(old.segmentFirstChar, builder.ToString());
                replace.parent = this;
                this.children.Exchange(old, replace);
                old.parent = null;
            }
        }
コード例 #2
0
        /// <summary>
        /// If the child node has no data associated with it and but one child of its own, it can be
        /// merged with the child, reducing the path by 1
        /// </summary>
        internal void MergeChild(int childIndex)
        {
            Fx.Assert(this.HasChildren, "");

            TrieSegment child = this.children[childIndex];

            if (child.CanMerge)
            {
                TrieSegment grandchild = child.children[0];

                StringBuilder newTail = new StringBuilder();
                newTail.Append(child.segmentTail);
                newTail.Append(grandchild.segmentFirstChar);
                newTail.Append(grandchild.segmentTail);

                grandchild.SetSegment(child.segmentFirstChar, newTail.ToString());
                grandchild.parent = this;

                this.children.Exchange(child, grandchild);
                child.parent = null;
            }
        }