From 0248522320a0023365c6a8ac31efbb9515438ec6 Mon Sep 17 00:00:00 2001 From: mahmoudkhalef Date: Fri, 29 Dec 2023 06:14:20 -0800 Subject: [PATCH] libdynamic --- 0x1A-hash_tables/hash_tables.h | 47 ++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/0x1A-hash_tables/hash_tables.h b/0x1A-hash_tables/hash_tables.h index a233cf4..f687d39 100644 --- a/0x1A-hash_tables/hash_tables.h +++ b/0x1A-hash_tables/hash_tables.h @@ -1,10 +1,9 @@ #ifndef HASH_TABLES_H #define HASH_TABLES_H -#include #include #include - +#include /** * struct hash_node_s - Node of a hash table @@ -40,6 +39,50 @@ unsigned long int hash_djb2(const unsigned char *str); unsigned long int key_index(const unsigned char *key, unsigned long int size); int hash_table_set(hash_table_t *ht, const char *key, const char *value); char *hash_table_get(const hash_table_t *ht, const char *key); +void hash_table_print(const hash_table_t *ht); +void hash_table_delete(hash_table_t *ht); + +/** + * struct shash_node_s - Node of a sorted hash table + * @key: The key, string + * The key is unique in the HashTable + * @value: The value corresponding to a key + * @next: A pointer to the next node of the List + * @sprev: A pointer to the previous element of the sorted linked list + * @snext: A pointer to the next element of the sorted linked list + */ +typedef struct shash_node_s +{ + char *key; + char *value; + struct shash_node_s *next; + struct shash_node_s *sprev; + struct shash_node_s *snext; +} shash_node_t; + +/** + * struct shash_table_s - Sorted hash table data structure + * @size: The size of the array + * @array: An array of size @size + * Each cell of this array is a pointer to the first node of a linked list, + * because we want our HashTable to use a Chaining collision handling + * @shead: A pointer to the first element of the sorted linked list + * @stail: A pointer to the last element of the sorted linked list + */ +typedef struct shash_table_s +{ + unsigned long int size; + shash_node_t **array; + shash_node_t *shead; + shash_node_t *stail; +} shash_table_t; + +shash_table_t *shash_table_create(unsigned long int size); +int shash_table_set(shash_table_t *ht, const char *key, const char *value); +char *shash_table_get(const shash_table_t *ht, const char *key); +void shash_table_print(const shash_table_t *ht); +void shash_table_print_rev(const shash_table_t *ht); +void shash_table_delete(shash_table_t *ht); #endif