Exemplo n.º 1
0
        public bool Match(char[] sen, int offset, int len)
        {
            TreeNode node = head;

            for (int i = 0; i < len; i++)
            {
                node = node.SubNode(sen[offset + i]);
                if (node == null)
                {
                    return(false);
                }
            }
            return(node.IsAlsoLeaf);
        }
Exemplo n.º 2
0
        public List <int> MaxMatch(List <int> tailLens, char[] sen, int offset)
        {
            TreeNode node = head;

            for (int i = offset; i < sen.Length; i++)
            {
                node = node.SubNode(sen[i]);
                if (node == null)
                {
                    break;
                }
                if (node.IsAlsoLeaf)
                {
                    tailLens.Add(i - offset + 1);
                }
            }
            return(tailLens);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 返回匹配最长词的长度,没有找到返回0.
        /// </summary>
        /// <param name="sen"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public int MaxMatch(char[] sen, int offset)
        {
            int      idx  = offset - 1;
            TreeNode node = head;

            for (int i = offset; i < sen.Length; i++)
            {
                node = node.SubNode(sen[i]);
                if (node == null)
                {
                    break;
                }
                if (node.IsAlsoLeaf)
                {
                    idx = i;
                }
            }
            return(idx - offset + 1);
        }
Exemplo n.º 4
0
        public void Add(char[] w)
        {
            if (w.Length < 1)
            {
                return;
            }
            TreeNode p = head;

            for (int i = 0; i < w.Length; i++)
            {
                TreeNode n = p.SubNode(w[i]);
                if (n == null)
                {
                    n = new TreeNode(w[i]);
                    p.Born(w[i], n);
                }
                p = n;
            }
            p.IsAlsoLeaf = true;
        }