26 const char* username_ptr = self->
username;
33 fprintf(
stream,
"user_id@%p {\n", (
void*)self);
47 fprintf(
stream,
"userdata@%p {\n", (
void*)self);
55#define KEY struct user_id
56#define KEY_EQ user_id_eq
57#define KEY_HASH user_id_hash
58#define KEY_DEBUG user_id_debug
59#define VALUE struct userdata
60#define VALUE_DEBUG userdata_debug
66 DC_SCOPED(user_map) map = user_map_new(stdalloc_get_ref());
68 struct user_id user1 = {.username =
"alice", .uuid = 1001};
69 struct user_id user2 = {.username =
"bob", .uuid = 1002};
71 struct userdata data1 = {.score = 1500, .hashed_password =
"hash1234567890"};
72 struct userdata data2 = {.score = 2000, .hashed_password =
"hash0987654321"};
74 user_map_insert(&map, user1, data1);
75 user_map_insert(&map, user2, data2);
77 struct userdata const* found_data1 = user_map_read(&map, user1);
82 struct userdata const* found_data2 = user_map_read(&map, user2);
86 struct user_id invalid_user = {.username =
"charlie", .uuid = 9999};
87 struct userdata const* not_found = user_map_try_read(&map, invalid_user);
91 fprintf(stdout,
"\n");
99 fprintf(
stream,
"largedata@%p {\n", (
void*)self);
107#define KEY_HASH DC_DEFAULT_HASH
108#define VALUE uint16_t
109#define NAME uuid_to_index_map
114 DC_SCOPED(uuid_to_index_map) map = uuid_to_index_map_new(stdalloc_get_ref());
116 uuid_to_index_map_insert(&map, 1001, 0);
117 uuid_to_index_map_insert(&map, 1002, 1);
118 uuid_to_index_map_insert(&map, 1003, 2);
121 fprintf(stdout,
"\n");
124 {.data =
"First large data"}, {.data =
"Second large data"}, {.data =
"Third large data"}};
127 uint16_t index = *entry.value;
130 fprintf(stdout,
"\n");
135#define KEY_HASH DC_DEFAULT_HASH
136#define VALUE struct largedata
137#define VALUE_DEBUG largedata_debug
138#define NAME ankerl_largedata_map
143 DC_SCOPED(ankerl_largedata_map) map = ankerl_largedata_map_new(stdalloc_get_ref());
145 struct largedata data1 = {.data =
"Ankerl map entry number one"};
146 struct largedata data2 = {.data =
"Ankerl map entry number two"};
147 struct largedata data3 = {.data =
"Ankerl map entry number three"};
149 ankerl_largedata_map_insert(&map, 2001, data1);
150 ankerl_largedata_map_insert(&map, 2002, data2);
151 ankerl_largedata_map_insert(&map, 2003, data3);
155 printf(
"Entry %zu: uuid=%" PRIu64
" data=", count, *entry.key);
157 fprintf(stdout,
"\n");
163 fprintf(stdout,
"\n");
static DC_PUBLIC size_t dc_hash_combine(size_t seed, size_t h)
#define DC_DEFAULT_HASH(obj)
static DC_PUBLIC void dc_debug_fmt_print(dc_debug_fmt fmt, FILE *stream, const char *format,...)
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_new()
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_end(dc_debug_fmt fmt)
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_begin(dc_debug_fmt fmt)
static DC_PUBLIC uint64_t dc_fnv1a_str_const(const char *const *s)
#define DC_FOR_CONST(TYPE, INSTANCE, ITER, ITEM)
static void largedata_debug(struct largedata const *self, dc_debug_fmt fmt, FILE *stream)
static void example_small()
static void example_iteration()
static size_t user_id_hash(struct user_id const *self)
static void userdata_debug(struct userdata const *self, dc_debug_fmt fmt, FILE *stream)
static void example_basic()
static void user_id_debug(struct user_id const *self, dc_debug_fmt fmt, FILE *stream)
static bool user_id_eq(struct user_id const *a, struct user_id const *b)
#define DC_ASSERT(expr,...)
#define DC_SCOPED(type,...)
RAII in C. Call the destructor when the variable goes out of scope.
Debug format helpers for debug printin data structures.
static DC_PUBLIC FILE * stream(SELF *self)