jenkins-hash.h 1.33 KB
Newer Older
Philip Carns's avatar
Philip Carns committed
1 2 3 4 5 6
/*
 * Copyright (C) 2013 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

7 8 9
#ifndef __JENKINS_HASH__
#define __JENKINS_HASH__

Jonathan Jenkins's avatar
Jonathan Jenkins committed
10 11 12 13
#ifdef __cplusplus
extern "C" {
#endif

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#include <sys/types.h>
#include <stdint.h>

/* This header declares and exports Bob Jenkins hash functions define in lookup3.c.
 * lookup3.c was downloaded from:  http://www.burtleburtle.net/bob/c/lookup3.c
 * See: http://www.burtleburtle.net/bob/hash/doobs.html for more information.
 *
 * Export other functions in that library as necessary.
 */

void bj_hashlittle2(
  const void *key,       /* the key to hash */
  size_t      length,    /* length of the key */
  uint32_t   *pc,        /* IN: primary initval, OUT: primary hash */
  uint32_t   *pb);        /* IN: secondary initval, OUT: secondary hash */

/* bj_hashsize(shift) gives a hash table size that is a power of 2, good for bj_hashlittle2.
 * shift values are:
 *
 * 1024 -> 10
 * 4096 -> 12
 * 16384 -> 14
 * 65536 -> 16
 * 262144 -> 18
 * 1048576 -> 20
 */
#define bj_hashsize(n) ((uint32_t)1<<(n))

/* bj_hashmask(n) gives a mask reasonable for returning a hash between 0 and the hashtable size.
 */
#define bj_hashmask(n) (bj_hashsize(n)-1)

Jonathan Jenkins's avatar
Jonathan Jenkins committed
46 47 48 49
#ifdef __cplusplus
}
#endif

50
#endif
Philip Carns's avatar
Philip Carns committed
51 52 53 54 55 56 57 58 59

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ts=8 sts=4 sw=4 expandtab
 */