Exemple #1
0
 public void Insert(IEnumerator <TKey> keyword, TValue value)
 {
     if (keyword.MoveNext())
     {
         var current = keyword.Current;
         if (_children.TryGetValue(current, out var node))
         {
             node.Insert(keyword, value);
         }
         else
         {
             var child = new TrieTreeNode <TKey, TValue>(current, _comparer);
             child.Insert(keyword, value);
             _children.Add(current, child);
         }
     }
     else
     {
         if (_values == null)
         {
             _values = new List <TValue>();
         }
         _values.Add(value);
     }
     _childrenValueCount += 1;
 }
Exemple #2
0
        public static TrieTreeNode <TKey, TValue> ToTrieTree <TKey, TValue>(
            this IEnumerable <TValue> source,
            Func <TValue, IEnumerable <TKey> > keySelector,
            IEqualityComparer <TKey> comparer)
        {
            var tree = new TrieTreeNode <TKey, TValue>(comparer);

            foreach (var value in source)
            {
                tree.Insert(keySelector(value).GetEnumerator(), value);
            }
            return(tree);
        }