Ejemplo n.º 1
0
 private static void Insert(PYNode node, string text, int idx)
 {
     if (idx == text.Length - 1)      // 准备添加叶节点
     {
         node.children[text[idx]] = new PYNode()
         {
             IsLeaf = true
         };
     }
     else                            //
     {
         PYNode subnode;
         if (!node.children.TryGetValue(text[idx], out subnode))
         {
             subnode = new PYNode()
             {
                 children = new Dictionary <char, PYNode>()
             };
             node.children[text[idx]] = subnode;
         }
         if (subnode.children == null)
         {
             subnode.children = new Dictionary <char, PYNode>();
         }
         Insert(subnode, text, idx + 1);
     }
 }
Ejemplo n.º 2
0
        private static void ExactMatch(string text, int idx, PYNode node, PYResultNode res_node)
        {
            if (idx == text.Length)
            {
                return;                          // match finished
            }
            var    c = text[idx++];
            PYNode subnode;

            if (!node.children.TryGetValue(c, out subnode))
            {
                return;                          // match failed
            }
            if (subnode.IsLeaf)
            {
                res_node.children[idx] = new PYResultNode(idx)
                {
                    parent = res_node
                }
            }
            ;
            if (subnode.children == null)
            {
                return;                         // match finished
            }
            ExactMatch(text, idx, subnode, res_node);
        }