public void InsertSuffix(string s, int from) { var cur = Root; for (int i = from; i < s.Length; ++i) { var c = s[i]; if (!cur.Children.ContainsKey(c)) { var n = new SuffixTreeNode() { Index = from }; cur.Children.Add(c, n); // Very slow assertion. Debug.Assert(Find(s.Substring(from)).Any()); return; } cur = cur.Children[c]; } Debug.Assert(false, "It should never be possible to arrive at this case"); throw new Exception("Suffix tree corruption"); }
//Insert the given string in this suffixtree node and //index is the index of the first char in the original string.. public void InsertString(string s, int index) { IndexList.Add(index); if (s != null && s.Length > 0) { //hardcoded get the first char of string char value = s[0]; SuffixTreeNode child = null; if (Children.ContainsKey(value)) { child = Children[value]; } else { //new child child = new SuffixTreeNode(value); this.Children.Add(value, child); } //hardcoded to 1 b string remaining = s.Substring(1); //note we are passing the index of the parent node to the child child.InsertString(remaining, index); } }
private static IEnumerable <SuffixTreeNode> VisitTree(SuffixTreeNode n) { foreach (var n1 in n.Children.Values) { foreach (var n2 in VisitTree(n1)) { yield return(n2); } } yield return(n); }