Go to the source code of this file.
|
| struct | item_t |
| | A queue comprised of an extendable circular buffer. More...
|
| struct | SELF |
| | An allocator that prints to stdout when it allocates or frees memory. More...
|
|
| static void | item_delete (item_t *t) |
| static item_t | item_clone (item_t const *i) |
| static SELF | new (ALLOC *alloc) |
| static SELF | new_with_capacity (size_t capacity, ALLOC *alloc) |
| static SELF | new_with_defaults (size_t size, ITEM default_item, ALLOC *alloc) |
| static void | reserve (SELF *self, size_t new_capacity) |
| static SELF | clone (SELF const *self) |
| static ITEM const * | try_read (SELF const *self, size_t index) |
| static ITEM const * | read (SELF const *self, size_t index) |
| static ITEM * | try_write (SELF *self, size_t index) |
| static ITEM * | write (SELF *self, size_t index) |
| static void | insert_at (SELF *self, size_t at, ITEM const *items, size_t count) |
| static void | remove_at (SELF *self, size_t at, size_t count) |
| static ITEM * | push (SELF *self, ITEM item) |
| static bool | try_pop (SELF *self, ITEM *destination) |
| static ITEM * | data (SELF *self) |
| static ITEM | pop (SELF *self) |
| static ITEM | pop_front (SELF *self) |
| static size_t | size (SELF const *self) |
| static void | delete (SELF *self) |
| static void | transfer_reverse (SELF *source, SELF *target, size_t to_move) |
| static bool | empty_item (ITEM *const *item) |
| static ITEM * | next (ITER *iter) |
| static size_t | position (ITER const *iter) |
| static bool | empty (ITER const *iter) |
| static ITER | get_iter (SELF *self) |
| static bool | empty_item (ITEM const *const *item) |
| static ITEM const * | next (ITER_CONST *iter) |
| static size_t | position (ITER_CONST const *iter) |
| static bool | empty (ITER_CONST const *iter) |
| static ITER_CONST | get_iter_const (SELF const *self) |
| | TRAIT_VECTOR (SELF) |
◆ INVARIANT_CHECK
| #define INVARIANT_CHECK |
( |
| self | ) |
|
Value:
ASSUME((self)->
size <= (self)->capacity); \
ASSUME((self->alloc)); \
ASSUME(
WHEN(!((self)->
data), (self)->capacity == 0 && (self)->
size == 0));
static INDEX_TYPE size(SELF const *self)
static ITEM * data(SELF *self)
Definition at line 52 of file template.h.
52#define INVARIANT_CHECK(self) \
53 ASSUME(self); \
54 ASSUME((self)->size <= (self)->capacity); \
55 ASSUME((self->alloc)); \
56 ASSUME(WHEN(!((self)->data), (self)->capacity == 0 && (self)->size == 0));
◆ ITEM
◆ ITEM_CLONE
◆ ITEM_DELETE
◆ index_t
◆ item
◆ clone()
Definition at line 130 of file template.h.
130 {
134 for (size_t index = 0; index < self->size; index++) {
136 }
138 (self->capacity - self->size) *
sizeof(
ITEM));
140 .size = self->size,
141 .capacity = self->capacity,
143 .alloc = self->alloc,
146 };
147}
static void * malloc(SELF *self, size_t size)
#define INVARIANT_CHECK(self)
static gdb_marker gdb_marker_new()
@ MEMORY_TRACKER_LVL_CONTAINER
static void memory_tracker_set(memory_tracker_level level, memory_tracker_capability cap, const volatile void *addr, size_t size)
@ MEMORY_TRACKER_CAP_NONE
static mutation_tracker mutation_tracker_new()
◆ data()
◆ delete()
| void delete |
( |
SELF * | self | ) |
|
|
static |
Definition at line 287 of file template.h.
287 {
290 for (
size_t i = 0; i < self->
size; i++) {
292
293
296 }
297
298
299
303 }
304}
static void free(SELF *self, void *ptr)
@ MEMORY_TRACKER_CAP_WRITE
◆ empty() [1/2]
| bool empty |
( |
ITER const * | iter | ) |
|
|
static |
Definition at line 372 of file template.h.
372 {
375 return iter->pos >= iter->vec->size;
376}
static void mutation_version_check(mutation_version const *self)
◆ empty() [2/2]
| bool empty |
( |
ITER_CONST const * | iter | ) |
|
|
static |
Definition at line 416 of file template.h.
416 {
419 return iter->pos >= iter->vec->size;
420}
◆ empty_item() [1/2]
| bool empty_item |
( |
ITEM *const * | item | ) |
|
|
static |
◆ empty_item() [2/2]
| bool empty_item |
( |
ITEM const *const * | item | ) |
|
|
static |
◆ get_iter()
| ITER get_iter |
( |
SELF * | self | ) |
|
|
static |
Definition at line 378 of file template.h.
378 {
380 return (ITER){
381 .vec = self,
382 .pos = 0,
384 };
385}
static mutation_version mutation_tracker_get(mutation_tracker const *self)
mutation_tracker iterator_invalidation_tracker
◆ get_iter_const()
| ITER_CONST get_iter_const |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 422 of file template.h.
422 {
424 return (ITER_CONST){
425 .vec = self,
426 .pos = 0,
428 };
429}
◆ insert_at()
| void insert_at |
( |
SELF * | self, |
|
|
size_t | at, |
|
|
ITEM const * | items, |
|
|
size_t | count ) |
|
static |
Definition at line 177 of file template.h.
177 {
182
183 if (count == 0) {
184 return;
185 }
186
190 memmove(&self->
data[at + count], &self->
data[at], (self->
size - at) *
sizeof(
ITEM));
191 memcpy(&self->
data[at], items, count *
sizeof(
ITEM));
193}
static void reserve(SELF *self, size_t new_capacity_for)
static void mutation_tracker_mutate(mutation_tracker *self)
◆ item_clone()
◆ item_delete()
| void item_delete |
( |
item_t * | t | ) |
|
|
static |
◆ new()
Definition at line 58 of file template.h.
58 {
60 .size = 0,
61 .capacity = 0,
62 .data = NULL,
63 .alloc = alloc,
66 };
67 return self;
68}
◆ new_with_capacity()
| SELF new_with_capacity |
( |
size_t | capacity, |
|
|
ALLOC * | alloc ) |
|
static |
Definition at line 70 of file template.h.
70 {
71 if (capacity == 0) {
72 return NS(
SELF,
new)(alloc);
73 }
74
78 capacity *
sizeof(
ITEM));
80 .size = 0,
81 .capacity = capacity,
83 .alloc = alloc,
86 };
87}
◆ new_with_defaults()
| SELF new_with_defaults |
( |
size_t | size, |
|
|
ITEM | default_item, |
|
|
ALLOC * | alloc ) |
|
static |
Definition at line 89 of file template.h.
89 {
92
93 data[0] = default_item;
94 for (
size_t i = 1; i <
size; i++) {
96 }
97 }
103 .alloc = alloc,
106 };
107}
◆ next() [1/2]
| ITEM * next |
( |
ITER * | iter | ) |
|
|
static |
Definition at line 354 of file template.h.
354 {
357
358 if (iter->pos < iter->vec->size) {
359 ITEM*
item = &iter->vec->data[iter->pos];
360 iter->pos++;
362 }
363 return NULL;
364}
◆ next() [2/2]
| ITEM const * next |
( |
ITER_CONST * | iter | ) |
|
|
static |
Definition at line 399 of file template.h.
399 {
402 if (iter->pos < iter->vec->size) {
403 ITEM const*
item = &iter->vec->data[iter->pos];
404 iter->pos++;
406 }
407 return NULL;
408}
◆ pop()
Definition at line 264 of file template.h.
264 {
267 return entry;
268}
static bool try_pop(SELF *self, ITEM *destination)
◆ pop_front()
Definition at line 270 of file template.h.
270 {
279 return entry;
280}
◆ position() [1/2]
| size_t position |
( |
ITER const * | iter | ) |
|
|
static |
Definition at line 366 of file template.h.
366 {
369 return iter->pos;
370}
◆ position() [2/2]
| size_t position |
( |
ITER_CONST const * | iter | ) |
|
|
static |
Definition at line 410 of file template.h.
410 {
413 return iter->pos;
414}
◆ push()
Definition at line 214 of file template.h.
214 {
217
219 size_t new_capacity;
220 if (self->
data == NULL) {
222
223
224
225
226 new_capacity = 8;
227 } else {
228
229
230
232 }
234 }
235
238
242 return entry;
243}
◆ read()
| ITEM const * read |
( |
SELF const * | self, |
|
|
size_t | index ) |
|
static |
Definition at line 157 of file template.h.
157 {
161}
static VALUE const * try_read(SELF const *self, INDEX index)
◆ remove_at()
| void remove_at |
( |
SELF * | self, |
|
|
size_t | at, |
|
|
size_t | count ) |
|
static |
Definition at line 195 of file template.h.
195 {
199
200 if (count == 0) {
201 return;
202 }
203
204 for (size_t i = at; i < at + count; i++) {
206 }
207
208 memmove(&self->
data[at], &self->
data[at + count], (self->
size - (at + count)) *
sizeof(
ITEM));
212}
◆ reserve()
| void reserve |
( |
SELF * | self, |
|
|
size_t | new_capacity ) |
|
static |
Definition at line 109 of file template.h.
109 {
111 if (new_capacity > self->
capacity) {
112 const size_t capacity_increase = new_capacity - self->
capacity;
113 const size_t uninit_elements = self->
capacity - self->
size;
114
115
117 &self->
data[self->
size], uninit_elements *
sizeof(
ITEM));
118
122 self->
data = new_data;
125 (uninit_elements + capacity_increase) *
sizeof(
ITEM));
127 }
128}
static void * realloc(SELF *self, void *ptr, size_t size)
◆ size()
| size_t size |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 282 of file template.h.
282 {
284 return self->size;
285}
◆ TRAIT_VECTOR()
◆ transfer_reverse()
| void transfer_reverse |
( |
SELF * | source, |
|
|
SELF * | target, |
|
|
size_t | to_move ) |
|
static |
Moves to_move items from the beginning of source, to the end of target, shuffling elements in source forward appropriately.
- Used for deque rebalancing
index: 0 1 2 3 4 5
source: [5, 4, 3, 2, 1, 0]
target: [6, 7, 8, 9]
Becomes:
index: 0 1 2 3 4 5
source: [3, 2, 1, 0]
target: [4, 5, 6, 7, 8, 9]
Definition at line 321 of file template.h.
321 {
324
326
330
331 for (size_t i = 0; i < to_move; i++) {
332 target->
data[to_move - 1 - i] = source->
data[i];
333 }
334
335 memmove(source->
data, &source->
data[to_move], (source->
size - to_move) *
sizeof(
ITEM));
336
337 source->
size -= to_move;
338 target->
size += to_move;
341}
◆ try_pop()
| bool try_pop |
( |
SELF * | self, |
|
|
ITEM * | destination ) |
|
static |
Definition at line 245 of file template.h.
245 {
248
251 *destination = self->
data[self->
size];
254 return true;
255 }
256 return false;
257}
◆ try_read()
| ITEM const * try_read |
( |
SELF const * | self, |
|
|
size_t | index ) |
|
static |
Definition at line 149 of file template.h.
149 {
152 return &self->data[index];
153 }
154 return NULL;
155}
◆ try_write()
| ITEM * try_write |
( |
SELF * | self, |
|
|
size_t | index ) |
|
static |
Definition at line 163 of file template.h.
163 {
166 return &self->
data[index];
167 }
168 return NULL;
169}
◆ write()
| ITEM * write |
( |
SELF * | self, |
|
|
size_t | index ) |
|
static |
Definition at line 171 of file template.h.
171 {
175}
static VALUE * try_write(SELF *self, INDEX index)