Derive-C
Loading...
Searching...
No Matches
template.h File Reference

Go to the source code of this file.

Data Structures

struct  value_t
struct  SELF
 An allocator that prints to stdout when it allocates or frees memory. More...
struct  IV_PAIR
struct  ITER
struct  IV_PAIR_CONST
struct  ITER_CONST

Macros

#define INDEX_BITS   32
 A vector-backed arena, with support for small indices.
#define VALUE   value_t
#define VALUE_DELETE   value_delete
#define VALUE_CLONE   value_clone
#define VALUE_DEBUG   value_debug
#define CHECK_ACCESS_INDEX(self, index)
#define RESIZE_FACTOR   2
#define SLOT   NS(NAME, slot)
#define SLOT_INDEX_TYPE   INDEX_TYPE
#define SLOT_VALUE   VALUE
#define SLOT_VALUE_CLONE   VALUE_CLONE
#define SLOT_VALUE_CLONE   VALUE_CLONE
#define SLOT_VALUE_DELETE   VALUE_DELETE
#define INTERNAL_NAME   SLOT
#define INVARIANT_CHECK(self)
#define IV_PAIR   NS(SELF, iv)
#define ITER   NS(SELF, iter)
#define IV_PAIR_CONST   NS(SELF, iv_const)
#define ITER_CONST   NS(SELF, iter_const)

Typedefs

typedef IV_PAIR item

Functions

static void VALUE_DELETE (value_t *)
static value_t VALUE_CLONE (value_t const *self)
static void VALUE_DEBUG (VALUE const *, dc_debug_fmt, FILE *)
 DC_STATIC_ASSERT (sizeof(VALUE), "VALUE must be a non-zero sized type")
static DC_PUBLIC SELF new_with_capacity_for (INDEX_TYPE items, ref alloc_ref)
static DC_PUBLIC INDEX insert (SELF *self, VALUE value)
static DC_PUBLIC VALUEtry_write (SELF *self, INDEX index)
static DC_PUBLIC VALUEwrite (SELF *self, INDEX index)
static DC_PUBLIC VALUE const * try_read (SELF const *self, INDEX index)
static DC_PUBLIC VALUE const * read (SELF const *self, INDEX index)
static DC_PUBLIC SELF clone (SELF const *self)
static DC_PUBLIC size_t size (SELF const *self)
static DC_PUBLIC bool full (SELF const *self)
static DC_PUBLIC bool try_remove (SELF *self, INDEX index, VALUE *destination)
static DC_PUBLIC VALUE remove (SELF *self, INDEX index)
static DC_PUBLIC IV_PAIR iv_empty ()
static DC_PUBLIC bool empty_item (IV_PAIR const *item)
static DC_PUBLIC bool empty (ITER const *iter)
static DC_PUBLIC IV_PAIR next (ITER *iter)
static DC_PUBLIC ITER get_iter (SELF *self)
static DC_PUBLIC void delete (SELF *self)
static DC_PUBLIC IV_PAIR_CONST iv_const_empty ()
static DC_PUBLIC bool empty_item (IV_PAIR_CONST const *item)
static DC_PUBLIC bool empty (ITER_CONST const *iter)
static DC_PUBLIC IV_PAIR_CONST next (ITER_CONST *iter)
static DC_PUBLIC ITER_CONST get_iter_const (SELF const *self)
static DC_PUBLIC void debug (SELF const *self, dc_debug_fmt fmt, FILE *stream)
 DC_TRAIT_ARENA (SELF)

Variables

static DC_PUBLIC const size_t max_entries = MAX_INDEX

Macro Definition Documentation

◆ CHECK_ACCESS_INDEX

#define CHECK_ACCESS_INDEX ( self,
index )
Value:
((index).index < (self)->exclusive_end)

Definition at line 51 of file template.h.

◆ INDEX_BITS

#define INDEX_BITS   32

A vector-backed arena, with support for small indices.

Definition at line 15 of file template.h.

◆ INTERNAL_NAME

#define INTERNAL_NAME   SLOT

Definition at line 67 of file template.h.

◆ INVARIANT_CHECK

#define INVARIANT_CHECK ( self)
Value:
DC_ASSUME(self); \
DC_ASSUME((self)->count <= (self)->capacity); \
DC_ASSUME((self)->exclusive_end >= (self)->count); \
DC_ASSUME((self)->count <= MAX_INDEX);
#define DC_ASSUME(expr,...)
Definition panic.h:57

Definition at line 90 of file template.h.

90#define INVARIANT_CHECK(self) \
91 DC_ASSUME(self); \
92 DC_ASSUME((self)->count <= (self)->capacity); \
93 DC_ASSUME((self)->exclusive_end >= (self)->count); \
94 DC_ASSUME((self)->count <= MAX_INDEX);

◆ ITER

#define ITER   NS(SELF, iter)

Definition at line 280 of file template.h.

◆ ITER_CONST

#define ITER_CONST   NS(SELF, iter_const)

Definition at line 366 of file template.h.

◆ IV_PAIR

#define IV_PAIR   NS(SELF, iv)

Definition at line 269 of file template.h.

◆ IV_PAIR_CONST

#define IV_PAIR_CONST   NS(SELF, iv_const)

Definition at line 355 of file template.h.

◆ RESIZE_FACTOR

#define RESIZE_FACTOR   2

Definition at line 55 of file template.h.

◆ SLOT

#define SLOT   NS(NAME, slot)

Definition at line 60 of file template.h.

◆ SLOT_INDEX_TYPE

#define SLOT_INDEX_TYPE   INDEX_TYPE

Definition at line 62 of file template.h.

◆ SLOT_VALUE

#define SLOT_VALUE   VALUE

Definition at line 63 of file template.h.

◆ SLOT_VALUE_CLONE [1/2]

#define SLOT_VALUE_CLONE   VALUE_CLONE

Definition at line 64 of file template.h.

◆ SLOT_VALUE_CLONE [2/2]

#define SLOT_VALUE_CLONE   VALUE_CLONE

Definition at line 64 of file template.h.

◆ SLOT_VALUE_DELETE

#define SLOT_VALUE_DELETE   VALUE_DELETE

Definition at line 66 of file template.h.

◆ VALUE

#define VALUE   value_t

Definition at line 25 of file template.h.

◆ VALUE_CLONE

#define VALUE_CLONE   value_clone

Definition at line 28 of file template.h.

◆ VALUE_DEBUG

#define VALUE_DEBUG   value_debug

Definition at line 30 of file template.h.

◆ VALUE_DELETE

#define VALUE_DELETE   value_delete

Definition at line 26 of file template.h.

Typedef Documentation

◆ item

typedef ITEM const * item
Examples
container/set.c, and container/vector.c.

Definition at line 281 of file template.h.

Function Documentation

◆ clone()

DC_PUBLIC SELF clone ( SELF const * self)
static

Definition at line 201 of file template.h.

201 {
202 INVARIANT_CHECK(self);
203 SLOT* slots = (SLOT*)NS(ALLOC, allocate_zeroed)(self->alloc_ref, self->capacity * sizeof(SLOT));
204
205 for (INDEX_TYPE index = 0; index < self->exclusive_end; index++) {
206 NS(SLOT, clone_from)(&self->slots[index], &slots[index]);
207 }
208
209 return (SELF){
210 .slots = slots,
211 .capacity = self->capacity,
212 .free_list = self->free_list,
213 .exclusive_end = self->exclusive_end,
214 .count = self->count,
215 .alloc_ref = self->alloc_ref,
216 .derive_c_arena_basic = dc_gdb_marker_new(),
217 .iterator_invalidation_tracker = mutation_tracker_new(),
218 };
219}
static DC_PUBLIC void * allocate_zeroed(SELF *self, size_t size)
Definition template.h:117
#define ALLOC
Definition template.h:31
#define SLOT
Definition template.h:65
#define INVARIANT_CHECK(self)
Definition template.h:90
#define SELF
Definition def.h:52
static DC_PUBLIC dc_gdb_marker dc_gdb_marker_new()
Definition gdb_marker.h:8
static DC_PUBLIC mutation_tracker mutation_tracker_new()
#define NS(pre, post)
Definition namespace.h:14
static DC_INTERNAL void clone_from(SELF const *from_slot, SELF *to_slot)
Definition template.h:94

◆ DC_STATIC_ASSERT()

DC_STATIC_ASSERT ( sizeof(VALUE) ,
"VALUE must be a non-zero sized type"  )

◆ DC_TRAIT_ARENA()

DC_TRAIT_ARENA ( SELF )

◆ debug()

DC_PUBLIC void debug ( SELF const * self,
dc_debug_fmt fmt,
FILE * stream )
static

Definition at line 425 of file template.h.

425 {
426 fprintf(stream, DC_EXPAND_STRING(SELF) "@%p {\n", (void*)self);
427 fmt = dc_debug_fmt_scope_begin(fmt);
428 dc_debug_fmt_print(fmt, stream, "capacity: %lu,\n", self->capacity);
429 dc_debug_fmt_print(fmt, stream, "count: %lu,\n", self->count);
430 dc_debug_fmt_print(fmt, stream, "slots: %p,\n", (void*)self->slots);
431
432 dc_debug_fmt_print(fmt, stream, "alloc: ");
433 NS(ALLOC, debug)(NS(NS(ALLOC, ref), deref)(self->alloc_ref), fmt, stream);
434 fprintf(stream, ",\n");
435
436 dc_debug_fmt_print(fmt, stream, "items: [");
437 fmt = dc_debug_fmt_scope_begin(fmt);
438
439 ITER_CONST iter = NS(SELF, get_iter_const)(self);
441 item = NS(ITER_CONST, next)(&iter)) {
442 dc_debug_fmt_print(fmt, stream, "{\n");
443 fmt = dc_debug_fmt_scope_begin(fmt);
444
445 dc_debug_fmt_print(fmt, stream, "key: ");
446 NS(INDEX, debug)(&item.index, fmt, stream);
447 fprintf(stream, ",\n");
448
449 dc_debug_fmt_print(fmt, stream, "value: ");
450 VALUE_DEBUG(item.value, fmt, stream);
451 fprintf(stream, ",\n");
452
453 fmt = dc_debug_fmt_scope_end(fmt);
454 dc_debug_fmt_print(fmt, stream, "},\n");
455 }
456
457 fmt = dc_debug_fmt_scope_end(fmt);
458 dc_debug_fmt_print(fmt, stream, "],\n");
459 fmt = dc_debug_fmt_scope_end(fmt);
460 dc_debug_fmt_print(fmt, stream, "}");
461}
static DC_PUBLIC void debug(SELF const *self, dc_debug_fmt fmt, FILE *stream)
Definition template.h:212
#define VALUE_DEBUG
Definition template.h:41
static DC_PUBLIC IV_PAIR next(ITER *iter)
Definition template.h:355
#define IV_PAIR_CONST
Definition template.h:412
static DC_PUBLIC bool empty_item(IV_PAIR const *item)
Definition template.h:347
#define ITER_CONST
Definition template.h:411
static DC_PUBLIC ITER_CONST get_iter_const(SELF const *self)
Definition template.h:464
IV_PAIR item
Definition template.h:281
static DC_PUBLIC void dc_debug_fmt_print(dc_debug_fmt fmt, FILE *stream, const char *format,...)
Definition fmt.h:32
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_end(dc_debug_fmt fmt)
Definition fmt.h:57
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_begin(dc_debug_fmt fmt)
Definition fmt.h:50
#define DC_EXPAND_STRING(NAME)
Definition namespace.h:6
static DC_PUBLIC FILE * stream(SELF *self)
Definition template.h:108

◆ delete()

DC_PUBLIC void delete ( SELF * self)
static

Definition at line 340 of file template.h.

340 {
341 INVARIANT_CHECK(self);
342 ITER iter = NS(SELF, get_iter)(self);
343
344 for (IV_PAIR entry = NS(ITER, next)(&iter); !NS(ITER, empty_item)(&entry);
345 entry = NS(ITER, next)(&iter)) {
346 VALUE_DELETE(entry.value);
347 }
348
349 NS(ALLOC, deallocate)(self->alloc_ref, self->slots, self->capacity * sizeof(SLOT));
350}
static DC_PUBLIC void deallocate(SELF *self, void *ptr, size_t size)
Definition template.h:127
#define IV_PAIR
Definition template.h:323
#define ITER
Definition template.h:322
static DC_PUBLIC ITER get_iter(SELF *self)
Definition template.h:373
#define VALUE_DELETE
Definition template.h:37
size_t capacity
Definition template.h:72
SLOT * slots
Definition template.h:71
ref alloc_ref
Definition template.h:49

◆ empty() [1/2]

DC_PUBLIC bool empty ( ITER const * iter)
static

Definition at line 291 of file template.h.

291 {
292 DC_ASSUME(iter);
293 mutation_version_check(&iter->version);
294 // JUSTIFY: If no entries are left, then the previous '.._next' call moved
295 // the index to the exclusive end
296 // NOTE: `index + 1 > exclusive_end` implies `index >= exclusive_end`
297 return iter->next_index == INDEX_NONE || iter->next_index >= iter->arena->exclusive_end;
298}
static DC_PUBLIC void mutation_version_check(mutation_version const *self)

◆ empty() [2/2]

DC_PUBLIC bool empty ( ITER_CONST const * iter)
static

Definition at line 382 of file template.h.

382 {
383 DC_ASSUME(iter);
384 mutation_version_check(&iter->version);
385 return iter->next_index == INDEX_NONE || iter->next_index >= iter->arena->exclusive_end;
386}

◆ empty_item() [1/2]

DC_PUBLIC bool empty_item ( IV_PAIR const * item)
static

Definition at line 283 of file template.h.

283{ return item->value == NULL; }

◆ empty_item() [2/2]

DC_PUBLIC bool empty_item ( IV_PAIR_CONST const * item)
static

Definition at line 371 of file template.h.

371 {
372 return item->value == NULL;
373}

◆ full()

DC_PUBLIC bool full ( SELF const * self)
static

Definition at line 226 of file template.h.

226 {
227 INVARIANT_CHECK(self);
228 if (self->capacity == CAPACITY_EXCLUSIVE_UPPER) {
229 if (self->free_list == INDEX_NONE) {
230 return true;
231 }
232 }
233 return false;
234}

◆ get_iter()

DC_PUBLIC ITER get_iter ( SELF * self)
static

Definition at line 326 of file template.h.

326 {
327 INVARIANT_CHECK(self);
328 INDEX_TYPE index = 0;
329 while (index < INDEX_NONE && index < self->exclusive_end && !self->slots[index].present) {
330 index++;
331 }
332
333 return (ITER){
334 .arena = self,
335 .next_index = index,
337 };
338}
static DC_PUBLIC mutation_version mutation_tracker_get(mutation_tracker const *self)
mutation_tracker iterator_invalidation_tracker
Definition template.h:87

◆ get_iter_const()

DC_PUBLIC ITER_CONST get_iter_const ( SELF const * self)
static

Definition at line 411 of file template.h.

411 {
412 INVARIANT_CHECK(self);
413 INDEX_TYPE index = 0;
414 while (index < INDEX_NONE && index < self->exclusive_end && !self->slots[index].present) {
415 index++;
416 }
417
418 return (ITER_CONST){
419 .arena = self,
420 .next_index = index,
421 .version = mutation_tracker_get(&self->iterator_invalidation_tracker),
422 };
423}

◆ insert()

DC_PUBLIC INDEX insert ( SELF * self,
VALUE value )
static

Definition at line 121 of file template.h.

121 {
122 INVARIANT_CHECK(self);
123 DC_ASSERT(self->count < MAX_INDEX,
124 "Arena is full, cannot insert {count=%lu, max_index=%lu, value=%s}",
125 (size_t)self->count, (size_t)MAX_INDEX, DC_DEBUG(VALUE_DEBUG, &value));
126
128 if (self->free_list != INDEX_NONE) {
129 INDEX_TYPE free_index = self->free_list;
130 SLOT* slot = &self->slots[free_index];
131 DC_ASSUME(!slot->present);
132
133 self->free_list = slot->next_free;
134 NS(SLOT, fill)(slot, value);
135
136 self->count++;
137 return (INDEX){.index = free_index};
138 }
139
140 if (self->exclusive_end == self->capacity) {
141 DC_ASSERT(self->capacity <= (CAPACITY_EXCLUSIVE_UPPER / RESIZE_FACTOR),
142 "Cannot increase capacity for new item {capacity=%lu, max_capacity=%lu, item=%s}",
143 (size_t)self->capacity, (size_t)CAPACITY_EXCLUSIVE_UPPER,
144 DC_DEBUG(VALUE_DEBUG, &value));
145 size_t old_size = self->capacity * sizeof(SLOT);
146 self->capacity *= RESIZE_FACTOR;
147 SLOT* new_alloc = (SLOT*)NS(ALLOC, reallocate)(self->alloc_ref, self->slots, old_size,
148 self->capacity * sizeof(SLOT));
149 self->slots = new_alloc;
150
151 for (size_t index = self->exclusive_end; index < self->capacity; index++) {
152 NS(SLOT, memory_tracker_empty)(&self->slots[index]);
153 }
154 }
155
156 INDEX_TYPE new_index = (INDEX_TYPE)self->exclusive_end;
157 SLOT* slot = &self->slots[new_index];
158 NS(SLOT, fill)(slot, value);
159
160 self->count++;
161 self->exclusive_end++;
162 return (INDEX){.index = new_index};
163}
static DC_PUBLIC void * reallocate(SELF *self, void *ptr, size_t old_size, size_t new_size)
Definition template.h:137
#define RESIZE_FACTOR
Definition template.h:55
#define DC_DEBUG(DEBUG_FN, DEBUG_PTR)
Definition dump.h:92
static DC_PUBLIC void mutation_tracker_mutate(mutation_tracker *self)
#define DC_ASSERT(expr,...)
Definition panic.h:37
INDEX_TYPE free_list
Definition template.h:79
size_t exclusive_end
Definition template.h:79
size_t count
Definition template.h:78
static DC_INTERNAL void fill(SELF *slot, SLOT_VALUE value)
Definition template.h:88
static DC_INTERNAL void memory_tracker_empty(SELF const *slot)
Definition template.h:64

◆ iv_const_empty()

DC_PUBLIC IV_PAIR_CONST iv_const_empty ( )
static

Definition at line 362 of file template.h.

362 {
363 return (IV_PAIR_CONST){.index = (INDEX){.index = INDEX_NONE}, .value = NULL};
364}

◆ iv_empty()

DC_PUBLIC IV_PAIR iv_empty ( )
static

Definition at line 276 of file template.h.

276 {
277 return (IV_PAIR){.index = (INDEX){.index = INDEX_NONE}, .value = NULL};
278}

◆ new_with_capacity_for()

DC_PUBLIC SELF new_with_capacity_for ( INDEX_TYPE items,
ref alloc_ref )
static

Definition at line 96 of file template.h.

96 {
97 DC_ASSERT(items > 0, "Cannot create arena with capacity for 0 items {items=%lu}",
98 (size_t)items);
99 size_t capacity = dc_math_next_power_of_2(items);
100 DC_ASSERT(capacity <= CAPACITY_EXCLUSIVE_UPPER,
101 "Index capacity too large {capacity=%lu, max_capacity=%lu}", (size_t)capacity,
102 (size_t)CAPACITY_EXCLUSIVE_UPPER);
103 SLOT* slots = (SLOT*)NS(ALLOC, allocate_zeroed)(alloc_ref, capacity * sizeof(SLOT));
104
105 for (INDEX_TYPE index = 0; index < capacity; index++) {
106 NS(SLOT, memory_tracker_empty)(&slots[index]);
107 }
108
109 return (SELF){
110 .slots = slots,
111 .capacity = (INDEX_TYPE)capacity,
112 .free_list = INDEX_NONE,
113 .exclusive_end = 0,
114 .count = 0,
115 .alloc_ref = alloc_ref,
116 .derive_c_arena_basic = dc_gdb_marker_new(),
117 .iterator_invalidation_tracker = mutation_tracker_new(),
118 };
119}
static DC_INLINE DC_CONST size_t dc_math_next_power_of_2(size_t x)
Definition math.h:46

◆ next() [1/2]

DC_PUBLIC IV_PAIR next ( ITER * iter)
static

Definition at line 300 of file template.h.

300 {
301 DC_ASSUME(iter);
303
304 while (iter->next_index < INDEX_NONE && iter->next_index < iter->arena->exclusive_end) {
305 IV_PAIR result = {
306 .index = (INDEX){.index = iter->next_index},
307 .value = &iter->arena->slots[iter->next_index].value,
308 };
309
310 iter->next_index++;
311 // advance to next present entry
312 while (iter->next_index < INDEX_NONE && iter->next_index < iter->arena->exclusive_end &&
313 !iter->arena->slots[iter->next_index].present) {
314 iter->next_index++;
315 }
316
317 if (result.value && result.value == &iter->arena->slots[result.index.index].value &&
318 iter->arena->slots[result.index.index].present) {
319 return result;
320 }
321 }
322
323 return NS(SELF, iv_empty)();
324}
static DC_PUBLIC IV_PAIR iv_empty()
Definition template.h:343
INDEX_TYPE next_index
Definition template.h:327
mutation_version version
Definition template.h:328
SELF * arena
Definition template.h:326
VALUE * value
Definition template.h:340
INDEX index
Definition template.h:339
VALUE value
Definition template.h:78

◆ next() [2/2]

DC_PUBLIC IV_PAIR_CONST next ( ITER_CONST * iter)
static

Definition at line 388 of file template.h.

388 {
389 DC_ASSUME(iter);
391
392 while (iter->next_index < INDEX_NONE && iter->next_index < iter->arena->exclusive_end) {
393 IV_PAIR_CONST result = {
394 .index = (INDEX){.index = iter->next_index},
395 .value = &iter->arena->slots[iter->next_index].value,
396 };
397 iter->next_index++;
398 while (iter->next_index != INDEX_NONE && iter->next_index < iter->arena->exclusive_end &&
399 !iter->arena->slots[iter->next_index].present) {
400 iter->next_index++;
401 }
402
403 if (result.value && iter->arena->slots[result.index.index].present) {
404 return result;
405 }
406 }
407
408 return NS(SELF, iv_const_empty)();
409}
static DC_PUBLIC IV_PAIR_CONST iv_const_empty()
Definition template.h:432
INDEX_TYPE next_index
Definition template.h:416
mutation_version version
Definition template.h:417
SELF const * arena
Definition template.h:415
VALUE const * value
Definition template.h:429

◆ read()

DC_PUBLIC VALUE const * read ( SELF const * self,
INDEX index )
static

Definition at line 195 of file template.h.

195 {
196 VALUE const* value = NS(SELF, try_read)(self, index);
197 DC_ASSERT(value, "Cannot read item, index not found {index=%lu}", (size_t)index.index);
198 return value;
199}
#define VALUE
Definition template.h:35
static DC_PUBLIC VALUE const * try_read(SELF const *self, INDEX index)
Definition template.h:180

◆ remove()

DC_PUBLIC VALUE remove ( SELF * self,
INDEX index )
static

Definition at line 259 of file template.h.

259 {
260 INVARIANT_CHECK(self);
262
263 VALUE value;
264 DC_ASSERT(NS(SELF, try_remove)(self, index, &value),
265 "Failed to remove item, index not found {index=%lu}", (size_t)index.index);
266 return value;
267}
static DC_PUBLIC bool try_remove(SELF *self, INDEX index, VALUE *destination)
Definition template.h:264

◆ size()

DC_PUBLIC size_t size ( SELF const * self)
static

Definition at line 221 of file template.h.

221 {
222 INVARIANT_CHECK(self);
223 return self->count;
224}

◆ try_read()

DC_PUBLIC VALUE const * try_read ( SELF const * self,
INDEX index )
static

Definition at line 183 of file template.h.

183 {
184 INVARIANT_CHECK(self);
185 if (!CHECK_ACCESS_INDEX(self, index)) {
186 return NULL;
187 }
188 SLOT* slot = &self->slots[index.index];
189 if (!slot->present) {
190 return NULL;
191 }
192 return &slot->value;
193}
#define CHECK_ACCESS_INDEX(self, index)
Definition template.h:51

◆ try_remove()

DC_PUBLIC bool try_remove ( SELF * self,
INDEX index,
VALUE * destination )
static

Definition at line 238 of file template.h.

238 {
239 INVARIANT_CHECK(self);
241
242 if (!CHECK_ACCESS_INDEX(self, index)) {
243 return false;
244 }
245
246 SLOT* entry = &self->slots[index.index];
247 if (entry->present) {
248 *destination = entry->value;
249
250 NS(SLOT, set_empty)(entry, self->free_list);
251
252 self->free_list = index.index;
253 self->count--;
254 return true;
255 }
256 return false;
257}
static DC_INTERNAL void set_empty(SELF *slot, SLOT_INDEX_TYPE next_free)
Definition template.h:73

◆ try_write()

DC_PUBLIC VALUE * try_write ( SELF * self,
INDEX index )
static

Definition at line 165 of file template.h.

165 {
166 INVARIANT_CHECK(self);
167 if (!CHECK_ACCESS_INDEX(self, index)) {
168 return NULL;
169 }
170 SLOT* slot = &self->slots[index.index];
171 if (!slot->present) {
172 return NULL;
173 }
174 return &slot->value;
175}

◆ VALUE_CLONE()

value_t VALUE_CLONE ( value_t const * self)
static

Definition at line 29 of file template.h.

29{ return *self; }

◆ VALUE_DEBUG()

void VALUE_DEBUG ( VALUE const * ,
dc_debug_fmt ,
FILE *  )
static

Definition at line 31 of file template.h.

31{}

◆ VALUE_DELETE()

void VALUE_DELETE ( value_t * )
static

Definition at line 27 of file template.h.

27{}

◆ write()

DC_PUBLIC VALUE * write ( SELF * self,
INDEX index )
static

Definition at line 177 of file template.h.

177 {
178 VALUE* value = NS(SELF, try_write)(self, index);
179 DC_ASSERT(value, "Cannot write item, index not found {index=%lu}", (size_t)index.index);
180 return value;
181}
static DC_PUBLIC VALUE * try_write(SELF *self, INDEX index)
Definition template.h:205

Variable Documentation

◆ max_entries

DC_PUBLIC const size_t max_entries = MAX_INDEX
static

Definition at line 236 of file template.h.