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 File Reference

Header file for a simple hash table implementation. More...

#include <stdbool.h>
Include dependency graph for hash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Entry
 Represents an entry in the hash table. More...
 
struct  HashTable
 Represents the hash table. More...
 

Functions

unsigned int hash (const char *key, int capacity)
 Computes the hash value for a given key.
 
HashTabletable_create (int initial_capacity)
 Creates a new hash table with the specified initial capacity.
 
void table_resize (HashTable *table)
 Resizes the hash table to accommodate more entries.
 
Entrytable_insert (HashTable *table, const char *key, void *value)
 Inserts a key-value pair into the hash table.
 
void table_insert_raw (HashTable *table, const char *key, void *value)
 Inserts a key-value pair into the hash table without checking for duplicates.
 
void * table_get (HashTable *table, const char *key)
 Retrieves the value associated with a given key in the hash table.
 
void table_remove (HashTable *table, const char *key)
 Removes a key-value pair from the hash table.
 
void table_free (HashTable *table)
 Frees all memory associated with the hash table.
 

Detailed Description

Header file for a simple hash table implementation.

This file contains the definitions and function declarations for a hash table implementation that supports insertion, retrieval, and deletion of key-value pairs.

Function Documentation

◆ hash()

unsigned int hash ( const char *  key,
int  capacity 
)

Computes the hash value for a given key.

Parameters
keyThe key to hash.
capacityThe capacity of the hash table.
Returns
The hash value for the key.

◆ table_create()

HashTable * table_create ( int  initial_capacity)

Creates a new hash table with the specified initial capacity.

Parameters
initial_capacityThe initial capacity of the hash table.
Returns
A pointer to the newly created hash table.

◆ table_resize()

void table_resize ( HashTable table)

Resizes the hash table to accommodate more entries.

Parameters
tableThe hash table to resize.

◆ table_insert()

Entry * table_insert ( HashTable table,
const char *  key,
void *  value 
)

Inserts a key-value pair into the hash table.

Parameters
tableThe hash table.
keyThe key to insert.
valueThe value to associate with the key.
Returns
A pointer to the newly inserted entry.

◆ table_insert_raw()

void table_insert_raw ( HashTable table,
const char *  key,
void *  value 
)

Inserts a key-value pair into the hash table without checking for duplicates.

Parameters
tableThe hash table.
keyThe key to insert.
valueThe value to associate with the key.

◆ table_get()

void * table_get ( HashTable table,
const char *  key 
)

Retrieves the value associated with a given key in the hash table.

Parameters
tableThe hash table.
keyThe key to look up.
Returns
A pointer to the value associated with the key, or NULL if the key is not found.

◆ table_remove()

void table_remove ( HashTable table,
const char *  key 
)

Removes a key-value pair from the hash table.

Parameters
tableThe hash table.
keyThe key to remove.

◆ table_free()

void table_free ( HashTable table)

Frees all memory associated with the hash table.

Parameters
tableThe hash table to free.