libds/include/ht.h

40 lines
788 B
C

#ifndef LIBDS_HT_HEADER
#define LIBDS_HT_HEADER
#define LIBDS_HT_SIZE 32
#include "libds.h"
struct ht_node_s {
void* key;
void* data;
struct ht_node_s* next;
};
struct ht_s {
struct ht_node_s* data[LIBDS_HT_SIZE];
unsigned int (*hash_func)(void*);
int (*cmp_func)(void*, void*);
void* (*copy_func)(void*);
void (*free_func)(void*);
};
typedef struct ht_node_s ht_node;
typedef struct ht_s ht;
unsigned int ht_default_hash_func(void*);
int ht_default_cmp_func(void*, void*);
void* ht_default_copy_func(void*);
void ht_default_free_func(void*);
void ht_init(ht*);
void ht_free(ht*);
libds_result ht_put(ht*, void*, void*);
void* ht_get(ht*, void*);
void ht_remove(ht*, void*);
int ht_foreach(ht*, void*, compare_func, foreach_func, ...);
#endif