Add and implement a hash table.

This commit is contained in:
2016-12-21 01:07:47 -08:00
parent c83a8f5b00
commit 8447522dc2
3 changed files with 169 additions and 1 deletions

39
include/ht.h Normal file
View File

@@ -0,0 +1,39 @@
#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