Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cython wrapper of the rollinghashcpp C++ repo

NotificationsYou must be signed in to change notification settings

jlanga/pyrollinghash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

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

How to compute hashes:

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

Available hashers

Adler32

>>>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

CyclicHash

>>>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

GeneralHash

>>>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

ThreeWiseHash

>>>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

RabinKarpHash

>>>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

References

About

Cython wrapper of the rollinghashcpp C++ repo

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp