Fast implementation of rolling hash in PHP -


i've implemented adler32 rolling hash in php, because ord slow (about 1mb per second on dev machine) integer values of chanters in string, solution unworkable 100mb+ files.

php's mhash function can quick calculation adler32 (120mb per second on dev machine). mhash doesn’t seem support rolling nature of adler32, have calculate whole new adler32 rolling window moves rather recalculate hash 2 bytes have changed.

i'm not tied adler32 algorithm, need fast rolling hash in php.

call low 2 bytes of adler-32 a , high 2 bytes b, adler-32 of sequence {x1, x2, ..., xn}.

to adler-32 of {x2, ..., xn}, subtract x1 a, modulo 65521, , subtract n * x1 + 1 b, again modulo 65521.

note if window size n happens multiple of 65521, can subtract 1 b (modulo 65521). might window size pick, if can. note if n larger 65521, can multiply x1 (n modulo 65521) instead. if n constant, can modulo operation ahead of time.

(note % operator in c , php not modulo operation, rather remainder operation. need take care negative numbers.)


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -