Universal hashing
In mathematics and computing, universal hashing (in a randomized algorithm or data structure) refers to selecting a hash function at random from a family of hash functions with a certain mathematical property (see definition below). This guarantees a low number of collisions in expectation, even if the data is chosen by an adversary. Many universal families are known (for hashing integers, vectors, strings), and their evaluation is often very efficient. Universal hashing has numerous uses in computer science, for example in implementations of hash tables, randomized algorithms, and cryptography.
Introduction
Assume we want to map keys from some universe [math]\displaystyle{ U }[/math] into [math]\displaystyle{ m }[/math] bins (labelled [math]\displaystyle{ [m] = \{0, \dots, m1\} }[/math]). The algorithm will have to handle some data set [math]\displaystyle{ S \subseteq U }[/math] of [math]\displaystyle{ S=n }[/math] keys, which is not known in advance. Usually, the goal of hashing is to obtain a low number of collisions (keys from [math]\displaystyle{ S }[/math] that land in the same bin). A deterministic hash function cannot offer any guarantee in an adversarial setting if [math]\displaystyle{ U \gt m \cdot n }[/math], since the adversary may choose [math]\displaystyle{ S }[/math] to be precisely the preimage of a bin. This means that all data keys land in the same bin, making hashing useless. Furthermore, a deterministic hash function does not allow for rehashing: sometimes the input data turns out to be bad for the hash function (e.g. there are too many collisions), so one would like to change the hash function.
The solution to these problems is to pick a function randomly from a family of hash functions. A family of functions [math]\displaystyle{ H = \{ h : U \to [m] \} }[/math] is called a universal family if, [math]\displaystyle{ \forall x, y \in U, ~ x\ne y: ~~ \{h\in H: h(x) = h(y)\}\le \frac{H}{m} }[/math].
In other words, any two different keys of the universe collide with probability at most [math]\displaystyle{ 1/m }[/math] when the hash function [math]\displaystyle{ h }[/math] is drawn uniformly at random from [math]\displaystyle{ H }[/math]. This is exactly the probability of collision we would expect if the hash function assigned truly random hash codes to every key.
Sometimes, the definition is relaxed by a constant factor, only requiring collision probability [math]\displaystyle{ O(1/m) }[/math] rather than [math]\displaystyle{ \leq 1/m }[/math]. This concept was introduced by Carter and Wegman^{[1]} in 1977, and has found numerous applications in computer science (see, for example^{[2]}).
If we have an upper bound of [math]\displaystyle{ \epsilon\lt 1 }[/math] on the collision probability, we say that we have [math]\displaystyle{ \epsilon }[/math]almost universality. So for example, a universal family has [math]\displaystyle{ 1/m }[/math]almost universality.
Many, but not all, universal families have the following stronger uniform difference property:
 [math]\displaystyle{ \forall x,y\in U, ~ x\ne y }[/math], when [math]\displaystyle{ h }[/math] is drawn randomly from the family [math]\displaystyle{ H }[/math], the difference [math]\displaystyle{ h(x)h(y) ~\bmod~ m }[/math] is uniformly distributed in [math]\displaystyle{ [m] }[/math].
Note that the definition of universality is only concerned with whether [math]\displaystyle{ h(x)h(y)=0 }[/math], which counts collisions. The uniform difference property is stronger.
(Similarly, a universal family can be XOR universal if [math]\displaystyle{ \forall x,y\in U, ~ x\ne y }[/math], the value [math]\displaystyle{ h(x) \oplus h(y) ~\bmod~ m }[/math] is uniformly distributed in [math]\displaystyle{ [m] }[/math] where [math]\displaystyle{ \oplus }[/math] is the bitwise exclusive or operation. This is only possible if [math]\displaystyle{ m }[/math] is a power of two.)
An even stronger condition is pairwise independence: we have this property when [math]\displaystyle{ \forall x,y\in U, ~ x\ne y }[/math] we have the probability that [math]\displaystyle{ x,y }[/math] will hash to any pair of hash values [math]\displaystyle{ z_1, z_2 }[/math] is as if they were perfectly random: [math]\displaystyle{ P(h(x)=z_1 \land h(y)=z_2)= 1/m^2 }[/math]. Pairwise independence is sometimes called strong universality.
Another property is uniformity. We say that a family is uniform if all hash values are equally likely: [math]\displaystyle{ P(h(x)=z)=1/m }[/math] for any hash value [math]\displaystyle{ z }[/math]. Universality does not imply uniformity. However, strong universality does imply uniformity.
Given a family with the uniform distance property, one can produce a pairwise independent or strongly universal hash family by adding a uniformly distributed random constant with values in [math]\displaystyle{ [m] }[/math] to the hash functions. (Similarly, if [math]\displaystyle{ m }[/math] is a power of two, we can achieve pairwise independence from an XOR universal hash family by doing an exclusive or with a uniformly distributed random constant.) Since a shift by a constant is sometimes irrelevant in applications (e.g. hash tables), a careful distinction between the uniform distance property and pairwise independent is sometimes not made.^{[3]}
For some applications (such as hash tables), it is important for the least significant bits of the hash values to be also universal. When a family is strongly universal, this is guaranteed: if [math]\displaystyle{ H }[/math] is a strongly universal family with [math]\displaystyle{ m=2^L }[/math], then the family made of the functions [math]\displaystyle{ h \bmod{2^{L'}} }[/math] for all [math]\displaystyle{ h \in H }[/math] is also strongly universal for [math]\displaystyle{ L'\leq L }[/math]. Unfortunately, the same is not true of (merely) universal families. For example, the family made of the identity function [math]\displaystyle{ h(x)=x }[/math] is clearly universal, but the family made of the function [math]\displaystyle{ h(x)=x \bmod{2^{L'}} }[/math] fails to be universal.
UMAC and Poly1305AES and several other message authentication code algorithms are based on universal hashing.^{[4]}^{[5]} In such applications, the software chooses a new hash function for every message, based on a unique nonce for that message.
Several hash table implementations are based on universal hashing. In such applications, typically the software chooses a new hash function only after it notices that "too many" keys have collided; until then, the same hash function continues to be used over and over. (Some collision resolution schemes, such as dynamic perfect hashing, pick a new hash function every time there is a collision. Other collision resolution schemes, such as cuckoo hashing and 2choice hashing, allow a number of collisions before picking a new hash function). A survey of fastest known universal and strongly universal hash functions for integers, vectors, and strings is found in.^{[6]}
Mathematical guarantees
For any fixed set [math]\displaystyle{ S }[/math] of [math]\displaystyle{ n }[/math] keys, using a universal family guarantees the following properties.
 For any fixed [math]\displaystyle{ x }[/math] in [math]\displaystyle{ S }[/math], the expected number of keys in the bin [math]\displaystyle{ h(x) }[/math] is [math]\displaystyle{ n/m }[/math]. When implementing hash tables by chaining, this number is proportional to the expected running time of an operation involving the key [math]\displaystyle{ x }[/math] (for example a query, insertion or deletion).
 The expected number of pairs of keys [math]\displaystyle{ x,y }[/math] in [math]\displaystyle{ S }[/math] with [math]\displaystyle{ x\ne y }[/math] that collide ([math]\displaystyle{ h(x) = h(y) }[/math]) is bounded above by [math]\displaystyle{ n(n1)/2m }[/math], which is of order [math]\displaystyle{ O(n^2/m) }[/math]. When the number of bins, [math]\displaystyle{ m }[/math] is chosen linear in [math]\displaystyle{ n }[/math] (i.e., is determined by a function in [math]\displaystyle{ \Omega(n) }[/math]), the expected number of collisions is [math]\displaystyle{ O(n) }[/math]. When hashing into [math]\displaystyle{ n^2 }[/math] bins, there are no collisions at all with probability at least a half.
 The expected number of keys in bins with at least [math]\displaystyle{ t }[/math] keys in them is bounded above by [math]\displaystyle{ 2n/(t2(n/m)+1) }[/math].^{[7]} Thus, if the capacity of each bin is capped to three times the average size ([math]\displaystyle{ t = 3n/m }[/math]), the total number of keys in overflowing bins is at most [math]\displaystyle{ O(m) }[/math]. This only holds with a hash family whose collision probability is bounded above by [math]\displaystyle{ 1/m }[/math]. If a weaker definition is used, bounding it by [math]\displaystyle{ O(1/m) }[/math], this result is no longer true.^{[7]}
As the above guarantees hold for any fixed set [math]\displaystyle{ S }[/math], they hold if the data set is chosen by an adversary. However, the adversary has to make this choice before (or independent of) the algorithm's random choice of a hash function. If the adversary can observe the random choice of the algorithm, randomness serves no purpose, and the situation is the same as deterministic hashing.
The second and third guarantee are typically used in conjunction with rehashing. For instance, a randomized algorithm may be prepared to handle some [math]\displaystyle{ O(n) }[/math] number of collisions. If it observes too many collisions, it chooses another random [math]\displaystyle{ h }[/math] from the family and repeats. Universality guarantees that the number of repetitions is a geometric random variable.
Constructions
Since any computer data can be represented as one or more machine words, one generally needs hash functions for three types of domains: machine words ("integers"); fixedlength vectors of machine words; and variablelength vectors ("strings").
Hashing integers
This section refers to the case of hashing integers that fit in machines words; thus, operations like multiplication, addition, division, etc. are cheap machinelevel instructions. Let the universe to be hashed be [math]\displaystyle{ \{0, \dots, U  1\} }[/math].
The original proposal of Carter and Wegman^{[1]} was to pick a prime [math]\displaystyle{ p \ge U }[/math] and define
 [math]\displaystyle{ h_{a,b}(x) = ((ax + b)~\bmod ~ p)~\bmod ~ m }[/math]
where [math]\displaystyle{ a,b }[/math] are randomly chosen integers modulo [math]\displaystyle{ p }[/math] with [math]\displaystyle{ a \neq 0 }[/math]. (This is a single iteration of a linear congruential generator.)
To see that [math]\displaystyle{ H = \{ h_{a,b} \} }[/math] is a universal family, note that [math]\displaystyle{ h(x) = h(y) }[/math] only holds when
 [math]\displaystyle{ ax+b \equiv ay + b + i\cdot m \pmod{p} }[/math]
for some integer [math]\displaystyle{ i }[/math] between [math]\displaystyle{ 0 }[/math] and [math]\displaystyle{ (p1)/m }[/math]. Since [math]\displaystyle{ p \ge U }[/math], if [math]\displaystyle{ x \neq y }[/math] their difference [math]\displaystyle{ xy }[/math] is nonzero and has an inverse modulo [math]\displaystyle{ p }[/math]. Solving for [math]\displaystyle{ a }[/math] yields
 [math]\displaystyle{ a \equiv i\cdot m \cdot (xy)^{1} \pmod{p} }[/math].
There are [math]\displaystyle{ p1 }[/math] possible choices for [math]\displaystyle{ a }[/math] (since [math]\displaystyle{ a=0 }[/math] is excluded) and, varying [math]\displaystyle{ i }[/math] in the allowed range, [math]\displaystyle{ \lfloor (p  1)/m \rfloor }[/math] possible nonzero values for the right hand side. Thus the collision probability is
 [math]\displaystyle{ \lfloor (p  1)/m \rfloor / (p1) \le ((p1)/m)/(p1) = 1/m }[/math].
Another way to see [math]\displaystyle{ H }[/math] is a universal family is via the notion of statistical distance. Write the difference [math]\displaystyle{ h(x)  h(y) }[/math] as
 [math]\displaystyle{ h(x)h(y) \equiv (a(xy)~ \bmod~ p) \pmod{m} }[/math].
Since [math]\displaystyle{ x  y }[/math] is nonzero and [math]\displaystyle{ a }[/math] is uniformly distributed in [math]\displaystyle{ \{1,\dots,p1\} }[/math], it follows that [math]\displaystyle{ a(xy) }[/math] modulo [math]\displaystyle{ p }[/math] is also uniformly distributed in [math]\displaystyle{ \{1,\dots,p1\} }[/math]. The distribution of [math]\displaystyle{ (h(x)h(y)) ~\bmod~ m }[/math] is thus almost uniform, up to a difference in probability of [math]\displaystyle{ \pm 1/p }[/math] between the samples. As a result, the statistical distance to a uniform family is [math]\displaystyle{ O(m/p) }[/math], which becomes negligible when [math]\displaystyle{ p \gg m }[/math].
The family of simpler hash functions
 [math]\displaystyle{ h_a(x) = (ax~\bmod~p)~\bmod~m }[/math]
is only approximately universal: [math]\displaystyle{ \Pr\{h_a(x) = h_a(y)\} \le 2/m }[/math] for all [math]\displaystyle{ x\neq y }[/math].^{[1]} Moreover, this analysis is nearly tight; Carter and Wegman ^{[1]} show that [math]\displaystyle{ \Pr\{h_a(1) = h_a(m+1)\} \ge 2/(m1) }[/math] whenever [math]\displaystyle{ (p1)~\bmod~ m = 1 }[/math].
Avoiding modular arithmetic
The state of the art for hashing integers is the multiplyshift scheme described by Dietzfelbinger et al. in 1997.^{[8]} By avoiding modular arithmetic, this method is much easier to implement and also runs significantly faster in practice (usually by at least a factor of four^{[9]}). The scheme assumes the number of bins is a power of two, [math]\displaystyle{ m=2^M }[/math]. Let [math]\displaystyle{ w }[/math] be the number of bits in a machine word. Then the hash functions are parametrised over odd positive integers [math]\displaystyle{ a \lt 2^w }[/math] (that fit in a word of [math]\displaystyle{ w }[/math] bits). To evaluate [math]\displaystyle{ h_{a}(x) }[/math], multiply [math]\displaystyle{ x }[/math] by [math]\displaystyle{ a }[/math] modulo [math]\displaystyle{ 2^w }[/math] and then keep the high order [math]\displaystyle{ M }[/math] bits as the hash code. In mathematical notation, this is
 [math]\displaystyle{ h_a(x) = (a\cdot x\,\, \bmod\, 2^w)\,\, \mathrm{div}\,\, 2^{wM} . }[/math]
This scheme does not satisfy the uniform difference property and is only [math]\displaystyle{ 2/m }[/math]almostuniversal; for any [math]\displaystyle{ x\neq y }[/math], [math]\displaystyle{ \Pr\{h_a(x) = h_a(y)\} \le 2/m }[/math].
To understand the behavior of the hash function, notice that, if [math]\displaystyle{ ax \bmod 2^w }[/math] and [math]\displaystyle{ ay\bmod 2^w }[/math] have the same highestorder 'M' bits, then [math]\displaystyle{ a(xy) \bmod 2^w }[/math] has either all 1's or all 0's as its highest order M bits (depending on whether [math]\displaystyle{ ax \bmod 2^w }[/math] or [math]\displaystyle{ ay \bmod 2^w }[/math] is larger). Assume that the least significant set bit of [math]\displaystyle{ xy }[/math] appears on position [math]\displaystyle{ wc }[/math]. Since [math]\displaystyle{ a }[/math] is a random odd integer and odd integers have inverses in the ring [math]\displaystyle{ Z_{2^w} }[/math], it follows that [math]\displaystyle{ a(xy)\bmod 2^w }[/math] will be uniformly distributed among [math]\displaystyle{ w }[/math]bit integers with the least significant set bit on position [math]\displaystyle{ wc }[/math]. The probability that these bits are all 0's or all 1's is therefore at most [math]\displaystyle{ 2/2^M=2/m }[/math]. On the other hand, if [math]\displaystyle{ c \lt M }[/math], then higherorder M bits of [math]\displaystyle{ a(xy) \bmod 2^w }[/math] contain both 0's and 1's, so it is certain that [math]\displaystyle{ h(x) \ne h(y) }[/math]. Finally, if [math]\displaystyle{ c=M }[/math] then bit [math]\displaystyle{ wM }[/math] of [math]\displaystyle{ a(xy) \bmod 2^w }[/math] is 1 and [math]\displaystyle{ h_a(x)=h_a(y) }[/math] if and only if bits [math]\displaystyle{ w1,\ldots,wM+1 }[/math] are also 1, which happens with probability [math]\displaystyle{ 1/2^{M1}=2/m }[/math].
This analysis is tight, as can be shown with the example [math]\displaystyle{ x=2^{wM2} }[/math] and [math]\displaystyle{ y=3x }[/math]. To obtain a truly 'universal' hash function, one can use the multiplyaddshift scheme that picks higherorder bits
 [math]\displaystyle{ h_{a,b}(x) = ((ax + b) \bmod 2^{w+M})\, \mathrm{div}\, 2^w , }[/math]
where [math]\displaystyle{ a }[/math] is a random positive integer with [math]\displaystyle{ a \lt 2^{2w} }[/math] and [math]\displaystyle{ b }[/math] is a random nonnegative integer with [math]\displaystyle{ b \lt 2^{2w} }[/math]. This requires doing arithmetic on [math]\displaystyle{ 2w }[/math]bit unsigned integers. This version of multiplyshift is due to Dietzfelbinger, and was later analyzed more precisely by Woelfel.^{[10]}
Hashing vectors
This section is concerned with hashing a fixedlength vector of machine words. Interpret the input as a vector [math]\displaystyle{ \bar{x} = (x_0, \dots, x_{k1}) }[/math] of [math]\displaystyle{ k }[/math] machine words (integers of [math]\displaystyle{ w }[/math] bits each). If [math]\displaystyle{ H }[/math] is a universal family with the uniform difference property, the following family (dating back to Carter and Wegman^{[1]}) also has the uniform difference property (and hence is universal):
 [math]\displaystyle{ h(\bar{x}) = \left( \sum_{i=0}^{k1} h_i(x_i) \right)\,\bmod~m }[/math], where each [math]\displaystyle{ h_i\in H }[/math] is chosen independently at random.
If [math]\displaystyle{ m }[/math] is a power of two, one may replace summation by exclusive or.^{[11]}
In practice, if doubleprecision arithmetic is available, this is instantiated with the multiplyshift hash family of hash functions.^{[12]} Initialize the hash function with a vector [math]\displaystyle{ \bar{a} = (a_0, \dots, a_{k1}) }[/math] of random odd integers on [math]\displaystyle{ 2w }[/math] bits each. Then if the number of bins is [math]\displaystyle{ m=2^M }[/math] for [math]\displaystyle{ M\le w }[/math]:
 [math]\displaystyle{ h_{\bar{a}}(\bar{x}) = \left(\big( \sum_{i=0}^{k1} x_i \cdot a_i \big) ~\bmod ~ 2^{2w} \right) \,\, \mathrm{div}\,\, 2^{2wM} }[/math].
It is possible to halve the number of multiplications, which roughly translates to a twofold speedup in practice.^{[11]} Initialize the hash function with a vector [math]\displaystyle{ \bar{a} = (a_0, \dots, a_{k1}) }[/math] of random odd integers on [math]\displaystyle{ 2w }[/math] bits each. The following hash family is universal:^{[13]}
 [math]\displaystyle{ h_{\bar{a}}(\bar{x}) = \left(\Big( \sum_{i=0}^{\lceil k/2 \rceil} (x_{2i} + a_{2i}) \cdot (x_{2i+1} + a_{2i+1}) \Big) \bmod ~ 2^{2w} \right) \,\, \mathrm{div}\,\, 2^{2wM} }[/math].
If doubleprecision operations are not available, one can interpret the input as a vector of halfwords ([math]\displaystyle{ w/2 }[/math]bit integers). The algorithm will then use [math]\displaystyle{ \lceil k/2 \rceil }[/math] multiplications, where [math]\displaystyle{ k }[/math] was the number of halfwords in the vector. Thus, the algorithm runs at a "rate" of one multiplication per word of input.
The same scheme can also be used for hashing integers, by interpreting their bits as vectors of bytes. In this variant, the vector technique is known as tabulation hashing and it provides a practical alternative to multiplicationbased universal hashing schemes.^{[14]}
Strong universality at high speed is also possible.^{[15]} Initialize the hash function with a vector [math]\displaystyle{ \bar{a} = (a_0, \dots, a_{k}) }[/math] of random integers on [math]\displaystyle{ 2w }[/math] bits. Compute
 [math]\displaystyle{ h_{\bar{a}}(\bar{x})^{\mathrm{strong}} = (a_0 + \sum_{i=0}^{k1} a_{i+1} x_{i} \bmod ~ 2^{2w} ) \,\, \mathrm{div}\,\, 2^w }[/math].
The result is strongly universal on [math]\displaystyle{ w }[/math] bits. Experimentally, it was found to run at 0.2 CPU cycle per byte on recent Intel processors for [math]\displaystyle{ w = 32 }[/math].
Hashing strings
This refers to hashing a variablesized vector of machine words. If the length of the string can be bounded by a small number, it is best to use the vector solution from above (conceptually padding the vector with zeros up to the upper bound). The space required is the maximal length of the string, but the time to evaluate [math]\displaystyle{ h(s) }[/math] is just the length of [math]\displaystyle{ s }[/math]. As long as zeroes are forbidden in the string, the zeropadding can be ignored when evaluating the hash function without affecting universality.^{[11]} Note that if zeroes are allowed in the string, then it might be best to append a fictitious nonzero (e.g., 1) character to all strings prior to padding: this will ensure that universality is not affected.^{[15]}
Now assume we want to hash [math]\displaystyle{ \bar{x} = (x_0,\dots, x_\ell) }[/math], where a good bound on [math]\displaystyle{ \ell }[/math] is not known a priori. A universal family proposed by ^{[12]} treats the string [math]\displaystyle{ x }[/math] as the coefficients of a polynomial modulo a large prime. If [math]\displaystyle{ x_i \in [u] }[/math], let [math]\displaystyle{ p \ge \max \{ u, m \} }[/math] be a prime and define:
 [math]\displaystyle{ h_a(\bar{x}) = h_\mathrm{int} \left( \big(\sum_{i=0}^\ell x_i\cdot a^{\elli} \big) \bmod ~p \right) }[/math], where [math]\displaystyle{ a \in [p] }[/math] is uniformly random and [math]\displaystyle{ h_\mathrm{int} }[/math] is chosen randomly from a universal family mapping integer domain [math]\displaystyle{ [p] \mapsto [m] }[/math].
Using properties of modular arithmetic, above can be computed without producing large numbers for large strings as follows:^{[16]}
uint hash(String x, int a, int p) uint h = INITIAL_VALUE for (uint i=0 ; i < x.length ; ++i) h = ((h*a) + x[i]) mod p return h
This RabinKarp rolling hash is based on a linear congruential generator.^{[17]} Above algorithm is also known as Multiplicative hash function.^{[18]} In practice, the mod operator and the parameter p can be avoided altogether by simply allowing integer to overflow because it is equivalent to mod (MaxIntValue + 1) in many programming languages. Below table shows values chosen to initialize h and a for some of the popular implementations.
Implementation  INITIAL_VALUE  a 

Bernstein's hash function djb2^{[19]}  5381  33 
STLPort 4.6.2  0  5 
Kernighan and Ritchie's hash function^{[20]}  0  31 
java.lang.String.hashCode() ^{[21]}

0  31 
Consider two strings [math]\displaystyle{ \bar{x}, \bar{y} }[/math] and let [math]\displaystyle{ \ell }[/math] be length of the longer one; for the analysis, the shorter string is conceptually padded with zeros up to length [math]\displaystyle{ \ell }[/math]. A collision before applying [math]\displaystyle{ h_\mathrm{int} }[/math] implies that [math]\displaystyle{ a }[/math] is a root of the polynomial with coefficients [math]\displaystyle{ \bar{x}  \bar{y} }[/math]. This polynomial has at most [math]\displaystyle{ \ell }[/math] roots modulo [math]\displaystyle{ p }[/math], so the collision probability is at most [math]\displaystyle{ \ell/p }[/math]. The probability of collision through the random [math]\displaystyle{ h_\mathrm{int} }[/math] brings the total collision probability to [math]\displaystyle{ \frac{1}{m} + \frac{\ell}{p} }[/math]. Thus, if the prime [math]\displaystyle{ p }[/math] is sufficiently large compared to the length of strings hashed, the family is very close to universal (in statistical distance).
Other universal families of hash functions used to hash unknownlength strings to fixedlength hash values include the Rabin fingerprint and the Buzhash.
Avoiding modular arithmetic
To mitigate the computational penalty of modular arithmetic, three tricks are used in practice:^{[11]}
 One chooses the prime [math]\displaystyle{ p }[/math] to be close to a power of two, such as a Mersenne prime. This allows arithmetic modulo [math]\displaystyle{ p }[/math] to be implemented without division (using faster operations like addition and shifts). For instance, on modern architectures one can work with [math]\displaystyle{ p = 2^{61}1 }[/math], while [math]\displaystyle{ x_i }[/math]'s are 32bit values.
 One can apply vector hashing to blocks. For instance, one applies vector hashing to each 16word block of the string, and applies string hashing to the [math]\displaystyle{ \lceil k/16 \rceil }[/math] results. Since the slower string hashing is applied on a substantially smaller vector, this will essentially be as fast as vector hashing.
 One chooses a poweroftwo as the divisor, allowing arithmetic modulo [math]\displaystyle{ 2^w }[/math] to be implemented without division (using faster operations of bit masking). The NH hashfunction family takes this approach.
See also
 Kindependent hashing – Family of Hash functions
 Rolling hashing
 Tabulation hashing – Hash functions computed by exclusive or
 Minwise independence
 Universal oneway hash function
 Lowdiscrepancy sequence
 Perfect hashing
References
 ↑ ^{1.0} ^{1.1} ^{1.2} ^{1.3} ^{1.4} Carter, Larry (1979). "Universal Classes of Hash Functions". Journal of Computer and System Sciences 18 (2): 143–154. doi:10.1016/00220000(79)900448. Conference version in STOC'77.
 ↑ Miltersen, Peter Bro. "Universal Hashing". http://www.daimi.au.dk/~bromille/Notes/un.pdf.
 ↑ Motwani, Rajeev; Raghavan, Prabhakar (1995). Randomized Algorithms. Cambridge University Press. p. 221. ISBN 0521474655.
 ↑ David Wagner, ed. "Advances in Cryptology  CRYPTO 2008". p. 145.
 ↑ JeanPhilippe Aumasson, Willi Meier, Raphael Phan, Luca Henzen. "The Hash Function BLAKE". 2014. p. 10.
 ↑ Thorup (2015). "High Speed Hashing for Integers and Strings". arXiv:1504.06804 [cs.DS].
 ↑ ^{7.0} ^{7.1} Baran, Ilya; Demaine, Erik D. (2008). "Subquadratic Algorithms for 3SUM". Algorithmica 50 (4): 584–596. doi:10.1007/s0045300790363. http://people.csail.mit.edu/mip/papers/3sum/3sum.pdf.
 ↑ Dietzfelbinger, Martin; Hagerup, Torben; Katajainen, Jyrki; Penttonen, Martti (1997). "A Reliable Randomized Algorithm for the ClosestPair Problem" (Postscript). Journal of Algorithms 25 (1): 19–51. doi:10.1006/jagm.1997.0873. http://www.diku.dk/~jyrki/Paper/CP11.4.1997.ps. Retrieved 10 February 2011.
 ↑ Thorup (18 December 2009). "Textbook algorithms at SODA". http://mybiasedcoin.blogspot.com/2009/12/textbookalgorithmsatsodaguestpost.html.
 ↑ Woelfel, Philipp (1999). "Efficient Strongly Universal and Optimally Universal Hashing". Mathematical Foundations of Computer Science 1999. 1672. pp. 262–272. doi:10.1007/3540483403_24.
 ↑ ^{11.0} ^{11.1} ^{11.2} ^{11.3} "String hashing for linear probing". 2009. pp. 655–664. doi:10.1137/1.9781611973068.72. ISBN 9780898716801., section 5.3
 ↑ ^{12.0} ^{12.1} Dietzfelbinger, Martin; Gil, Joseph; Matias, Yossi; Pippenger, Nicholas (1992). "Polynomial Hash Functions Are Reliable (Extended Abstract)". pp. 235–246.
 ↑ Black, J.; Halevi, S.; Krawczyk, H.; Krovetz, T. (1999). "UMAC: Fast and Secure Message Authentication". http://www.cs.ucdavis.edu/~rogaway/papers/umacfull.pdf., Equation 1
 ↑ "The power of simple tabulation hashing". 2011. pp. 1–10. doi:10.1145/1993636.1993638. ISBN 9781450306911.
 ↑ ^{15.0} ^{15.1} Kaser, Owen; Lemire, Daniel (2013). "Strongly universal string hashing is fast". Computer Journal (Oxford University Press) 57 (11): 1624–1638. doi:10.1093/comjnl/bxt070.
 ↑ "Hebrew University Course Slides". http://www.cs.huji.ac.il/course/2002/dast/slides/tirgul9.pdf.
 ↑ Robert Uzgalis. "Library Hash Functions". 1996.
 ↑ Kankowsk, Peter. "Hash functions: An empirical comparison". http://www.strchr.com/hash_functions.
 ↑ Yigit, Ozan. "String hash functions". http://www.cse.yorku.ca/~oz/hash.html.
 ↑ Kernighan; Ritchie (1988). "6". The C Programming Language (2nd ed.). Prentice Hall. pp. 118. ISBN 0131103628. https://archive.org/details/cprogramminglang00bria/page/118.
 ↑ "String (Java Platform SE 6)". http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#hashCode().
Further reading
 Knuth, Donald Ervin (1998). The Art of Computer Programming, Vol. III: Sorting and Searching (3rd ed.). Reading, Mass; London: AddisonWesley. ISBN 0201896850.
External links
Original source: https://en.wikipedia.org/wiki/Universal hashing.
Read more 