Go to the source code of this file.
|
static void | key_delete (key_t *UNUSED(self)) |
static key_t | key_clone (key_t const *self) |
static bool | key_eq (key_t const *key_1, key_t const *key_2) |
static size_t | key_hash (key_t const *key) |
static void | value_delete (value_t *UNUSED(self)) |
static value_t | value_clone (value_t const *self) |
static SELF | new_with_capacity_for (size_t capacity, ALLOC *alloc) |
static SELF | new (ALLOC *alloc) |
static SELF | clone (SELF const *self) |
static void | delete (SELF *self) |
static VALUE * | insert (SELF *self, KEY key, VALUE value) |
static void | extend_capacity_for (SELF *self, size_t expected_items) |
static VALUE * | try_insert (SELF *self, KEY key, VALUE value) |
static VALUE * | try_write (SELF *self, KEY key) |
static VALUE * | write (SELF *self, KEY key) |
static VALUE const * | try_read (SELF const *self, KEY key) |
static VALUE const * | read (SELF const *self, KEY key) |
static bool | try_remove (SELF *self, KEY key, VALUE *destination) |
static VALUE | remove (SELF *self, KEY key) |
static void | delete_entry (SELF *self, KEY key) |
static size_t | size (SELF const *self) |
static KV_PAIR const * | next (ITER *iter) |
static bool | empty (ITER const *iter) |
static ITER | get_iter (SELF *self) |
static KV_PAIR_CONST const * | next (ITER_CONST *iter) |
static bool | empty (ITER_CONST const *iter) |
static ITER_CONST | get_iter_const (SELF const *self) |
◆ KEY
◆ KEY_CLONE
◆ KEY_DELETE
◆ KEY_ENTRY
#define KEY_ENTRY NS(SELF, key_entry) |
◆ KEY_EQ
◆ KEY_HASH
◆ KV_PAIR
◆ KV_PAIR_CONST
#define KV_PAIR_CONST NS(SELF, kv_const) |
◆ VALUE
◆ VALUE_CLONE
◆ VALUE_DELETE
◆ clone()
Definition at line 114 of file template.h.
114 {
116
117
118
119
120
121
122
126
127 for (size_t i = 0; i < self->capacity; i++) {
128 if (self->keys[i].present) {
129 KEY_ENTRY const* old_entry = &self->keys[i];
131 .present = true,
134 };
136 }
137 }
138
140 .capacity = self->capacity,
141 .items = self->items,
142 .keys = keys,
143 .values = values,
144 .alloc = self->alloc,
145 };
146}
static void * malloc(SELF *self, size_t size)
static void * calloc(SELF *self, size_t count, size_t size)
#define DEBUG_ASSERT(expr)
uint16_t distance_from_desired
◆ delete()
void delete |
( |
SELF * | self | ) |
|
|
static |
Definition at line 394 of file template.h.
394 {
397
398 for (
size_t i = 0; i < self->
capacity; i++) {
402 }
403 }
404
407}
static void free(SELF *self, void *ptr)
static ITER get_iter(SELF *self)
◆ delete_entry()
void delete_entry |
( |
SELF * | self, |
|
|
KEY | key ) |
|
static |
Definition at line 337 of file template.h.
337 {
340}
static VALUE remove(SELF *self, INDEX index)
◆ empty() [1/2]
bool empty |
( |
ITER const * | iter | ) |
|
|
static |
Definition at line 376 of file template.h.
376 {
378 return iter->index >= iter->map->capacity;
379}
◆ empty() [2/2]
bool empty |
( |
ITER_CONST const * | iter | ) |
|
|
static |
Definition at line 441 of file template.h.
441 {
443 return iter->index >= iter->map->capacity;
444}
◆ extend_capacity_for()
void extend_capacity_for |
( |
SELF * | self, |
|
|
size_t | expected_items ) |
|
static |
Definition at line 152 of file template.h.
152 {
155 if (target_capacity > self->
capacity) {
157 for (
size_t index = 0; index < self->
capacity; index++) {
161 }
162 }
165 *self = new_map;
166 }
167}
static size_t apply_capacity_policy(size_t capacity)
static INDEX insert(SELF *self, VALUE value)
static SELF new_with_capacity_for(INDEX_TYPE items, ALLOC *alloc)
◆ get_iter()
ITER get_iter |
( |
SELF * | self | ) |
|
|
static |
Definition at line 381 of file template.h.
381 {
383 size_t first_index = 0;
384 while (first_index < self->capacity && !self->
keys[first_index].
present) {
385 first_index++;
386 }
387 return (ITER){
388 .map = self,
389 .index = first_index,
390 .curr = (
KV_PAIR){.key = NULL, .value = NULL},
391 };
392}
◆ get_iter_const()
ITER_CONST get_iter_const |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 446 of file template.h.
446 {
448 size_t first_index = 0;
449 while (first_index < self->capacity && !self->keys[first_index].present) {
450 first_index++;
451 }
452 return (ITER_CONST){
453 .map = self,
454 .index = first_index,
456 };
457}
◆ insert()
Definition at line 222 of file template.h.
222 {
225 return value_ptr;
226}
static VALUE * try_insert(SELF *self, KEY key, VALUE value)
◆ key_clone()
◆ key_delete()
void key_delete |
( |
key_t * | UNUSEDself | ) |
|
|
static |
◆ key_eq()
bool key_eq |
( |
key_t const * | key_1, |
|
|
key_t const * | key_2 ) |
|
static |
Definition at line 27 of file template.h.
27{ return key_1->x == key_2->x; }
◆ key_hash()
size_t key_hash |
( |
key_t const * | key | ) |
|
|
static |
◆ new()
Definition at line 110 of file template.h.
110 {
112}
static size_t const INITIAL_CAPACITY
◆ new_with_capacity_for()
SELF new_with_capacity_for |
( |
size_t | capacity, |
|
|
ALLOC * | alloc ) |
|
static |
Definition at line 91 of file template.h.
91 {
95
96
97
102 .capacity = real_capacity,
103 .items = 0,
104 .keys = keys,
105 .values = values,
106 .alloc = alloc,
107 };
108}
◆ next() [1/2]
KV_PAIR const * next |
( |
ITER * | iter | ) |
|
|
static |
Definition at line 362 of file template.h.
362 {
364 if (iter->index < iter->map->capacity) {
365 iter->curr = (
KV_PAIR){.key = &iter->map->keys[iter->index].key,
366 .value = &iter->map->values[iter->index]};
367 iter->index++;
368 while (iter->index < iter->map->capacity && !iter->map->keys[iter->index].present) {
369 iter->index++;
370 }
371 return &iter->curr;
372 }
373 return NULL;
374}
◆ next() [2/2]
Definition at line 427 of file template.h.
427 {
429 if (iter->index < iter->map->capacity) {
430 iter->curr = (
KV_PAIR_CONST){.key = &iter->map->keys[iter->index].key,
431 .value = &iter->map->values[iter->index]};
432 iter->index++;
433 while (iter->index < iter->map->capacity && !iter->map->keys[iter->index].present) {
434 iter->index++;
435 }
436 return &iter->curr;
437 }
438 return NULL;
439}
◆ read()
Definition at line 270 of file template.h.
270 {
273 return value;
274}
static VALUE const * try_read(SELF const *self, INDEX index)
◆ remove()
Definition at line 331 of file template.h.
331 {
334 return value;
335}
static bool try_remove(SELF *self, INDEX index, VALUE *destination)
◆ size()
size_t size |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 342 of file template.h.
342 {
344 return self->items;
345}
◆ try_insert()
Definition at line 169 of file template.h.
169 {
173 }
174
175 uint16_t distance_from_desired = 0;
178 VALUE* placed_entry = NULL;
179 for (;;) {
182
185 return NULL;
186 }
187
189 KEY switch_key = entry->
key;
192
195 self->
values[index] = value;
196
197 key = switch_key;
198 distance_from_desired = switch_distance_from_desired;
199 value = switch_value;
200
201 if (!placed_entry) {
202 placed_entry = &self->
values[index];
203 }
204 }
205
206 distance_from_desired++;
208 } else {
212 self->
values[index] = value;
213 if (!placed_entry) {
214 placed_entry = &self->
values[index];
215 }
217 return placed_entry;
218 }
219 }
220}
static size_t modulus_power_of_2_capacity(size_t index, size_t capacity)
static void extend_capacity_for(SELF *self, size_t expected_items)
◆ try_read()
Definition at line 252 of file template.h.
252 {
256
257 for (;;) {
261 return &self->values[index];
262 }
264 } else {
265 return NULL;
266 }
267 }
268}
◆ try_remove()
bool try_remove |
( |
SELF * | self, |
|
|
KEY | key, |
|
|
VALUE * | destination ) |
|
static |
Definition at line 276 of file template.h.
276 {
280
281 for (;;) {
286
287 *destination = self->
values[index];
289
290
291
292
293
294
295
296 size_t free_index = index;
298
301
303 free_entry->
key = check_entry->
key;
306
307 free_index = check_index;
308 free_entry = check_entry;
309
311 check_entry = &self->
keys[check_index];
312 }
313
314
315
316
317
318
319
321
322 return true;
323 }
325 } else {
326 return false;
327 }
328 }
329}
◆ try_write()
Definition at line 228 of file template.h.
228 {
232
233 for (;;) {
237 return &self->
values[index];
238 }
240 } else {
241 return NULL;
242 }
243 }
244}
◆ value_clone()
◆ value_delete()
void value_delete |
( |
value_t * | UNUSEDself | ) |
|
|
static |
◆ write()
Definition at line 246 of file template.h.
246 {
249 return value;
250}
static VALUE * try_write(SELF *self, INDEX index)