#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <derive-c/core/helpers.h>
#include <derive-c/core/panic.h>
#include <derive-c/core/alloc/def.h>
#include <derive-c/core/self/def.h>
#include <derive-c/core/alloc/undef.h>
#include <derive-c/core/self/undef.h>
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 *UNUSED(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 ITEM * | next (ITER *iter) |
static size_t | position (ITER const *iter) |
static bool | empty (ITER const *iter) |
static ITER | get_iter (SELF *self) |
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) |
◆ ITEM
◆ ITEM_CLONE
◆ ITEM_DELETE
◆ clone()
Definition at line 99 of file template.h.
99 {
103 for (size_t index = 0; index < self->size; index++) {
105 }
107 .size = self->size,
108 .capacity = self->capacity,
110 .alloc = self->alloc,
111 };
112}
static void * malloc(SELF *self, size_t size)
#define DEBUG_ASSERT(expr)
static ITEM * data(SELF *self)
◆ data()
◆ delete()
void delete |
( |
SELF * | self | ) |
|
|
static |
Definition at line 240 of file template.h.
240 {
243 for (
size_t i = 0; i < self->
size; i++) {
245 }
247 }
248}
static void free(SELF *self, void *ptr)
◆ empty() [1/2]
bool empty |
( |
ITER const * | iter | ) |
|
|
static |
Definition at line 272 of file template.h.
272 {
274 return iter->pos >= iter->vec->size;
275}
◆ empty() [2/2]
bool empty |
( |
ITER_CONST const * | iter | ) |
|
|
static |
Definition at line 308 of file template.h.
308 {
310 return iter->pos >= iter->vec->size;
311}
◆ get_iter()
ITER get_iter |
( |
SELF * | self | ) |
|
|
static |
Definition at line 277 of file template.h.
277 {
279 return (ITER){
280 .vec = self,
281 .pos = 0,
282 };
283}
◆ get_iter_const()
ITER_CONST get_iter_const |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 313 of file template.h.
313 {
315 return (ITER_CONST){
316 .vec = self,
317 .pos = 0,
318 };
319}
◆ insert_at()
void insert_at |
( |
SELF * | self, |
|
|
size_t | at, |
|
|
ITEM const * | items, |
|
|
size_t | count ) |
|
static |
Definition at line 142 of file template.h.
142 {
146
147 if (count == 0) {
148 return;
149 }
150
152
153 memmove(&self->
data[at + count], &self->
data[at], (self->
size - at) *
sizeof(
ITEM));
154 memcpy(&self->
data[at], items, count *
sizeof(
ITEM));
156}
static INDEX_TYPE size(SELF const *self)
static void reserve(SELF *self, size_t new_capacity_for)
◆ item_clone()
◆ item_delete()
void item_delete |
( |
item_t * | UNUSEDt | ) |
|
|
static |
◆ new()
Definition at line 45 of file template.h.
45 {
47 .size = 0,
48 .capacity = 0,
49 .data = NULL,
50 .alloc = alloc,
51 };
52 return temp;
53}
◆ new_with_capacity()
SELF new_with_capacity |
( |
size_t | capacity, |
|
|
ALLOC * | alloc ) |
|
static |
Definition at line 55 of file template.h.
55 {
56 if (capacity == 0) {
57 return NS(
SELF,
new)(alloc);
58 }
59
63 .size = 0,
64 .capacity = capacity,
66 .alloc = alloc,
67 };
68}
◆ new_with_defaults()
SELF new_with_defaults |
( |
size_t | size, |
|
|
ITEM | default_item, |
|
|
ALLOC * | alloc ) |
|
static |
Definition at line 70 of file template.h.
70 {
73
74 data[0] = default_item;
75 for (
size_t i = 1; i <
size; i++) {
77 }
78 }
84 .alloc = alloc,
85 };
86}
◆ next() [1/2]
ITEM * next |
( |
ITER * | iter | ) |
|
|
static |
Definition at line 257 of file template.h.
257 {
259 if (iter->pos < iter->vec->size) {
260 ITEM* item = &iter->vec->data[iter->pos];
261 iter->pos++;
262 return item;
263 }
264 return NULL;
265}
◆ next() [2/2]
ITEM const * next |
( |
ITER_CONST * | iter | ) |
|
|
static |
Definition at line 293 of file template.h.
293 {
295 if (iter->pos < iter->vec->size) {
296 ITEM const* item = &iter->vec->data[iter->pos];
297 iter->pos++;
298 return item;
299 }
300 return NULL;
301}
◆ pop()
Definition at line 220 of file template.h.
220 {
223 return entry;
224}
static bool try_pop(SELF *self, ITEM *destination)
◆ pop_front()
Definition at line 226 of file template.h.
226 {
232 return entry;
233}
◆ position() [1/2]
size_t position |
( |
ITER const * | iter | ) |
|
|
static |
Definition at line 267 of file template.h.
267 {
269 return iter->pos;
270}
◆ position() [2/2]
size_t position |
( |
ITER_CONST const * | iter | ) |
|
|
static |
Definition at line 303 of file template.h.
303 {
305 return iter->pos;
306}
◆ push()
Definition at line 174 of file template.h.
174 {
178 size_t new_capacity;
179 if (self->
data == NULL) {
181
182
183
184
185 new_capacity = 8;
187 } else {
188
189
190
192 new_data =
194 }
197 self->
data = new_data;
198 }
200 *entry = item;
202 return entry;
203}
static void * realloc(SELF *self, void *ptr, size_t size)
◆ read()
ITEM const * read |
( |
SELF const * | self, |
|
|
size_t | index ) |
|
static |
Definition at line 122 of file template.h.
122 {
125 return item;
126}
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 158 of file template.h.
158 {
161
162 if (count == 0) {
163 return;
164 }
165
166 for (size_t i = at; i < at + count; i++) {
168 }
169
170 memmove(&self->
data[at], &self->
data[at + count], (self->
size - (at + count)) *
sizeof(
ITEM));
172}
◆ reserve()
void reserve |
( |
SELF * | self, |
|
|
size_t | new_capacity ) |
|
static |
Definition at line 88 of file template.h.
88 {
94 self->
data = new_data;
96 }
97}
◆ size()
size_t size |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 235 of file template.h.
235 {
237 return self->size;
238}
◆ try_pop()
bool try_pop |
( |
SELF * | self, |
|
|
ITEM * | destination ) |
|
static |
Definition at line 205 of file template.h.
205 {
209 *destination = self->
data[self->
size];
210 return true;
211 }
212 return false;
213}
◆ try_read()
ITEM const * try_read |
( |
SELF const * | self, |
|
|
size_t | index ) |
|
static |
Definition at line 114 of file template.h.
114 {
117 return &self->data[index];
118 }
119 return NULL;
120}
◆ try_write()
ITEM * try_write |
( |
SELF * | self, |
|
|
size_t | index ) |
|
static |
Definition at line 128 of file template.h.
128 {
131 return &self->
data[index];
132 }
133 return NULL;
134}
◆ write()
ITEM * write |
( |
SELF * | self, |
|
|
size_t | index ) |
|
static |
Definition at line 136 of file template.h.
136 {
139 return item;
140}
static VALUE * try_write(SELF *self, INDEX index)