1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12#include "dict.h"
13#include <glib.h>
14#include <stdbool.h>
15#include <stdlib.h>
16#include <string.h>
17
18dict_t *dict(void (*value_destroyer)(void *value)) {
19    return g_hash_table_new_full(g_str_hash, g_str_equal, NULL, value_destroyer);
20}
21
22void dict_set(dict_t *d, const char *key, void *value) {
23    g_hash_table_insert(d, (gpointer)key, value);
24}
25
26void *dict_get(dict_t *d, const char *key) {
27    return g_hash_table_lookup(d, key);
28}
29
30bool dict_contains(dict_t *d, const char *key) {
31    return g_hash_table_contains(d, key);
32}
33
34void dict_destroy(dict_t *d) {
35    g_hash_table_destroy(d);
36}
37