- Notifications
You must be signed in to change notification settings - Fork0
jlanga/pyrollinghash
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A poor attempt to wrap in Cython therollinghashcpp library.
Note: Work in progress
Note: all hashes return 64-bit integers that later are converted to what you want
frompyrollinghash.cyclichashimportCyclicHash# Initialize elementsread="CACTACACTAC"n=len(read)k=5ch=CyclicHash(k,64,1,1)# Hash the initial 5-gram with Hasher.eat()foriinrange(k):ch.eat(ord(read[i]))print(read[0:k],ch.hashvalue)# Hash the remainder 5-grams with Hasher.update(out, in)foriinrange(k,n):ngram=read[i-k+1:i+1]ch.update(ord(read[i-k]),ord(read[i]))print(ngram,ch.hashvalue)
CACTA 5677400150441078107ACTAC 18253274918174107859CTACA 13733297960976284091TACAC 2154973599019565330ACACT 9619269492940898979CACTA 5677400150441078107 # The pattern repeats againACTAC 18253274918174107859>>>frompyrollinghashimportAdler32>>>hasher=Adler32(3)# Set window size to 3>>>hasher.hashvalue# The hasher is reset0>>>foriinrange(3):# Hash 0, 1 ,2hasher.eat(i)>>>hasher.hashvalue458756>>>hasher.update(0,3)# Remove 0, add 3>>>hasher.hashvalue851975>>>hasher.reset()>>>hasher.hashvalue0>>>foriinrange(1,4):# Same result?hasher.eat(i)>>>hasher.hashvalue851975
>>>frompyrollinghashimportCyclicHash>>>hasher=CyclicHash(3,64,1,1)>>>hasher.hashvalue0>>>foriinrange(3):# Hash 0, 1 ,2hasher.eat(i)>>>hasher.hashvalue17145202471131414222>>>hasher.update(0,3)# Remove 0, add 3>>>hasher.hashvalue7164181364666550526>>>hasher.reset()>>>hasher.hashvalue0>>>foriinrange(1,4):# Check that we will get the same hash with 1-3hasher.eat(i)>>>hasher.hashvalue7164181364666550526
>>>frompyrollinghashimportGeneralHash>>>hasher=GeneralHash(3,19)>>>hasher.hashvalue0>>>foriinrange(3):# Hash 0, 1 ,2hasher.eat(i)>>>hasher.hashvalue434959>>>hasher.update(0,3)# Remove 0, add 3>>>hasher.hashvalue7153>>>hasher.reset()>>>hasher.hashvalue0>>>foriinrange(1,4):# Check that we will get the same hash with 1-3hasher.eat(i)>>>hasher.hashvalue7153
>>>frompyrollinghashimportThreeWiseHash>>>hasher=ThreeWiseHash(3,64)>>>hasher.hashvalue# Not 0. Doesn't matter.140542657667792>>>foriinrange(3):# Hash 0, 1 ,2hasher.eat(i)>>>hasher.hashvalue9309819415051597224>>>hasher.update(0,3)# Remove 0, add 3>>>hasher.hashvalue4181938747326092072>>>hasher.reset()>>>hasher.hashvalue0>>>foriinrange(1,4):# Check that we will get the same hash with 1-3hasher.eat(i)>>>hasher.hashvalue4181938747326092072
>>>frompyrollinghashimportKarpRabinHash>>>hasher=KarpRabinHash(3,64)>>>hasher.hashvalue0>>>foriinrange(3):# Hash 0, 1 ,2hasher.eat(i)>>>hasher.hashvalue5277449530275385433>>>hasher.update(0,3)# Remove 0, add 3>>>hasher.hashvalue13252376563992438057>>>hasher.reset()>>>hasher.hashvalue0>>>foriinrange(1,4):# Check that we will get the same hash with 1-3hasher.eat(i)>>>hasher.hashvalue13252376563992438057
About
Cython wrapper of the rollinghashcpp C++ repo
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.