Ejemplo n.º 1
0
 public bool TryGetValue(char c, out TrieNode3 node)
 {
     if (minflag <= (uint)c && maxflag >= (uint)c)
     {
         return(m_values.TryGetValue(c, out node));
     }
     node = null;
     return(false);
 }
Ejemplo n.º 2
0
 public void Add(char c, TrieNode3 node3)
 {
     if (minflag > c)
     {
         minflag = c;
     }
     if (maxflag < c)
     {
         maxflag = c;
     }
     m_values.Add(c, node3);
 }
Ejemplo n.º 3
0
        protected virtual void SetKeywords2(List <string> keywords)
        {
            List <TrieNode> allNode = BuildFirstLayerTrieNode(keywords);
            TrieNode        root    = allNode[0];

            var allNode2 = new List <TrieNode3>();

            for (int i = 0; i < allNode.Count; i++)
            {
                allNode2.Add(new TrieNode3());
            }

            for (int i = 0; i < allNode2.Count; i++)
            {
                var oldNode = allNode[i];
                var newNode = allNode2[i];

                foreach (var item in oldNode.m_values)
                {
                    var key   = item.Key;
                    var index = item.Value.Index;
                    if (key == 0)
                    {
                        newNode.HasWildcard  = true;
                        newNode.WildcardNode = allNode2[index];
                        continue;
                    }
                    newNode.Add(key, allNode2[index]);
                }
                foreach (var item in oldNode.Results)
                {
                    if (oldNode.IsWildcard)
                    {
                        if (keywords[item].Length > oldNode.WildcardLayer)
                        {
                            newNode.SetResults(item);
                        }
                    }
                    else
                    {
                        newNode.SetResults(item);
                    }
                    //newNode.SetResults(item);
                }

                var failure = oldNode.Failure;
                while (failure != root)
                {
                    if (oldNode.IsWildcard && failure.Layer <= oldNode.WildcardLayer)
                    {
                        break;
                    }
                    foreach (var item in failure.m_values)
                    {
                        var key   = item.Key;
                        var index = item.Value.Index;
                        if (key == 0)
                        {
                            newNode.HasWildcard = true;
                            if (newNode.WildcardNode == null)
                            {
                                newNode.WildcardNode = allNode2[index];
                            }
                            continue;
                        }
                        if (newNode.HasKey(key) == false)
                        {
                            newNode.Add(key, allNode2[index]);
                        }
                    }
                    foreach (var item in failure.Results)
                    {
                        if (oldNode.IsWildcard)
                        {
                            if (keywords[item].Length > oldNode.WildcardLayer)
                            {
                                newNode.SetResults(item);
                            }
                        }
                        else
                        {
                            newNode.SetResults(item);
                        }
                    }
                    failure = failure.Failure;
                }
            }
            allNode.Clear();
            allNode = null;
            root    = null;

            //var root2 = allNode2[0];
            TrieNode3[] first = new TrieNode3[char.MaxValue + 1];
            foreach (var item in allNode2[0].m_values)
            {
                first[item.Key] = item.Value;
            }
            _first = first;
        }