Пример #1
0
 public TriNode()
 {
     hitCount = 0;
     children = new TriNode [26];
     for (int i = 0; i < 26; i++)
     {
         children [i] = null;
     }
 }
Пример #2
0
 public void NextSuperTriNode(SuperTriNode superTriNode, TriNode triNode, int id)
 {
     for (int i = 0; i < 26; i++)
     {
         if (triNode.children [i] != null)
         {
             if (superTriNode.children [i] == null)
             {
                 superTriNode.children [i] = new SuperTriNode();
             }
             if (!superTriNode.children[i].hitList.Contains(id))
             {
                 superTriNode.children[i].hitList.Add(id);
             }
             NextSuperTriNode(superTriNode.children [i], triNode.children [i], id);
         }
     }
 }
Пример #3
0
        public bool IsSubString(string s)
        {
            string  realS   = s.ToLower();
            TriNode curNode = root;

            for (int i = 0; i < realS.Length; i++)
            {
                int c = realS[i] - 'a';
                if ((c < 0) || (c >= 26))
                {
                    continue;
                }
                if (curNode.children[c] == null)
                {
                    return(false);
                }
                curNode = curNode.children[c];
            }
            return(true);
        }
Пример #4
0
        public int CountOccurrences(string s)
        {
            string  realS   = s.ToLower();
            TriNode curNode = root;

            for (int i = 0; i < realS.Length; i++)
            {
                int c = realS[i] - 'a';
                if ((c < 0) || (c >= 26))
                {
                    continue;
                }
                if (curNode.children[c] == null)
                {
                    return(0);
                }
                curNode = curNode.children[c];
            }
            return(curNode.hitCount);
        }
Пример #5
0
 public TriNode(string [] s, ref int pos)
 {
     if (pos >= s.Length)
     {
         return;
     }
     hitCount = int.Parse(s [pos]);
     pos++;
     children = new TriNode [26];
     for (int i = 0; i < 26; i++)
     {
         if (s [pos] != "")
         {
             children [i] = new TriNode(s, ref pos);
         }
         else
         {
             children [i] = null;
             pos++;
         }
     }
 }
Пример #6
0
        public void AddString(string s)
        {
            string  realS   = s.ToLower();
            TriNode curNode = root;

            for (int i = 0; i < realS.Length; i++)
            {
                int c = realS[i] - 'a';
                if ((c < 0) || (c >= 26))
                {
                    continue;
                }
                if (curNode.children[c] == null)
                {
                    curNode.children[c] = new TriNode();
                }
                curNode = curNode.children[c];
            }
            if (curNode != root)
            {
                curNode.hitCount++;
            }
        }
Пример #7
0
        public Tri(string s)
        {
            int pos = 0;

            root = new TriNode(Decompress(s).Split(','), ref pos);
        }
Пример #8
0
 public Tri()
 {
     root = new TriNode();
 }