#include <os/base.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <sys/types.h>
#include <sys/param.h>
#include <os/assumes.h>
#include "table.h"
#include "notify_internal.h"
#define TABLE_TOMBSTONE ((void *)~0)
#define TABLE_MINSHIFT 5
#define TABLE_MINSIZE (1 << TABLE_MINSHIFT)
OS_ALWAYS_INLINE
static inline uint32_t
table_next(uint32_t i, uint32_t size)
{
i++;
return i >= size ? 0 : i;
}
OS_ALWAYS_INLINE
static inline uint32_t
table_prev(uint32_t i, uint32_t size)
{
return (i ? i : size) - 1;
}
static inline bool
string_equals(const char *a, const char *b)
{
return a == b || strcmp(a, b) == 0;
}
static uint32_t
string_hash(const char *key)
{
uint32_t hash = 0;
for (; *key; key++) {
hash += (unsigned char)(*key);
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash;
}
static inline bool
uint32_equals(uint32_t a, uint32_t b)
{
return a == b;
}
static inline uint32_t
uint32_hash(uint32_t x)
{
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = (x >> 16) ^ x;
return x;
}
static inline bool
uint64_equals(uint64_t a, uint64_t b)
{
return a == b;
}
static inline uint32_t
uint64_hash(uint64_t key)
{
return uint32_hash((uint32_t)key ^ (uint32_t)(key >> 32));
}
#define ns(n) _nc_table##n
#define key_t char *
#define ckey_t const char *
#define key_hash string_hash
#define key_equals string_equals
#include "table.in.c"
#define ns(n) _nc_table##n##_n
#define key_t uint32_t
#define ckey_t uint32_t
#define key_hash uint32_hash
#define key_equals uint32_equals
#include "table.in.c"
#define ns(n) _nc_table##n##_64
#define key_t uint64_t
#define ckey_t uint64_t
#define key_hash uint64_hash
#define key_equals uint64_equals
#include "table.in.c"