|
Packit |
fb9d21 |
/*
|
|
Packit |
fb9d21 |
* Copyright 2008-2009 Katholieke Universiteit Leuven
|
|
Packit |
fb9d21 |
*
|
|
Packit |
fb9d21 |
* Use of this software is governed by the MIT license
|
|
Packit |
fb9d21 |
*
|
|
Packit |
fb9d21 |
* Written by Sven Verdoolaege, K.U.Leuven, Departement
|
|
Packit |
fb9d21 |
* Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
|
|
Packit |
fb9d21 |
*/
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#ifndef ISL_HASH_H
|
|
Packit |
fb9d21 |
#define ISL_HASH_H
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#include <stdlib.h>
|
|
Packit |
fb9d21 |
#include <isl/stdint.h>
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#if defined(__cplusplus)
|
|
Packit |
fb9d21 |
extern "C" {
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define isl_hash_init() (2166136261u)
|
|
Packit |
fb9d21 |
#define isl_hash_byte(h,b) do { \
|
|
Packit |
fb9d21 |
h *= 16777619; \
|
|
Packit |
fb9d21 |
h ^= b; \
|
|
Packit |
fb9d21 |
} while(0)
|
|
Packit |
fb9d21 |
#define isl_hash_hash(h,h2) \
|
|
Packit |
fb9d21 |
do { \
|
|
Packit |
fb9d21 |
isl_hash_byte(h, (h2) & 0xFF); \
|
|
Packit |
fb9d21 |
isl_hash_byte(h, ((h2) >> 8) & 0xFF); \
|
|
Packit |
fb9d21 |
isl_hash_byte(h, ((h2) >> 16) & 0xFF); \
|
|
Packit |
fb9d21 |
isl_hash_byte(h, ((h2) >> 24) & 0xFF); \
|
|
Packit |
fb9d21 |
} while(0)
|
|
Packit |
fb9d21 |
#define isl_hash_bits(h,bits) \
|
|
Packit |
fb9d21 |
((bits) == 32) ? (h) : \
|
|
Packit |
fb9d21 |
((bits) >= 16) ? \
|
|
Packit |
fb9d21 |
((h) >> (bits)) ^ ((h) & (((uint32_t)1 << (bits)) - 1)) : \
|
|
Packit |
fb9d21 |
(((h) >> (bits)) ^ (h)) & (((uint32_t)1 << (bits)) - 1)
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
uint32_t isl_hash_string(uint32_t hash, const char *s);
|
|
Packit |
fb9d21 |
uint32_t isl_hash_mem(uint32_t hash, const void *p, size_t len);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define isl_hash_builtin(h,l) isl_hash_mem(h, &l, sizeof(l))
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
struct isl_hash_table_entry
|
|
Packit |
fb9d21 |
{
|
|
Packit |
fb9d21 |
uint32_t hash;
|
|
Packit |
fb9d21 |
void *data;
|
|
Packit |
fb9d21 |
};
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
struct isl_hash_table {
|
|
Packit |
fb9d21 |
int bits;
|
|
Packit |
fb9d21 |
int n;
|
|
Packit |
fb9d21 |
struct isl_hash_table_entry *entries;
|
|
Packit |
fb9d21 |
};
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
struct isl_ctx;
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
struct isl_hash_table *isl_hash_table_alloc(struct isl_ctx *ctx, int min_size);
|
|
Packit |
fb9d21 |
void isl_hash_table_free(struct isl_ctx *ctx, struct isl_hash_table *table);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
int isl_hash_table_init(struct isl_ctx *ctx, struct isl_hash_table *table,
|
|
Packit |
fb9d21 |
int min_size);
|
|
Packit |
fb9d21 |
void isl_hash_table_clear(struct isl_hash_table *table);
|
|
Packit |
fb9d21 |
struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx,
|
|
Packit |
fb9d21 |
struct isl_hash_table *table,
|
|
Packit |
fb9d21 |
uint32_t key_hash,
|
|
Packit |
fb9d21 |
int (*eq)(const void *entry, const void *val),
|
|
Packit |
fb9d21 |
const void *val, int reserve);
|
|
Packit |
fb9d21 |
int isl_hash_table_foreach(struct isl_ctx *ctx,
|
|
Packit |
fb9d21 |
struct isl_hash_table *table,
|
|
Packit |
fb9d21 |
int (*fn)(void **entry, void *user), void *user);
|
|
Packit |
fb9d21 |
void isl_hash_table_remove(struct isl_ctx *ctx,
|
|
Packit |
fb9d21 |
struct isl_hash_table *table,
|
|
Packit |
fb9d21 |
struct isl_hash_table_entry *entry);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#if defined(__cplusplus)
|
|
Packit |
fb9d21 |
}
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#endif
|