排序字符串的前缀压缩算法,结合lucene

来源:互联网 发布:淘宝让你提供质检报告 编辑:程序博客网 时间:2024/05/20 06:36

排序的字符串如下:

ab

abcd

abcde

我还是举lucene中的例子吧,lucene存储如下,顺便也就用到了lucene中的vint数据类型

(vint)0 ab

(vint)2  cd

(vint)4 e


那么存储的过程中就必然会涉及到子串的匹配,最大子串匹配的算法很多。lucene中的实现算法没有看,不过我认为因为是排序的字符序列,采用简单匹配算法就可以了,因为算法的世界运行效率也是很高的。


没有考虑容错性:

<span style="font-size:18px;">public static void test(String text,String sub) {int textLength = text.length();for(int i = 0;i<textLength;i++) {int j = 0;for(;j<sub.length();j++) {char textChar = text.charAt(i+j);//母串对应的字符char subChar = sub.charAt(j);//子串对应的字符if(textChar != subChar) {break;} }if(j == sub.length()) {//说明匹配成功System.out.println(i);break;}}}</span>


0 0
原创粉丝点击