#ifndef _HASH_TABLE_H
#define _HASH_TABLE_H
#include <stdlib.h>
#include <inttypes.h>
#include <stdbool.h>
#include "c99_compat.h"
#include "macros.h"
#ifdef __cplusplus
extern "C" {
#endif
struct hash_entry {
uint32_t hash;
const void *key;
void *data;
};
struct hash_table {
struct hash_entry *table;
bool (*key_equals_function)(const void *a, const void *b);
const void *deleted_key;
uint32_t size;
uint32_t rehash;
uint32_t max_entries;
uint32_t size_index;
uint32_t entries;
uint32_t deleted_entries;
};
struct hash_table *
_mesa_hash_table_create(void *mem_ctx,
bool (*key_equals_function)(const void *a,
const void *b));
void _mesa_hash_table_destroy(struct hash_table *ht,
void (*delete_function)(struct hash_entry *entry));
void _mesa_hash_table_set_deleted_key(struct hash_table *ht,
const void *deleted_key);
struct hash_entry *
_mesa_hash_table_insert(struct hash_table *ht, uint32_t hash,
const void *key, void *data);
struct hash_entry *
_mesa_hash_table_search(struct hash_table *ht, uint32_t hash,
const void *key);
void _mesa_hash_table_remove(struct hash_table *ht,
struct hash_entry *entry);
struct hash_entry *_mesa_hash_table_next_entry(struct hash_table *ht,
struct hash_entry *entry);
struct hash_entry *
_mesa_hash_table_random_entry(struct hash_table *ht,
bool (*predicate)(struct hash_entry *entry));
uint32_t _mesa_hash_data(const void *data, size_t size);
uint32_t _mesa_hash_string(const char *key);
bool _mesa_key_string_equal(const void *a, const void *b);
bool _mesa_key_pointer_equal(const void *a, const void *b);
static inline uint32_t _mesa_hash_pointer(const void *pointer)
{
return _mesa_hash_data(&pointer, sizeof(pointer));
}
#define hash_table_foreach(ht, entry) \
for (entry = _mesa_hash_table_next_entry(ht, NULL); \
entry != NULL; \
entry = _mesa_hash_table_next_entry(ht, entry))
#ifdef __cplusplus
}
#endif
#endif