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