Derive-C
Loading...
Searching...
No Matches
template.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <derive-c/container/vector/trait.h>
#include <derive-c/core/debug/gdb_marker.h>
#include <derive-c/core/debug/memory_tracker.h>
#include <derive-c/core/debug/mutation_tracker.h>
#include <derive-c/core/prelude.h>
#include <derive-c/core/self/def.h>
#include <derive-c/core/self/undef.h>
Include dependency graph for template.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

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...

Macros

#define ITEM   item_t
#define ITEM_DELETE   item_delete
#define ITEM_CLONE   item_clone
#define INPLACE_CAPACITY   8
#define INDEX_TYPE   uint8_t
#define INVARIANT_CHECK(self)

Typedefs

typedef INDEX_TYPE index_t
typedef ITEMitem

Functions

static void item_delete (item_t *self)
static item_t item_clone (item_t const *self)
static SELF new ()
static SELF clone (SELF const *self)
static ITEM const * try_read (SELF const *self, INDEX_TYPE index)
static ITEM const * read (SELF const *self, INDEX_TYPE index)
static ITEMtry_write (SELF *self, INDEX_TYPE index)
static ITEMwrite (SELF *self, INDEX_TYPE index)
static ITEMtry_push (SELF *self, ITEM item)
static bool try_insert_at (SELF *self, INDEX_TYPE at, ITEM const *items, INDEX_TYPE count)
static void remove_at (SELF *self, INDEX_TYPE at, INDEX_TYPE count)
static ITEMpush (SELF *self, ITEM item)
static bool try_pop (SELF *self, ITEM *destination)
static ITEM pop (SELF *self)
static INDEX_TYPE size (SELF const *self)
static void delete (SELF *self)
static bool empty_item (ITEM *const *item)
static ITEMnext (ITER *iter)
static INDEX_TYPE 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 INDEX_TYPE position (ITER_CONST const *iter)
static bool empty (ITER_CONST const *iter)
static ITER_CONST get_iter_const (SELF const *self)
 TRAIT_VECTOR (SELF)

Variables

static const INDEX_TYPE max_size = INPLACE_CAPACITY

Macro Definition Documentation

◆ INDEX_TYPE

#define INDEX_TYPE   uint8_t

Definition at line 46 of file template.h.

◆ INPLACE_CAPACITY

#define INPLACE_CAPACITY   8

Definition at line 42 of file template.h.

◆ INVARIANT_CHECK

#define INVARIANT_CHECK ( self)
Value:
ASSUME(self); \
ASSUME((self->size) <= INPLACE_CAPACITY);
#define INPLACE_CAPACITY
Definition template.h:42
#define ASSUME(expr,...)
Definition macros.h:62

Definition at line 64 of file template.h.

64#define INVARIANT_CHECK(self) \
65 ASSUME(self); \
66 ASSUME((self->size) <= INPLACE_CAPACITY);

◆ ITEM

#define ITEM   item_t

Definition at line 23 of file template.h.

◆ ITEM_CLONE

#define ITEM_CLONE   item_clone

Definition at line 27 of file template.h.

◆ ITEM_DELETE

#define ITEM_DELETE   item_delete

Definition at line 25 of file template.h.

Typedef Documentation

◆ index_t

Definition at line 54 of file template.h.

◆ item

typedef ITEM const* item

Definition at line 213 of file template.h.

Function Documentation

◆ clone()

SELF clone ( SELF const * self)
static

Definition at line 81 of file template.h.

81 {
82 SELF new_self = NS(SELF, new)();
83 new_self.size = self->size;
84
86 self->size * sizeof(ITEM));
87 for (INDEX_TYPE i = 0; i < self->size; i++) {
88 new_self.data[i] = ITEM_CLONE(&self->data[i]);
89 }
90
91 return new_self;
92}
#define ITEM
Definition template.h:58
#define ITEM_CLONE
Definition template.h:29
#define INDEX_TYPE
Definition template.h:46
@ 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_WRITE
#define NS(pre, post)
Definition namespace.h:4
#define SELF
Definition def.h:52
size_t size
Definition template.h:44
ITEM * data
Definition template.h:44
Here is the call graph for this function:

◆ delete()

void delete ( SELF * self)
static

Definition at line 203 of file template.h.

203 {
204 INVARIANT_CHECK(self);
205 for (INDEX_TYPE i = 0; i < self->size; i++) {
206 ITEM_DELETE(&self->data[i]);
207 }
209 self->size * sizeof(ITEM));
210}
#define INVARIANT_CHECK(self)
Definition template.h:142
#define ITEM_DELETE
Definition template.h:27
@ MEMORY_TRACKER_CAP_NONE
Here is the call graph for this function:

◆ empty() [1/2]

bool empty ( ITER const * iter)
static

Definition at line 240 of file template.h.

240 {
241 ASSUME(iter);
242 mutation_version_check(&iter->version);
243 return iter->pos >= iter->vec->size;
244}
static void mutation_version_check(mutation_version const *self)
Here is the call graph for this function:

◆ empty() [2/2]

bool empty ( ITER_CONST const * iter)
static

Definition at line 283 of file template.h.

283 {
284 ASSUME(iter);
285 mutation_version_check(&iter->version);
286 return iter->pos >= iter->vec->size;
287}
Here is the call graph for this function:

◆ empty_item() [1/2]

bool empty_item ( ITEM *const * item)
static

Definition at line 215 of file template.h.

215{ return *item == NULL; }
IV_PAIR const * item
Definition template.h:350
Here is the call graph for this function:

◆ empty_item() [2/2]

bool empty_item ( ITEM const *const * item)
static

Definition at line 258 of file template.h.

258{ return *item == NULL; }
Here is the call graph for this function:

◆ get_iter()

ITER get_iter ( SELF * self)
static

Definition at line 246 of file template.h.

246 {
247 ASSUME(self);
248 return (ITER){.vec = self,
249 .pos = 0,
251}
static mutation_version mutation_tracker_get(mutation_tracker const *self)
mutation_tracker iterator_invalidation_tracker
Definition template.h:139
Here is the call graph for this function:

◆ get_iter_const()

ITER_CONST get_iter_const ( SELF const * self)
static

Definition at line 289 of file template.h.

289 {
290 ASSUME(self);
291 return (ITER_CONST){
292 .vec = self,
293 .pos = 0,
294 .version = mutation_tracker_get(&self->iterator_invalidation_tracker),
295 };
296}
Here is the call graph for this function:

◆ item_clone()

item_t item_clone ( item_t const * self)
static

Definition at line 26 of file template.h.

26{ return *self; }

◆ item_delete()

void item_delete ( item_t * self)
static

Definition at line 24 of file template.h.

24{ (void)self; }

◆ new()

SELF new ( )
static

Definition at line 68 of file template.h.

68 {
69 SELF self = {
70 .size = 0,
71 .derive_c_staticvec = gdb_marker_new(),
72 .iterator_invalidation_tracker = mutation_tracker_new(),
73 };
75 sizeof(ITEM) * INPLACE_CAPACITY);
76 return self;
77}
static gdb_marker gdb_marker_new()
Definition gdb_marker.h:7
static mutation_tracker mutation_tracker_new()
Here is the call graph for this function:

◆ next() [1/2]

ITEM * next ( ITER * iter)
static

Definition at line 223 of file template.h.

223 {
224 ASSUME(iter);
225 mutation_version_check(&iter->version);
226 if (iter->pos < iter->vec->size) {
227 ITEM* item = &iter->vec->data[iter->pos];
228 iter->pos++;
229 return item;
230 }
231 return NULL;
232}
Here is the call graph for this function:

◆ next() [2/2]

ITEM const * next ( ITER_CONST * iter)
static

Definition at line 266 of file template.h.

266 {
267 ASSUME(iter);
268 mutation_version_check(&iter->version);
269 if (iter->pos < iter->vec->size) {
270 ITEM const* item = &iter->vec->data[iter->pos];
271 iter->pos++;
272 return item;
273 }
274 return NULL;
275}
Here is the call graph for this function:

◆ pop()

ITEM pop ( SELF * self)
static

Definition at line 192 of file template.h.

192 {
193 ITEM entry;
194 ASSERT(NS(SELF, try_pop)(self, &entry));
195 return entry;
196}
static bool try_pop(SELF *self, ITEM *destination)
Definition template.h:245
#define ASSERT(expr,...)
Definition macros.h:42
Here is the call graph for this function:

◆ position() [1/2]

INDEX_TYPE position ( ITER const * iter)
static

Definition at line 234 of file template.h.

234 {
235 ASSUME(iter);
236 mutation_version_check(&iter->version);
237 return iter->pos;
238}
Here is the call graph for this function:

◆ position() [2/2]

INDEX_TYPE position ( ITER_CONST const * iter)
static

Definition at line 277 of file template.h.

277 {
278 ASSUME(iter);
279 mutation_version_check(&iter->version);
280 return iter->pos;
281}
Here is the call graph for this function:

◆ push()

ITEM * push ( SELF * self,
ITEM item )
static

Definition at line 173 of file template.h.

173 {
174 ITEM* slot = NS(SELF, try_push)(self, item);
175 ASSERT(slot);
176 return slot;
177}
static ITEM * try_push(SELF *self, ITEM item)
Definition template.h:122
Here is the call graph for this function:

◆ read()

ITEM const * read ( SELF const * self,
INDEX_TYPE index )
static

Definition at line 102 of file template.h.

102 {
103 ITEM const* value = NS(SELF, try_read)(self, index);
104 ASSERT(value);
105 return value;
106}
static VALUE const * try_read(SELF const *self, INDEX index)
Definition template.h:228
Here is the call graph for this function:

◆ remove_at()

void remove_at ( SELF * self,
INDEX_TYPE at,
INDEX_TYPE count )
static

Definition at line 155 of file template.h.

155 {
156 INVARIANT_CHECK(self);
157 ASSERT(at + count <= self->size);
158
159 if (count == 0) {
160 return;
161 }
162
163 for (INDEX_TYPE i = at; i < at + count; i++) {
164 ITEM_DELETE(&self->data[i]);
165 }
166
167 memmove(&self->data[at], &self->data[at + count], (self->size - (at + count)) * sizeof(ITEM));
168 self->size -= count;
170 &self->data[self->size], count * sizeof(ITEM));
171}
static INDEX_TYPE size(SELF const *self)
Definition template.h:275
Here is the call graph for this function:

◆ size()

INDEX_TYPE size ( SELF const * self)
static

Definition at line 198 of file template.h.

198 {
199 INVARIANT_CHECK(self);
200 return self->size;
201}
Here is the call graph for this function:

◆ TRAIT_VECTOR()

TRAIT_VECTOR ( SELF )

◆ try_insert_at()

bool try_insert_at ( SELF * self,
INDEX_TYPE at,
ITEM const * items,
INDEX_TYPE count )
static

Definition at line 136 of file template.h.

137 {
138 INVARIANT_CHECK(self);
139 ASSUME(items);
140 ASSERT(at <= self->size);
142
143 if (self->size + count > INPLACE_CAPACITY) {
144 return false;
145 }
146
148 &self->data[self->size], count * sizeof(ITEM));
149 memmove(&self->data[at + count], &self->data[at], (self->size - at) * sizeof(ITEM));
150 memcpy(&self->data[at], items, count * sizeof(ITEM));
151 self->size += count;
152 return true;
153}
static void mutation_tracker_mutate(mutation_tracker *self)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_pop()

bool try_pop ( SELF * self,
ITEM * destination )
static

Definition at line 179 of file template.h.

179 {
180 INVARIANT_CHECK(self);
182 if (LIKELY(self->size > 0)) {
183 self->size--;
184 *destination = self->data[self->size];
186 &self->data[self->size + 1], sizeof(ITEM));
187 return true;
188 }
189 return false;
190}
#define LIKELY(x)
Definition macros.h:53
Here is the call graph for this function:

◆ try_push()

ITEM * try_push ( SELF * self,
ITEM item )
static

Definition at line 122 of file template.h.

122 {
123 INVARIANT_CHECK(self);
125 if (self->size < INPLACE_CAPACITY) {
126 ITEM* slot = &self->data[self->size];
128 sizeof(ITEM));
129 *slot = item;
130 self->size++;
131 return slot;
132 }
133 return NULL;
134}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_read()

ITEM const * try_read ( SELF const * self,
INDEX_TYPE index )
static

Definition at line 94 of file template.h.

94 {
95 INVARIANT_CHECK(self);
96 if (LIKELY(index < self->size)) {
97 return &self->data[index];
98 }
99 return NULL;
100}
Here is the call graph for this function:

◆ try_write()

ITEM * try_write ( SELF * self,
INDEX_TYPE index )
static

Definition at line 108 of file template.h.

108 {
109 INVARIANT_CHECK(self);
110 if (LIKELY(index < self->size)) {
111 return &self->data[index];
112 }
113 return NULL;
114}
Here is the call graph for this function:

◆ write()

ITEM * write ( SELF * self,
INDEX_TYPE index )
static

Definition at line 116 of file template.h.

116 {
117 ITEM* value = NS(SELF, try_write)(self, index);
118 ASSERT(value);
119 return value;
120}
static VALUE * try_write(SELF *self, INDEX index)
Definition template.h:210
Here is the call graph for this function:

Variable Documentation

◆ max_size

const INDEX_TYPE max_size = INPLACE_CAPACITY
static

Definition at line 79 of file template.h.