/// <summary> /// Tries to apply travesal to the entry suitable for char c, if no such entry, then returns false and back to root. otherwise travels and returns true. /// </summary> /// <param name="c"></param> public bool travel( char c ) { current = current.neighbours[c]; if ( current == null ) { rewind(); return false; } else currentPosition++; sb.Append(c); return true; }
private void recoursiveTravel( Node node , ICollection<Node> results ) { if ( node == null ) return; Neighberhood n = node.neighbours; for ( int i = 0 ; i < n.Size ; i++ ) { Node temp = n[i]; recoursiveTravel(temp , results); if ( temp.isLeaf() ) results.Add(temp); } }
public bool back() { current = current.parent; bool fail = current == null; if ( fail ) { currentPosition = 0; current = trie.root; } else { currentPosition--; sb.Length--; } return !fail; }
/// <summary> /// travels back to the root of the trie /// </summary> public void rewind() { currentPosition = 0; current = trie.root; sb.Clear(); }
public TrieTraveler( Trie t ) { trie = t; current = trie.root; sb = new StringBuilder(); }
public TrieTraveler( TrieTraveler trieTraveler ) { current = trieTraveler.current; currentPosition = trieTraveler.currentPosition; trie = trieTraveler.trie; sb = new StringBuilder(trieTraveler.sb.ToString()); }
public void clear() { root = new Node(); traveler = new TrieTraveler(this); this.count = 0; }
public Trie( string[] strings ) { root = new Node(); traveler = new TrieTraveler(this); foreach (string s in strings) add(s); }
public Trie( String s ) { root = new Node(); traveler = new TrieTraveler(this); addAll(s); }
public Trie() { root = new Node(); traveler = new TrieTraveler(this); }
public Node( Node parent , char c ) { this.parent = parent; this.c = c; }