Back to index

glibc  2.9
Defines | Functions
hashval.h File Reference
#include <limits.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define hashval_t   unsigned long int

Functions

hashval_t compute_hashval (const void *key, size_t keylen)

Define Documentation

#define hashval_t   unsigned long int

Definition at line 22 of file hashval.h.


Function Documentation

hashval_t compute_hashval ( const void *  key,
size_t  keylen 
)

Definition at line 27 of file hashval.h.

{
  size_t cnt;
  hashval_t hval;

  /* Compute the hash value for the given string.  The algorithm
     is taken from [Aho,Sethi,Ullman], modified to reduce the number of
     collisions for short strings with very varied bit patterns.
     See http://www.clisp.org/haible/hashfunc.html.  */
  cnt = 0;
  hval = keylen;
  while (cnt < keylen)
    {
      hval = (hval << 9) | (hval >> (sizeof hval * CHAR_BIT - 9));
      hval += (hashval_t) *(((char *) key) + cnt++);
    }
  return hval != 0 ? hval : ~((hashval_t) 0);
}