Content deleted Content added
Guy Harris (talk | contribs) Get rid of unnecessary piping. |
Guy Harris (talk | contribs) Division may or may not be microcoded; the issue is whether it takes multiple cycles, regardless of whether it's implemented with a hardware state machine or microcoded. That, and single-cycle vs. multi-cycle multiplication, are microarchitecture issues. And the division issue predated single-chip microprocessors. Unrolling a division loop ultimately generates machine instructions, whether they are first put into assembly language or not. |
||
Line 69:
Because collisions should be infrequent, and cause a marginal delay but are otherwise harmless, it is usually preferable to choose a faster hash function over one that needs more computation but saves a few collisions.
Division-based implementations can be of particular concern because
We can allow the table size {{math|''n''}} to not be a power of 2 and still not have to perform any remainder or division operation, as these computations are sometimes costly. For example, let {{math|''n''}} be significantly less than {{math|2<sup>''b''</sup>}}. Consider a [[pseudorandom number generator]] function {{math|''P''(key)}} that is uniform on the interval {{math|[0, 2<sup>''b''</sup> − 1]}}. A hash function uniform on the interval {{math|[0, ''n'' − 1]}} is {{math|''n'' ''P''(key) / 2<sup>''b''</sup>}}. We can replace the division by a (possibly faster) right [[bit shifting|bit shift]]: {{math|''n P''(key) >> ''b''}}.
Line 134:
=== Division hashing ===
A standard technique is to use a modulo function on the key, by selecting a divisor {{Mvar|M}} which is a prime number close to the table size, so {{Math|''h''(''K'') ≡ ''K'' (mod ''M'')}}. The table size is usually a power of 2. This gives a distribution from {{Math|{{mset|0, ''M'' − 1}}}}. This gives good results over a large number of key sets. A significant drawback of division hashing is that division
=== Algebraic coding ===
|