CHashTable 1
Loading...
Searching...
No Matches
hash_table.h
Go to the documentation of this file.
1
6#ifndef CHASHTABLE_HASH_TABLE_H
7#define CHASHTABLE_HASH_TABLE_H
8
20typedef struct entry {
21 int key;
22 int value;
23 struct entry *next;
25
36typedef struct hash_table HashTable;
37
46HashTable *hash_table_create(void);
47
57bool hash_table_destroy(HashTable *table);
58
70bool hash_table_insert(HashTable *table, int key, int value);
71
79const Entry *hash_table_get(const HashTable *table, int key);
80
88bool hash_table_delete(HashTable *table, int key);
89
97bool hash_table_equal(const HashTable *table1, const HashTable *table2);
98
105HashTable *hash_table_copy(const HashTable *table);
106
114void hash_table_foreach(const HashTable *table, void (*callback)(int key, int value, void *), void *user_data);
115
126bool hash_table_save(const HashTable *table, const char *filename);
127
133typedef enum {
134 HT_LOAD_OK = 0, // Success
135 HT_LOAD_ERROR_FILE_OPEN, // Could not open the file
136 HT_LOAD_ERROR_EMPTY, // File is empty or header is unreadable
137 HT_LOAD_ERROR_INVALID_HEADER, // Invalid file header prefix
138 HT_LOAD_ERROR_MISSING_COUNT, // Item count line is missing
139 HT_LOAD_ERROR_MALFORMED_COUNT,// Failed to parse the item count
140 HT_LOAD_ERROR_ALLOC_FAILED, // Failed to allocate memory for the hash table
141 HT_LOAD_ERROR_PREMATURE_EOF, // File ended before all items were read
142 HT_LOAD_ERROR_MALFORMED_LINE // File contains malformed key-value pairs, or item count mismatch.
144
159HashTable_LoadError hash_table_load(const char *filename, HashTable **out_table);
160
168const char *hash_table_error_string(HashTable_LoadError error_code);
169
179void hash_table_print(const HashTable *table, bool print_empty_buckets);
180
// End of the hash_table Doxygen group
182
183#endif //CHASHTABLE_HASH_TABLE_H
struct entry Entry
A hash table entry object.
HashTable_LoadError
Error codes for the hash_table_load function.
Definition hash_table.h:133
struct hash_table HashTable
An opaque handle to a hash table object.
Definition hash_table.h:36
const char * hash_table_error_string(HashTable_LoadError error_code)
Converts a hash table load error code into a static, human-readable string.
Definition hash_table_io.c:134
HashTable_LoadError hash_table_load(const char *filename, HashTable **out_table)
Loads a hash table from a specified file.
Definition hash_table_io.c:42
A hash table entry object.
Definition hash_table.h:20
Definition hash_table_internal.h:21