Hashing n-grams by cyclic polynomials - java implementation

白昼怎懂夜的黑 提交于 2019-12-06 12:10:33

问题


I'm solving some problem that involves Rabin–Karp string search algorithm. This algorithm requires rolling hash to be faster then naive search. This article describes how to implement rolling hash. I implemented "Rabin-Karp rolling hash" without problems and found few implementations implementations, but article also mentions computational complexity and that hashing n-grams by cyclic polynomials is prefered. It links to BuzHash implementation of such technique but I wonder how it can be used to build n-gram hash on top of it. I want to have something like this or

CPHash cp = new CPHash("efghijk");
cp.shiftRight('l') // now we got hash of "fghijki"
cp.shiftLeft('d') // "defghi"

for java.

For people who will encounter problems related with string search (like me) there are some articles that I found usefull: 1, 2, 3


回答1:


I recently published an Apache licensed Java library which implements several rolling hash functions including Cyclic and Rabin-Karp:

http://code.google.com/p/rollinghashjava/

https://github.com/lemire/rollinghashjava



来源:https://stackoverflow.com/questions/5086899/hashing-n-grams-by-cyclic-polynomials-java-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!