#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <derive-c/core.h>
#include <derive-c/panic.h>
#include <derive-c/self.h>
Go to the source code of this file.
◆ CHECK_ACCESS_INDEX
#define CHECK_ACCESS_INDEX |
( |
| self, |
|
|
| index ) |
Value:(index.index < self->exclusive_end)
Definition at line 57 of file template.h.
◆ INDEX
◆ INDEX_BITS
A vector-backed arena, with support for small indices.
Definition at line 15 of file template.h.
◆ IV_PAIR
◆ IV_PAIR_CONST
#define IV_PAIR_CONST NAME(SELF, iv_const) |
◆ RESIZE_FACTOR
◆ SLOT
#define V derive_c_parameter_value |
◆ V_DELETE
#define V_DELETE derive_c_parameter_value_delete |
◆ delete()
static void delete |
( |
SELF * | self | ) |
|
|
static |
Definition at line 319 of file template.h.
319 {
326 }
327 }
328
330}
static bool empty(ITER const *iter)
static ITER get_iter(SELF *self)
static IV_PAIR next(ITER *iter)
#define DEBUG_ASSERT(expr)
◆ delete_entry()
static bool delete_entry |
( |
SELF * | self, |
|
|
INDEX | index ) |
|
static |
Definition at line 237 of file template.h.
237 {
240 return false;
241 }
242
250 return true;
251 }
252 return false;
253}
#define CHECK_ACCESS_INDEX(self, index)
◆ empty() [1/2]
static bool empty |
( |
ITER const * | iter | ) |
|
|
static |
Definition at line 273 of file template.h.
273 {
275
276
277
278 return iter->next_index == INDEX_NONE || iter->next_index >= iter->arena->exclusive_end;
279}
◆ empty() [2/2]
static bool empty |
( |
ITER_CONST const * | iter | ) |
|
|
static |
Definition at line 353 of file template.h.
353 {
355 return iter->next_index == INDEX_NONE || iter->next_index >= iter->arena->exclusive_end;
356}
◆ full()
static bool full |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 199 of file template.h.
199 {
202 if (self->free_list == INDEX_NONE) {
203 return true;
204 }
205 }
206 return false;
207}
◆ get_iter()
static ITER get_iter |
( |
SELF * | self | ) |
|
|
static |
Definition at line 305 of file template.h.
305 {
307 INDEX_TYPE index = 0;
308 while (index < INDEX_NONE && index < self->exclusive_end && !self->
slots[index].
present) {
309 index++;
310 }
311
312 return (ITER){
313 .arena = self,
314 .next_index = index,
315 .pos = 0,
316 };
317}
◆ get_iter_const()
static ITER_CONST get_iter_const |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 382 of file template.h.
382 {
384 INDEX_TYPE index = 0;
385 while (index < INDEX_NONE && index < self->exclusive_end && !self->slots[index].present) {
386 index++;
387 }
388
389 return (ITER_CONST){
390 .arena = self,
391 .next_index = index,
392 .pos = 0,
393 };
394}
◆ insert()
Definition at line 114 of file template.h.
114 {
124 return (
INDEX){.index = free_index};
125 }
126
132 self->
slots = new_alloc;
133 }
134
141 return (
INDEX){.index = new_index};
142}
◆ new_with_capacity_for()
static SELF new_with_capacity_for |
( |
INDEX_TYPE | items | ) |
|
|
static |
Definition at line 99 of file template.h.
99 {
106 .slots = slots,
107 .capacity = (INDEX_TYPE)capacity,
108 .free_list = INDEX_NONE,
109 .exclusive_end = 0,
110 .count = 0,
111 };
112}
static size_t next_power_of_2(size_t x)
◆ next() [1/2]
Definition at line 281 of file template.h.
281 {
283
285 return (
IV_PAIR){.index = (
INDEX){.index = INDEX_NONE}, .value = NULL};
286 } else {
288 .value = &iter->arena->slots[iter->next_index].value};
289 iter->next_index++;
290 while (iter->next_index < INDEX_NONE && iter->next_index < iter->arena->exclusive_end &&
291 !iter->arena->slots[iter->next_index].present) {
292 iter->next_index++;
293 }
294
295 iter->pos++;
296 return out;
297 }
298}
◆ next() [2/2]
Definition at line 358 of file template.h.
358 {
360
363 } else {
365 .value = &iter->arena->slots[iter->next_index].value};
366 iter->next_index++;
367 while (iter->next_index != INDEX_NONE && iter->next_index < iter->arena->exclusive_end &&
368 !iter->arena->slots[iter->next_index].present) {
369 iter->next_index++;
370 }
371
372 iter->pos++;
373 return out;
374 }
375}
◆ position() [1/2]
static size_t position |
( |
ITER const * | iter | ) |
|
|
static |
Definition at line 300 of file template.h.
300 {
302 return iter->pos;
303}
◆ position() [2/2]
static size_t position |
( |
ITER_CONST const * | iter | ) |
|
|
static |
Definition at line 377 of file template.h.
377 {
379 return iter->pos;
380}
◆ read()
static V const * read |
( |
SELF const * | self, |
|
|
INDEX | index ) |
|
static |
Definition at line 174 of file template.h.
174 {
177 return value;
178}
static V const * try_read(SELF const *self, INDEX index)
◆ remove()
Definition at line 231 of file template.h.
231 {
234 return value;
235}
static bool try_remove(SELF *self, INDEX index, V *destination)
◆ shallow_clone()
static SELF shallow_clone |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 180 of file template.h.
180 {
182 SLOT* slots = (
SLOT*)malloc(self->capacity *
sizeof(
SLOT));
184 memcpy(slots, self->slots, self->exclusive_end *
sizeof(
SLOT));
186 .slots = slots,
187 .capacity = self->capacity,
188 .free_list = self->free_list,
189 .exclusive_end = self->exclusive_end,
190 .count = self->count,
191 };
192}
◆ size()
static INDEX_TYPE size |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 194 of file template.h.
194 {
196 return self->count;
197}
◆ try_read()
static V const * try_read |
( |
SELF const * | self, |
|
|
INDEX | index ) |
|
static |
Definition at line 162 of file template.h.
162 {
165 return NULL;
166 }
169 return NULL;
170 }
172}
◆ try_remove()
static bool try_remove |
( |
SELF * | self, |
|
|
INDEX | index, |
|
|
V * | destination ) |
|
static |
Definition at line 212 of file template.h.
212 {
215 return false;
216 }
217
220 *destination = entry->
value;
225 return true;
226 } else {
227 return false;
228 }
229}
◆ try_write()
Definition at line 144 of file template.h.
144 {
147 return NULL;
148 }
151 return NULL;
152 }
154}
◆ write()
Definition at line 156 of file template.h.
156 {
159 return value;
160}
static V * try_write(SELF *self, INDEX index)
◆ iv_const_empty
Initial value:= {
.index = {.index = INDEX_NONE},
.value = NULL,
}
Definition at line 341 of file template.h.
341 {
342 .index = {.index = INDEX_NONE},
343 .value = NULL,
344};
◆ iv_empty
Initial value:= {
.index = {.index = INDEX_NONE},
.value = NULL,
}
Definition at line 261 of file template.h.
261 {
262 .index = {.index = INDEX_NONE},
263 .value = NULL,
264};
◆ max_capacity
◆ max_index
size_t max_index = MAX_INDEX |
|
static |