From 729aac88a58b6589c0d1aeb82bd729b886555771 Mon Sep 17 00:00:00 2001 From: Johnny Richard Date: Wed, 13 Apr 2022 02:06:11 +0200 Subject: hash_table: Implement hash_table data struct --- hash_table.h | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'hash_table.h') diff --git a/hash_table.h b/hash_table.h index 5ac3cfd..66731b5 100644 --- a/hash_table.h +++ b/hash_table.h @@ -16,21 +16,45 @@ * along with this program. If not, see . */ #ifndef HASH_TABLE_H -#define HASH_TABLE +#define HASH_TABLE_H #include +#include -typedef struct hash_entry { - const char* key; - void* value; -} hash_entry_t; +typedef struct hash_table hash_table_t; +typedef struct hash_table_entry hash_table_entry_t; +typedef struct hash_table_iterator hash_table_iterator_t; -typedef struct hash_table { - hash_entry_t* entries; +struct hash_table { + hash_table_entry_t* entries; size_t capacity; size_t length; -} hash_table_t; +}; + +struct hash_table_entry { + const char* key; + void* value; +}; + +struct hash_table_iterator { + const char* key; + void* value; + hash_table_t *_table; + size_t _index; +}; + +hash_table_t* hash_table_new (); +void hash_table_destroy (hash_table_t *ht); +void hash_table_insert (hash_table_t *ht, + const char *key, + void *value); +bool hash_table_remove (hash_table_t *ht, + const char *key); +void* hash_table_get (hash_table_t *ht, + const char *key); +size_t hash_table_length (hash_table_t *ht); -hash_table_t* hash_table_new(); +hash_table_iterator_t hash_table_get_iterator(hash_table_t *ht); +bool hash_table_iterator_next(hash_table_iterator_t *it); #endif /* HASH_TABLE_H */ -- cgit v1.2.3