Skip to content

Commit

Permalink
libdynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoudkhalef committed Dec 29, 2023
1 parent 46827ab commit 0248522
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions 0x1A-hash_tables/hash_tables.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#ifndef HASH_TABLES_H
#define HASH_TABLES_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <stdio.h>

/**
* struct hash_node_s - Node of a hash table
Expand Down Expand Up @@ -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

0 comments on commit 0248522

Please sign in to comment.