mirror of
https://github.com/theoludwig/libcproject.git
synced 2024-11-09 22:08:40 +01:00
36 lines
733 B
C
36 lines
733 B
C
#ifndef __DICTIONARY__
|
|
#define __DICTIONARY__
|
|
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "string.h"
|
|
#include "types.h"
|
|
|
|
#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
|