35 lines
731 B
C
35 lines
731 B
C
|
|
#ifndef HASH_MAP_H
|
||
|
|
#define HASH_MAP_H
|
||
|
|
|
||
|
|
#include <stdbool.h>
|
||
|
|
#include <stddef.h>
|
||
|
|
|
||
|
|
struct pair_list
|
||
|
|
{
|
||
|
|
const char *key;
|
||
|
|
void *value;
|
||
|
|
struct pair_list *next;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct hash_map
|
||
|
|
{
|
||
|
|
struct pair_list **data;
|
||
|
|
size_t size;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct hash_map *hash_map_init(size_t size);
|
||
|
|
|
||
|
|
bool hash_map_insert(struct hash_map *hash_map, const char *key, void *value,
|
||
|
|
bool *updated);
|
||
|
|
|
||
|
|
void hash_map_free(struct hash_map *hash_map);
|
||
|
|
|
||
|
|
void hash_map_foreach(struct hash_map *hash_map,
|
||
|
|
void (*fn)(const char *, const void *));
|
||
|
|
|
||
|
|
const void *hash_map_get(const struct hash_map *hash_map, const char *key);
|
||
|
|
|
||
|
|
bool hash_map_remove(struct hash_map *hash_map, const char *key);
|
||
|
|
|
||
|
|
#endif /* ! HASH_MAP_H */
|