HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Efficiently extendable hash function?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
extendableefficientlyfunctionhash

Problem

I'm wondering whether there exist any good hash functions with the following property: Assume that $x$ is some string over some alphabet $A$, then given $H(x)$ we can compute in $O(1)$ time both $H(ax)$ and $H(xa)$ for any letter $a\in A$. In practice one can assume that $A$ is for example the set of $8$-bit integers.

In other words, a hash function for strings that can quickly be extended in both directions. I'm only interested in hash functions that actually distribute the data well and which are very fast to compute in practice.

Solution

Use any rolling hash, e.g., the Rabin-karp rolling hash, Buzhash, or CRC. See also the following resources:

-
additive hash function

-
Can ropes (AVL trees) be interned?

-
https://crypto.stackexchange.com/q/17935/351

-
https://crypto.stackexchange.com/q/11420/351

-
the answers to https://crypto.stackexchange.com/q/1558/351

Context

StackExchange Computer Science Q#118265, answer score: 2

Revisions (0)

No revisions yet.