首页 文章 精选 留言 我的

精选列表

搜索[国密算法],共10000篇文章
优秀的个人博客,低调大师

BMH子串查找算法(PHP实现)

代码 interface StringSearchable { public function search($substring, $buffer); } class BoyerMooreStringSearch implements StringSearchable { public $substring = null; public $buffer = ''; public $jumpTable = array(); protected $results = array(); public function __construct() { } public function __destruct() { } public function search($substring, $buffer) { $this->results = array(); $this->substring = $substring; $this->buffer = $buffer; $this->deriveJumpTable(); $substringLen = strlen($this->substring); $currentCharIndex = $substringLen - 1; $bufferLen = strlen($this->buffer); while ($currentCharIndex < $bufferLen) { for ($i = $substringLen - 1; $i >= 0; $i--) { if ($this->buffer[$currentCharIndex - $substringLen + $i + 1] == $this->substring[$i]) { if ($i == 0) { $this->results[] = $currentCharIndex - $substringLen; $currentCharIndex += $this->getJumpLength($this->buffer[$currentCharIndex]); } else { continue; } } else { $currentCharIndex += $this->getJumpLength($this->buffer[$currentCharIndex]); break; } } } return (sizeof($this->results) > 0); } protected function deriveJumpTable() { $maxJump = strlen($this->substring); for ($i = strlen($this->substring) - 2; $i >= 0; $i--) { if (!array_key_exists($this->substring[$i], $this->jumpTable)) { $this->jumpTable[$this->substring[$i]]] = $maxJump - $i -1; } } } public function getJumpTable() { return $this->jumpTable; } public function getResults() { return $this->results; } public function getResultsCount() { return sizeof($this->results); } public function getJumpLength($charIndex) { if (array_key_exists($charIndex, $this->jumpTable)) { return $this->jumpTable[$charIndex]; } else { return strlen($this->substring); } } } function Main() { $poem = <<<POEM you son of bitch god damn it hey,god love me POEM; $bm = new BoyerMooreStringSearch(); $bm->search('god', $poem); $count = $bm->getResultsCount; echo $count; } 复制代码 本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2010/04/21/1717668.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

ES设置查询的相似度算法

similarity Elasticsearch allows you to configure a scoring algorithm orsimilarityper field. Thesimilaritysetting provides a simple way of choosing a similarity algorithm other than the defaultBM25, such asTF/IDF. Similarities are mostly useful fortextfields, but can also apply to other field types. Custom similarities can be configured by tuning the parameters of the built-in similarities. For more details about this expert options, see thesimilarity module. The only similarities which can be used out of the box, without any further configuration are: BM25 The Okapi BM25 algorithm. The algorithm used by default in Elasticsearch and Lucene. See Pluggable Similarity Algorithmsfor more information. classic The TF/IDF algorithm which used to be the default in Elasticsearch and Lucene. See Lucene’s Practical Scoring Functionfor more information. boolean A simple boolean similarity, which is used when full-text ranking is not needed and the score should only be based on whether the query terms match or not. Boolean similarity gives terms a score equal to their query boost. Thesimilaritycan be set on the field level when a field is first created, as follows: PUT my_index { "mappings": { "my_type": { "properties": { "default_field": { "type": "text" }, "classic_field": { "type": "text", "similarity": "classic" }, "boolean_sim_field": { "type": "text", "similarity": "boolean" } } } } } COPY AS CURL VIEW IN CONSOLE Thedefault_fielduses theBM25similarity. Theclassic_fielduses theclassicsimilarity (ie TF/IDF). Theboolean_sim_fielduses thebooleansimilarity. Default and Base Similarities By default, Elasticsearch will use whatever similarity is configured asdefault. However, the similarity functionsqueryNorm()andcoord()are not per-field. Consequently, for expert users wanting to change the implementation used for these two methods, while not changing thedefault, it is possible to configure a similarity with the namebase. This similarity will then be used for the two methods. You can change the default similarity for all fields in an index when it iscreated: PUT /my_index { "settings": { "index": { "similarity": { "default": { "type": "classic" } } } } } If you want to change the default similarity after creating the index you mustcloseyour index, send the follwing request andopenit again afterwards: PUT /my_index/_settings { "settings": { "index": { "similarity": { "default": { "type": "classic" } } } } } from:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/index-modules-similarity.html 本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/7451929.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Elasticsearch mapping文档相似性算法

Elasticsearch allows you to configure a scoring algorithm orsimilarityper field. Thesimilaritysetting provides a simple way of choosing a similarity algorithm other than the default TF/IDF, such asBM25. Similarities are mostly useful fortextfields, but can also apply to other field types. Custom similarities can be configured by tuning the parameters of the built-in similarities. For more details about this expert options, see thesimilarity module. The only similarities which can be used out of the box, without any further configuration are: BM25 The Okapi BM25 algorithm. The algorithm used by default in Elasticsearch and Lucene. See Pluggable Similarity Algorithmsfor more information. classic The TF/IDF algorithm which used to be the default in Elasticsearch and Lucene. See Lucene’s Practical Scoring Functionfor more information. Thesimilaritycan be set on the field level when a field is first created, as follows: PUT my_index { "mappings": { "my_type": { "properties": { "default_field": { "type": "text" }, "classic_field": { "type": "text", "similarity": "classic" } } } } } COPY AS CURL VIEW IN CONSOLE Thedefault_fielduses theBM25similarity. Theclassic_fielduses theclassicsimilarity (ie TF/IDF). 参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/similarity.html 本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6472719.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

妙趣横生的算法--顺序表

静态表 题目:创建一个静态的顺序表存放整数,大小为10,完成以下的操作。 (1)输入6个整数,打印出顺序表的内容,并显示表中的剩余空间个数。 (2)在顺序表中的第3个位置插入0,打印出顺序表中的内容,并显示表中剩余的空间个数。 (3)再试图插入表中第11个位置整数0,程序提示超出范围。 (4)删除表中第6个元素,打印出顺序表中的内容,并表示表中剩余的空间个数。 #include "stdio.h" #define MaxSize 10 /*静态顺序表的各种操作*/ /** 向顺序表中插入元素 */ /** 参数Sqlist:表首地址 */ /** 参数*len: 表的长度 */ /** 参数i: 插入元素的位置 */ /** 参数x:待插入的元素值 */ void insertElem(int Sqlist[],int *len,int i,int x) { int t; if(*len==MaxSize || i<1 || i>*len+1) { printf("This insert is illegal\n"); return; } /*非法插入*/ for(t=*len-1;t>=i-1;t--) Sqlist[t+1]=Sqlist[t];//插入位置之后的元素往后面推 Sqlist[i-1]=x; /*插入元素*/ *len=*len+1; /*表长加1*/ } /** 向顺序表中删除元素 */ /** 参数Sqlist:表首地址 */ /** 参数*len: 表的长度 */ /** 参数i: 插入元素的位置 */ void DelElem(int Sqlist[],int *len,int i) { int j; if(i<1 || i>*len) { printf("This insert is illegal"); return; } /*非法插入*/ for(j=i;j<=*len-1;j++) Sqlist[j-1]=Sqlist[j]; //将删除元素后面的元素往前移动 *len=*len-1; /*表长减1*/ } /**测试函数*/ main() { /*按照题目要求进行测试*/ int Sqlist[MaxSize]; /*定义一个静态顺序表*/ int len; int i; for(i=0;i<6;i++) scanf("%d",&Sqlist[i]); /*从键盘输入6个整数*/ len=6; for(i=0;i<len;i++) printf("%d ",Sqlist[i]); /*输出顺序表中的6个整数*/ printf("\nThe spare length is %d\n",MaxSize - len); /*显示表中的剩余空间*/ insertElem(Sqlist,&len,3,0); /*在表中第3位置插入整数0*/ for(i=0;i<len;i++) printf("%d ",Sqlist[i]); /*输出顺序表中的所有元素*/ printf("\nThe spare length is %d\n",MaxSize - len); /*显示表中的剩余空间*/ insertElem(Sqlist,&len,11,0); /*在表中第11位置插入整数0*/ DelElem(Sqlist,&len,6); /*删除顺序表中的第6个元素*/ for(i=0;i<len;i++) printf("%d ",Sqlist[i]); /*输出顺序表中的所有元素*/ printf("\nThe spare length is %d\n",MaxSize - len); /*显示表中的剩余空间*/ } 动态表 编写一个程序,动态的创建一个顺序表。要求:顺序表初始长度为10,向顺序表中输入15个整数,并打印出来;再检出顺序表中的第5个元素,打印出来删除后的结果。 #include "stdio.h" #include "conio.h" #include "stdlib.h" #define MaxSize 10 typedef int ElemType ; /*将int定义为ElemType*/ typedef struct{ int *elem;//元素 int length;//长度 int listsize; //内存 } Sqlist; /** 初始化一个顺序表 */ /** 参数L:Sqlist类型的指针 */ void initSqlist(Sqlist *L){ L->elem=(int *)malloc(MaxSize*sizeof(ElemType)); if(!L->elem) exit(0);//没有创建成功 L->length=0; L->listsize= MaxSize; } /** 向顺序表中插入元素 */ /** 参数L:Sqlist类型的指针 */ /** 参数i:插入元素的位置 */ /** 参数item:插入的元素 */ void InsertElem(Sqlist *L,int i,ElemType item){ /*向顺序表L中第i个位置上插入元素item*/ ElemType *base,* insertPtr,*p; if(i<1||i>L->length+1) exit(0);//防止过量插入 if(L->length>=L->listsize) { base=(ElemType*)realloc(L->elem,(L->listsize+10)*sizeof(ElemType));//重新分配内存空间 L->elem=base;//传首地址 L->listsize=L->listsize+100; } insertPtr=&(L->elem[i-1]);//将要删除的地址赋值 for(p=&(L->elem[L->length-1]);p>= insertPtr;p--)//以地址来判断 *(p+1)=*p;//往后面移 * insertPtr=item; L->length++;//长度增加 } /** 从顺序表中删除元素 */ /** 参数L:Sqlist类型的指针 */ /** 参数i:删除元素的位置 */ void DelElem(Sqlist *L,int i) { /*从顺序表L中删除第i个元素*/ ElemType *delItem, *q; if(i<1||i>L->length) exit(0);//防止没有那个位置的删除 delItem=&(L->elem[i-1]);//穿要删除的地址 q=L->elem+L->length-1 ;//这里的-1没有理解非常深刻,后面是<=,那么这里的-1应该是可有可无的 for(++delItem; delItem<=q;++ delItem)*( delItem-1)=* delItem;//往前面移 L->length--;//长度减小 } /** 测试函数 */ main() { Sqlist l; int i; initSqlist(&l); /*初始化一个顺序表*/ for(i=0;i<15;i++) InsertElem(&l,i+1,i+1); /*向顺序表中插入1……15*/ printf("\nThe content of the list is\n"); for(i=0;i<l.length;i++) printf("%d ",l.elem[i]);/*打印出顺序表中的内容*/ DelElem(&l,5); /*删除第5个元素,即5*/ printf("\nDelete the fifth element\n"); for(i=0;i<l.length;i++) /*打印出删除后的结果*/ printf("%d ",l.elem[i]); getche(); } 顺序表个人敲了一遍代码之后能够理解了,但是还是有些细节不够明白哈。希望大概能看懂,上面也写的有注释。 本文转自我爱物联网博客园博客,原文链接:http://www.cnblogs.com/yydcdut/p/3663792.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册