public TriNode() { hitCount = 0; children = new TriNode [26]; for (int i = 0; i < 26; i++) { children [i] = null; } }
public void NextSuperTriNode(SuperTriNode superTriNode, TriNode triNode, int id) { for (int i = 0; i < 26; i++) { if (triNode.children [i] != null) { if (superTriNode.children [i] == null) { superTriNode.children [i] = new SuperTriNode(); } if (!superTriNode.children[i].hitList.Contains(id)) { superTriNode.children[i].hitList.Add(id); } NextSuperTriNode(superTriNode.children [i], triNode.children [i], id); } } }
public bool IsSubString(string s) { string realS = s.ToLower(); TriNode curNode = root; for (int i = 0; i < realS.Length; i++) { int c = realS[i] - 'a'; if ((c < 0) || (c >= 26)) { continue; } if (curNode.children[c] == null) { return(false); } curNode = curNode.children[c]; } return(true); }
public int CountOccurrences(string s) { string realS = s.ToLower(); TriNode curNode = root; for (int i = 0; i < realS.Length; i++) { int c = realS[i] - 'a'; if ((c < 0) || (c >= 26)) { continue; } if (curNode.children[c] == null) { return(0); } curNode = curNode.children[c]; } return(curNode.hitCount); }
public TriNode(string [] s, ref int pos) { if (pos >= s.Length) { return; } hitCount = int.Parse(s [pos]); pos++; children = new TriNode [26]; for (int i = 0; i < 26; i++) { if (s [pos] != "") { children [i] = new TriNode(s, ref pos); } else { children [i] = null; pos++; } } }
public void AddString(string s) { string realS = s.ToLower(); TriNode curNode = root; for (int i = 0; i < realS.Length; i++) { int c = realS[i] - 'a'; if ((c < 0) || (c >= 26)) { continue; } if (curNode.children[c] == null) { curNode.children[c] = new TriNode(); } curNode = curNode.children[c]; } if (curNode != root) { curNode.hitCount++; } }
public Tri(string s) { int pos = 0; root = new TriNode(Decompress(s).Split(','), ref pos); }
public Tri() { root = new TriNode(); }