1/*
2 * Copyright 2016, 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(D61_BSD)
11 */
12
13#ifndef _CHASH_H_
14#define _CHASH_H_
15
16#include <data_struct/cvector.h>
17
18#ifndef kmalloc
19    #include <stdlib.h>
20    #include <stdint.h>
21    #define kmalloc malloc
22    #define krealloc realloc
23    #define kfree free
24#endif
25
26typedef void* chash_item_t;
27
28typedef struct chash_entry_s {
29    uint32_t key;
30    chash_item_t item;
31} chash_entry_t;
32
33typedef struct chash_s {
34    cvector_t* table;
35    size_t tableSize;
36} chash_t;
37
38void chash_init(chash_t *t, size_t sz);
39
40void chash_release(chash_t *t);
41
42chash_item_t chash_get(chash_t *t, uint32_t key);
43
44int chash_set(chash_t *t, uint32_t key, chash_item_t obj);
45
46void chash_remove(chash_t *t, uint32_t key);
47
48int chash_find_free(chash_t *t, uint32_t rangeStart, uint32_t rangeEnd);
49
50#endif /* _CHASH_H_ */
51