| 1 |
#include <cstdarg> |
| 2 |
#include <cstdint> |
| 3 |
#include <cstdlib> |
| 4 |
#include <ostream> |
| 5 |
#include <new> |
| 6 |
|
| 7 |
template<typename T = void> |
| 8 |
struct MaybeUninit; |
| 9 |
|
| 10 |
using Str = const char*; |
| 11 |
|
| 12 |
template<typename K, typename V, bool IS_MAP> |
| 13 |
struct HashTable { |
| 14 |
uintptr_t num_buckets; |
| 15 |
uintptr_t capacity; |
| 16 |
uint8_t *occupied; |
| 17 |
MaybeUninit<K> *keys; |
| 18 |
MaybeUninit<V> *vals; |
| 19 |
}; |
| 20 |
|
| 21 |
using MySet = HashTable<Str, char, false>; |
| 22 |
|
| 23 |
using SetCallback = void(*)(Str key); |
| 24 |
|
| 25 |
using MapCallback = void(*)(Str key, uint64_t val); |
| 26 |
|
| 27 |
extern "C" { |
| 28 |
|
| 29 |
MySet *new_set(); |
| 30 |
|
| 31 |
void set_for_each(const MySet *set, SetCallback callback); |
| 32 |
|
| 33 |
HashTable<Str, uint64_t, true> *new_map(); |
| 34 |
|
| 35 |
void map_for_each(const HashTable<Str, uint64_t, true> *map, MapCallback callback); |
| 36 |
|
| 37 |
} // extern "C" |