upscheme/c/ptrhash.c

52 lines
1.0 KiB
C
Raw Normal View History

2008-06-30 21:53:51 -04:00
/*
pointer hash table
optimized for storing info about particular values
*/
2019-08-18 18:20:02 -04:00
#include <sys/types.h>
2008-06-30 21:53:51 -04:00
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <setjmp.h>
#include <stdarg.h>
2019-08-09 16:25:20 -04:00
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
2008-06-30 21:53:51 -04:00
#include "scheme.h"
#include "equalhash.h"
#include "htable_inc.h"
2008-06-30 21:53:51 -04:00
#define OP_EQ(x, y) ((x) == (y))
2008-06-30 21:53:51 -04:00
2010-05-08 20:42:37 -04:00
#ifdef BITS64
2019-08-27 03:39:39 -04:00
static uint64_t _pinthash(uint64_t a)
2010-05-08 20:42:37 -04:00
{
2019-08-27 03:39:39 -04:00
a = (~a) + (a << 21); // a = (a << 21) - a - 1;
a = a ^ (a >> 24);
a = (a + (a << 3)) + (a << 8); // a * 265
a = a ^ (a >> 14);
a = (a + (a << 2)) + (a << 4); // a * 21
a = a ^ (a >> 28);
a = a + (a << 31);
return a;
2010-05-08 20:42:37 -04:00
}
#else
static uint32_t _pinthash(uint32_t a)
2010-05-08 20:42:37 -04:00
{
a = (a + 0x7ed55d16) + (a << 12);
a = (a ^ 0xc761c23c) ^ (a >> 19);
a = (a + 0x165667b1) + (a << 5);
a = (a + 0xd3a2646c) ^ (a << 9);
a = (a + 0xfd7046c5) + (a << 3);
a = (a ^ 0xb55a4f09) ^ (a >> 16);
2010-05-08 20:42:37 -04:00
return a;
}
#endif
HTIMPL(ptrhash, _pinthash, OP_EQ)