Example #1
0
 /// <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;
 }
Example #2
0
 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);
     }
 }
Example #3
0
 public bool back()
 {
     current = current.parent;
     bool fail = current == null;
     if ( fail ) {
         currentPosition = 0;
         current = trie.root;
     } else {
         currentPosition--;
         sb.Length--;
     }
     return !fail;
 }
Example #4
0
 /// <summary>
 /// travels back to the root of the trie
 /// </summary>
 public void rewind()
 {
     currentPosition = 0;
     current = trie.root;
     sb.Clear();
 }
Example #5
0
 public TrieTraveler( Trie t )
 {
     trie = t;
     current = trie.root;
     sb = new StringBuilder();
 }
Example #6
0
 public TrieTraveler( TrieTraveler trieTraveler )
 {
     current = trieTraveler.current;
     currentPosition = trieTraveler.currentPosition;
     trie = trieTraveler.trie;
     sb = new StringBuilder(trieTraveler.sb.ToString());
 }
Example #7
0
 public void clear()
 {
     root = new Node();
     traveler = new TrieTraveler(this);
     this.count = 0;
 }
Example #8
0
 public Trie( string[] strings )
 {
     root = new Node();
     traveler = new TrieTraveler(this);
     foreach (string s in strings)
         add(s);
 }
Example #9
0
 public Trie( String s )
 {
     root = new Node();
     traveler = new TrieTraveler(this);
     addAll(s);
 }
Example #10
0
 public Trie()
 {
     root = new Node();
     traveler = new TrieTraveler(this);
 }
Example #11
0
 public Node( Node parent , char c )
 {
     this.parent = parent;
     this.c = c;
 }