isl_tab: introduce support for "big parameters"
[isl.git] / include / isl_hash.h
blobc596b5e7bd7386e3b858ae1a7f2a70709f22ac1c
1 #ifndef ISL_HASH_H
2 #define ISL_HASH_H
4 #include <isl_stdint.h>
6 #if defined(__cplusplus)
7 extern "C" {
8 #endif
10 #define isl_hash_init() (2166136261u)
11 #define isl_hash_byte(h,b) do { \
12 h *= 16777619; \
13 h ^= b; \
14 } while(0)
15 #define isl_hash_hash(h,h2) \
16 do { \
17 isl_hash_byte(h, (h2) & 0xFF); \
18 isl_hash_byte(h, ((h2) >> 8) & 0xFF); \
19 isl_hash_byte(h, ((h2) >> 16) & 0xFF); \
20 isl_hash_byte(h, ((h2) >> 24) & 0xFF); \
21 } while(0)
22 #define isl_hash_bits(h,bits) \
23 ((bits) == 32) ? (h) : \
24 ((bits) >= 16) ? \
25 ((h) >> (bits)) ^ ((h) & (((uint32_t)1 << (bits)) - 1)) : \
26 (((h) >> (bits)) ^ (h)) & (((uint32_t)1 << (bits)) - 1)
28 uint32_t isl_hash_string(uint32_t hash, const char *s);
30 struct isl_hash_table_entry
32 uint32_t hash;
33 void *data;
36 struct isl_hash_table {
37 int bits;
38 int n;
39 struct isl_hash_table_entry *entries;
42 struct isl_ctx;
44 struct isl_hash_table *isl_hash_table_alloc(struct isl_ctx *ctx, int min_size);
45 void isl_hash_table_free(struct isl_ctx *ctx, struct isl_hash_table *table);
47 int isl_hash_table_init(struct isl_ctx *ctx, struct isl_hash_table *table,
48 int min_size);
49 void isl_hash_table_clear(struct isl_hash_table *table);
50 struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx,
51 struct isl_hash_table *table,
52 uint32_t key_hash,
53 int (*eq)(const void *entry, const void *val),
54 const void *val, int reserve);
55 void isl_hash_table_remove(struct isl_ctx *ctx,
56 struct isl_hash_table *table,
57 struct isl_hash_table_entry *entry);
59 #if defined(__cplusplus)
61 #endif
63 #endif