DSA Hacking Club Library
Loading...
Searching...
No Matches
hashtable.h
Go to the documentation of this file.
1
10
11#ifndef HASHTABLE_H
12#define HASHTABLE_H
13
14#include <stdbool.h>
15#include <stddef.h>
16
17// --- Public Constants and Definitions ---
18
19#define DELETED_NODE \
20 ((void *)0xFFFFFFFFFFFFFFFUL)
21
28typedef const char *(*get_key_func)(const void *);
29
37typedef struct {
38 void **table;
39 size_t size;
41} hashtable;
42
43// --- Public Function Prototypes ---
44
52void init_hash_table(hashtable *ht, get_key_func get_key, size_t size);
53
63
71void print_table(const hashtable *ht);
72
80bool hash_table_insert(hashtable *ht, void *item);
81
89void *hash_table_lookup(const hashtable *ht, const char *key);
90
100void *hash_table_delete(hashtable *ht, const char *key);
101
102#endif // HASHTABLE_H
void * hash_table_lookup(const hashtable *ht, const char *key)
Looks up an object in the hash table by its string key.
Definition hashtable.c:69
const char *(* get_key_func)(const void *)
Function pointer type for extracting a string key from an object.
Definition hashtable.h:28
void * hash_table_delete(hashtable *ht, const char *key)
Deletes an object from the hash table by its string key.
Definition hashtable.c:87
void init_hash_table(hashtable *ht, get_key_func get_key, size_t size)
Initializes the hash table with a given size.
void free_hash_table(hashtable *ht)
Frees the dynamically allocated table inside the hash table.
Definition hashtable.c:26
void print_table(const hashtable *ht)
Prints the current state of the hash table to the console.
Definition hashtable.c:41
bool hash_table_insert(hashtable *ht, void *item)
Inserts an object into the hash table using linear probing.
Definition hashtable.c:53
The hash table structure.
Definition hashtable.h:37
void ** table
Dynamic array of pointers to stored objects.
Definition hashtable.h:38
get_key_func get_key
Function to extract keys from objects.
Definition hashtable.h:40
size_t size
Number of buckets in the table.
Definition hashtable.h:39