Hashing functions

Solo disponible en BuenasTareas
  • Páginas : 2 (403 palabras )
  • Descarga(s) : 0
  • Publicado : 2 de marzo de 2011
Leer documento completo
Vista previa del texto
HASHING FUNCTIONS
Modular Arithmetic
In modular arithmetic, first the key is converted to an integer, then it is divided by the size of the index range, and the remainder is taken to be the hashvalue. The spread achieved depends very much on the modulus. If the modulus is the power of small integers such as 2 or 10, then many keys tend to map into the same index, while other indices remainunused. The best choice for the modulus is often, but not always, a prime number, which usually has the effect of spreading the keys quite uniformly.
Truncation
Truncation ignores part of the key, anduses the remainder directly as the hash value (using numeric code to represent non-numeric field data). If the keys, for example, are eight-digit numbers and the hash table has 1000 entries, then thefirst, second, and fifth digits from the right side might make the hash value. So, 62538194 maps to 394. It is a fast method, but it often fails to distribute keys evenly.
Folding
In folding, theidentifier is partitioned into several parts, all but the last part being of the same length. These parts are then added together to obtain the hash value. For example, an eight-digit integer can bedivided into groups of three, three, and two digits. The groups are then added together, and truncated, if necessary, to be in the proper range of indices. So 62538149 maps to 625 + 381 + 94 = 1100,truncated to 100. Since all information in the key can affect the value of the function, folding often achieves a better spread of indices than truncation.
Mid-square method
In this method, theidentifier is squared (using numeric code to represent non- numeric field data), and then the appropriate number of bits from the middle of the square are used to get the hash value. Since the middle bits ofthe square usually depend on all the characters in the identifier, it is expected that different identifiers will result in different values. The number of middle bits that we select depends on...
tracking img