public SuffixTreeNodeDebugView(SuffixTreeNode node) { Guard.IsNotNull(node, nameof(node)); this.node = node; this.keys = node.GetKeys(); this.children = node.GetChildren(); }
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); }
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); }
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); }
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); }
public SuffixTreeNodeResolver(SuffixTreeNode root) { Guard.IsNotNull(root, nameof(root)); this.root = root; }
public SuffixTreeEdge(string label, SuffixTreeNode startNode, SuffixTreeNode endNode) { this.label = label; this.startNode = startNode; this.endNode = endNode; }