1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2024-09-19 13:25:53 +02:00
libcproject/lib/dictionary.h

36 lines
757 B
C
Raw Normal View History

#ifndef __LIBCPROJECT_DICTIONARY__
#define __LIBCPROJECT_DICTIONARY__
2023-01-05 19:28:05 +01:00
#include <stdbool.h>
#include <stdlib.h>
2023-01-07 19:38:01 +01:00
#include "string.h"
2023-06-25 15:07:34 +02:00
#include "types.h"
2023-01-05 19:28:05 +01:00
#define DICTIONARY_INITIAL_CAPACITY 10
// Dictionary implementation with O(n) lookup complexity.
struct dictionary {
struct dictionary_item **items;
size_t length;
size_t capacity;
};
struct dictionary_item {
void *data;
char *key;
};
struct dictionary *dictionary_initialization();
void dictionary_add(struct dictionary *dictionary, char *key, void *data);
void dictionary_remove(struct dictionary *dictionary, char *key);
struct dictionary_item *dictionary_get(struct dictionary *dictionary, char *key);
bool dictionary_contains_key(struct dictionary *dictionary, char *key);
#endif