示例#1
0
 public Trie(IEnumerable <Tuple <byte[], int> > tuples, bool regex = false)
 {
     Root = new Node();
     Tuple <byte[], int>[] enumerable = tuples as Tuple <byte[], int>[] ?? tuples.ToArray();
     Console.WriteLine("Building new tree from {0} words.", enumerable.Length);
     enumerable.ForEach(t =>
     {
         BaseNode current = Root;
         t.Item1.ForEach(b => current.Add(b, t.Item2, out current));
         current?.End(t.Item2);
     });
     Node.Loaded = true;
 }
示例#2
0
 /// <summary>
 /// Builds a suffix tree.  Every string is split into individual words, and each word associated with an <see cref="Node"/>.
 /// </summary>
 /// <param name="reader"></param>
 public Trie(IDictionary <byte[], HashSet <int> > reader)
 {
     Console.WriteLine("Building new tree from {0} words.", reader.Count());
     Root = new Node();
     reader.ForEach(kv =>
     {
         BaseNode current = Root;
         int val          = kv.Value.First();
         foreach (byte b in kv.Key)
         {
         }
         kv.Key.ForEach(b => current.Add(b, val, out current)); //Build the branch using each byte as a node
         current?.End(val);                                     //Mark the final node as a terminal
     });
     Node.Loaded = true;
 }