コード例 #1
0
 public SuffixTreeNodeDebugView(SuffixTreeNode node)
 {
     Guard.IsNotNull(node, nameof(node));
     this.node     = node;
     this.keys     = node.GetKeys();
     this.children = node.GetChildren();
 }
コード例 #2
0
        public void AddChild(string label, SuffixTreeNode node)
        {
            Guard.IsNotNullOrEmpty(label);
            SuffixTreeEdge edge = new SuffixTreeEdge(label, this, node);

            KeyToEdgeMap.Add(label, edge);
            SymbolToEdgeMap.Add(label[0], edge);
        }
コード例 #3
0
 public SuffixTree(char terminalSymbol, string text)
 {
     Guard.IsNotNull(text, nameof(text));
     this.terminalSymbol = terminalSymbol;
     this.text           = text;
     this.root           = SuffixTreeBuilder.Build(terminalSymbol, text);
     this.resolver       = new SuffixTreeNodeResolver(root);
 }
コード例 #4
0
        static SuffixTreeNode BuildCore(SuffixGroup group, int index)
        {
            if (group.Size == 1)
            {
                return(new SuffixTreeNode(index, true));
            }

            SuffixTreeNode node = new SuffixTreeNode(-1, false);

            foreach (SuffixGroup subGroup in group.BuildGroups())
            {
                string      prefix;
                SuffixGroup reducedGroup = subGroup.Reduce(out prefix);
                node.AddChild(prefix, BuildCore(reducedGroup, index - prefix.Length));
            }
            return(node);
        }
コード例 #5
0
        public SuffixTreeNode Resolve(string @string)
        {
            int            index = -1;
            SuffixTreeNode node  = root;
            SuffixTreeEdge edge  = null;

            for (int n = 0; n < @string.Length; n++)
            {
                char symbol = @string[n];
                if (index == -1)
                {
                    edge = node.GetEdge(symbol);
                    if (edge == null)
                    {
                        return(null);
                    }
                    node = edge.EndNode;
                    if (edge.Label.Length > 1)
                    {
                        index = 1;
                    }
                }
                else
                {
                    if (symbol != edge.Label[index])
                    {
                        return(null);
                    }
                    if (++index == edge.Label.Length)
                    {
                        index = -1;
                    }
                }
            }
            return(node);
        }
コード例 #6
0
 public SuffixTreeNodeResolver(SuffixTreeNode root)
 {
     Guard.IsNotNull(root, nameof(root));
     this.root = root;
 }
コード例 #7
0
 public SuffixTreeEdge(string label, SuffixTreeNode startNode, SuffixTreeNode endNode)
 {
     this.label     = label;
     this.startNode = startNode;
     this.endNode   = endNode;
 }