myxce/src/include/htab.h

43 lines
938 B
C

#if !defined(_HTAB_H_)
#define _HTAB_H_ 1
#include <stdint.h>
#include "mylock.h"
typedef unsigned int (*hash_key_hash_fn_t)(void*);
typedef int (*hash_key_cmp_fn_t)(void*, void*);
typedef void* (*hash_key_copy_fn_t)(void*);
typedef void (*hash_key_free_fn_t)(void*);
typedef struct {
hash_key_hash_fn_t hash;
hash_key_cmp_fn_t cmp;
hash_key_copy_fn_t copy;
hash_key_free_fn_t free;
} hash_key_fn_t;
typedef struct _hent {
struct _hent* next;
void* key;
int64_t data;
} hent_t;
typedef struct {
mylock_t lock;
int nslots;
hash_key_fn_t fn;
hent_t** slots;
} htab_t;
extern hash_key_fn_t string_hash_key;
extern hash_key_fn_t int_hash_key;
extern int ht_init(htab_t*, int, hash_key_fn_t);
extern void ht_fini(htab_t*);
extern hent_t* ht_get(htab_t*, void*);
extern hent_t* ht_add(htab_t*, void*);
extern int ht_del(htab_t*, void*);
#endif