Claude Chappe' Curse - A C Game
Logo Institut d'Informatique Claude Chappe Logo Université de Le Mans Logo Raeptor Production
 
Loading...
Searching...
No Matches
hash.h
Go to the documentation of this file.
1#ifndef HASH_H
2#define HASH_H
3
4#include <stdbool.h>
5
30typedef struct Entry {
31 char *key;
32 void *value;
34 struct Entry *next;
35} Entry;
36
50typedef struct HashTable {
52 int size;
54} HashTable;
55
63unsigned int hash(const char *key, int capacity);
64
71HashTable *table_create(int initial_capacity);
72
78void table_resize(HashTable *table);
79
88Entry *table_insert(HashTable *table, const char *key, void *value);
89
97void table_insert_raw(HashTable *table, const char *key, void *value);
98
106void *table_get(HashTable *table, const char *key);
107
114void table_remove(HashTable *table, const char *key);
115
121void table_free(HashTable *table);
122
123#endif
void table_free(HashTable *table)
Frees all memory associated with the hash table.
Definition hash.c:112
void table_resize(HashTable *table)
Resizes the hash table to accommodate more entries.
Definition hash.c:26
unsigned int hash(const char *key, int capacity)
Computes the hash value for a given key.
Definition hash.c:10
HashTable * table_create(int initial_capacity)
Creates a new hash table with the specified initial capacity.
Definition hash.c:18
void table_remove(HashTable *table, const char *key)
Removes a key-value pair from the hash table.
Definition hash.c:88
void * table_get(HashTable *table, const char *key)
Retrieves the value associated with a given key in the hash table.
Definition hash.c:76
Entry * table_insert(HashTable *table, const char *key, void *value)
Inserts a key-value pair into the hash table.
Definition hash.c:46
void table_insert_raw(HashTable *table, const char *key, void *value)
Inserts a key-value pair into the hash table without checking for duplicates.
Definition hash.c:72
Represents an entry in the hash table.
Definition hash.h:30
char * key
Definition hash.h:31
struct Entry * next
Definition hash.h:34
bool needs_free
Definition hash.h:33
void * value
Definition hash.h:32
Represents the hash table.
Definition hash.h:50
int size
Definition hash.h:52
Entry ** table
Definition hash.h:51
int capacity
Definition hash.h:53