当前位置: 首页 > news >正文

php网站开发实训总结画质优化app下载

php网站开发实训总结,画质优化app下载,班级网页设计模板html代码,wordpress主题检测Aho-Corasick算法简称AC算法,也称为AC自动机(Aho-Corasick)算法,1975年产生于贝尔实验室(The Bell Labs),是一种用于解决多模式字符串匹配的经典算法之一。 the Bell Lab 本文的运行效果: AC算法以模式树…

Aho-Corasick算法简称AC算法,也称为AC自动机(Aho-Corasick)算法,1975年产生于贝尔实验室The Bell Labs,是一种用于解决多模式字符串匹配的经典算法之一。

the Bell Lab 

本文的运行效果:

AC算法以模式树(字典树)Trie、广度优先策略和KMP模式匹配算法为核心内容。

using System;
using System.Collections;
using System.Collections.Generic;

namespace Legalsoft.Truffer.Algorithm
{
    /// <summary>
    /// Aho_Corasick 算法
    /// </summary>
    public static partial class PatternSearch
    {
        private static int MAXS = 512;
        private static int MAXC = 26;

        private static int[] outt = new int[MAXS];

        private static int[] f = new int[MAXS];

        private static int[,] g = new int[MAXS, MAXC];

        private static int buildMatchingMachine(string[] arr, int k)
        {
            for (int i = 0; i < outt.Length; i++)
            {
                outt[i] = 0;
            }

            for (int i = 0; i < MAXS; i++)
            {
                for (int j = 0; j < MAXC; j++)
                {
                    g[i, j] = -1;
                }
            }

            int states = 1;
            for (int i = 0; i < k; ++i)
            {
                string word = arr[i];
                int currentState = 0;

                for (int j = 0; j < word.Length; ++j)
                {
                    int ch = word[j] - 'A';
                    if (g[currentState, ch] == -1)
                    {
                        g[currentState, ch] = states++;
                    }
                    currentState = g[currentState, ch];
                }

                outt[currentState] |= (1 << i);
            }

            for (int ch = 0; ch < MAXC; ++ch)
            {
                if (g[0, ch] == -1)
                {
                    g[0, ch] = 0;
                }
            }

            for (int i = 0; i < MAXC; i++)
            {
                f[i] = 0;
            }

            Queue<int> q = new Queue<int>();
            for (int ch = 0; ch < MAXC; ++ch)
            {
                if (g[0, ch] != 0)
                {
                    f[g[0, ch]] = 0;
                    q.Enqueue(g[0, ch]);
                }
            }

            while (q.Count != 0)
            {
                int state = q.Peek();
                q.Dequeue();

                for (int ch = 0; ch < MAXC; ++ch)
                {
                    if (g[state, ch] != -1)
                    {
                        int failure = f[state];
                        while (g[failure, ch] == -1)
                        {
                            failure = f[failure];
                        }

                        failure = g[failure, ch];
                        f[g[state, ch]] = failure;

                        outt[g[state, ch]] |= outt[failure];

                        q.Enqueue(g[state, ch]);
                    }
                }
            }
            return states;
        }

        private static int findNextState(int currentState, char nextInput)
        {
            int answer = currentState;
            int ch = nextInput - 'A';

            while (g[answer, ch] == -1)
            {
                answer = f[answer];
            }
            return g[answer, ch];
        }

        public static List<int> Aho_Corasick_Search(string text, string pattern, int k = 1)
        {
            List<int> matchs = new List<int>();

            string[] arr = new string[1] { pattern };
            buildMatchingMachine(arr, k);

            int currentState = 0;

            for (int i = 0; i < text.Length; ++i)
            {
                currentState = findNextState(currentState, text[i]);

                if (outt[currentState] == 0)
                {
                    continue;
                }

                for (int j = 0; j < k; ++j)
                {
                    if ((outt[currentState] & (1 << j)) > 0)
                    {
                        matchs.Add((i - arr[j].Length + 1));
                    }
                }
            }

            return matchs;
        }
    }
}

POWER BY TRUFFER.CN

using System;
using System.Collections;
using System.Collections.Generic;namespace Legalsoft.Truffer.Algorithm
{/// <summary>/// Aho_Corasick 算法/// </summary>public static partial class PatternSearch{private static int MAXS = 512;private static int MAXC = 26;private static int[] outt = new int[MAXS];private static int[] f = new int[MAXS];private static int[,] g = new int[MAXS, MAXC];private static int buildMatchingMachine(string[] arr, int k){for (int i = 0; i < outt.Length; i++){outt[i] = 0;}for (int i = 0; i < MAXS; i++){for (int j = 0; j < MAXC; j++){g[i, j] = -1;}}int states = 1;for (int i = 0; i < k; ++i){string word = arr[i];int currentState = 0;for (int j = 0; j < word.Length; ++j){int ch = word[j] - 'A';if (g[currentState, ch] == -1){g[currentState, ch] = states++;}currentState = g[currentState, ch];}outt[currentState] |= (1 << i);}for (int ch = 0; ch < MAXC; ++ch){if (g[0, ch] == -1){g[0, ch] = 0;}}for (int i = 0; i < MAXC; i++){f[i] = 0;}Queue<int> q = new Queue<int>();for (int ch = 0; ch < MAXC; ++ch){if (g[0, ch] != 0){f[g[0, ch]] = 0;q.Enqueue(g[0, ch]);}}while (q.Count != 0){int state = q.Peek();q.Dequeue();for (int ch = 0; ch < MAXC; ++ch){if (g[state, ch] != -1){int failure = f[state];while (g[failure, ch] == -1){failure = f[failure];}failure = g[failure, ch];f[g[state, ch]] = failure;outt[g[state, ch]] |= outt[failure];q.Enqueue(g[state, ch]);}}}return states;}private static int findNextState(int currentState, char nextInput){int answer = currentState;int ch = nextInput - 'A';while (g[answer, ch] == -1){answer = f[answer];}return g[answer, ch];}public static List<int> Aho_Corasick_Search(string text, string pattern, int k = 1){List<int> matchs = new List<int>();string[] arr = new string[1] { pattern };buildMatchingMachine(arr, k);int currentState = 0;for (int i = 0; i < text.Length; ++i){currentState = findNextState(currentState, text[i]);if (outt[currentState] == 0){continue;}for (int j = 0; j < k; ++j){if ((outt[currentState] & (1 << j)) > 0){matchs.Add((i - arr[j].Length + 1));}}}return matchs;}}
}

http://www.mnyf.cn/news/15510.html

相关文章:

  • 四川省住房和城乡建设厅官网站网新冠疫情最新情况
  • 有什么做家常菜的网站上海有实力的seo推广咨询
  • 上海有名的猎头公司网站seo链接购买
  • 做网站去什么公司浏览器谷歌手机版下载
  • 做dj选歌是哪个网站优化营商环境的措施建议
  • 备案期间的网站打开建站之星官方网站
  • python在线网站seo推广的方法
  • ssm框架做音乐网站网络整合营销4i原则是指
  • 邯郸网站设计培训网络软文范例
  • 建设网站群的指导思想app开发制作
  • 地方网站做相亲赢利点在哪网络推广渠道排名
  • .net 网站 调试58精准推广点击器
  • 深圳整装装修公司排名seo优化技巧
  • 文字控图片在线制作佛山百度提升优化
  • wordpress网站如何播放视频常州百度搜索优化
  • 网站备案新增域名东营seo
  • 成都帮忙做网站的童鞋批发商百度首页网站推广多少钱一年
  • 湖南微网站开发软文推广例子
  • 陕西新闻最新消息今天石家庄网站seo外包
  • c++手机编程软件网络seo招聘
  • 网站建设网易搜狗竞价
  • 湖南建设厅官方网站网站免费进入窗口软件有哪些
  • 查询网站whois青岛seo
  • 网站搭建心得体会swot分析
  • 兴化网站开发网站的seo 如何优化
  • 按商品种类可将b2c电子商务网站分为最近时政热点新闻
  • 肥东网站制作域名seo站长工具
  • 网站如何做攻击防护株洲企业seo优化
  • 网络服务平台标书鹤壁网站seo
  • 做网站图结构最近最新新闻