diff options
| author | Nebula Moe <nebula_moe@outlook.com> | 2023-07-24 19:47:03 +0800 |
|---|---|---|
| committer | Nebula Moe <nebula_moe@outlook.com> | 2023-07-28 22:30:22 +0800 |
| commit | 2161797b19b068622a692628f352c78254d8a354 (patch) | |
| tree | 146272037ff9a79dbd3903dd9471a7713469419d /htable.h | |
Diffstat (limited to 'htable.h')
| -rw-r--r-- | htable.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/htable.h b/htable.h new file mode 100644 index 0000000..c373baa --- /dev/null +++ b/htable.h @@ -0,0 +1,31 @@ +// Copyright (C) 2023 Dzshy <dzshy@outlook.com>. All Rights Reserved. +// Licensed under Non-Profit Open Software License ("Non-Profit OSL") 3.0. + +#ifndef HTABLE_H_ +#define HTABLE_H_ + +#include <stdbool.h> +#include <stdint.h> + +typedef struct { + void *buf; + int size; + int cap; + int taken; + void *begin; + int elemsz; + uint32_t (*hash)(void *); + bool (*eq)(void *, void *); +} HTable; + +void htable_init(HTable *ht, int elemsz, int cap, uint32_t (*hash)(void *), + bool (*eq)(void *, void *)); +bool htable_insert(HTable *ht, void *elem); +void htable_del(HTable *ht, void *iter); + +// return a iterator +void *htable_find(HTable *ht, void *elem); +void *htable_begin(HTable *ht); +void *htable_next(HTable *ht, void *iter); + +#endif |
