container.h
Go to the documentation of this file.
1 #pragma once
2 
15 
16 #include <inttypes.h>
17 
22 typedef struct{
26  void *data;
28  uint64_t size;
29 } cr8r_base_ft;
30 
32 typedef enum{
33  CR8R_WALK_CONTINUE = 0,
34  CR8R_WALK_SKIP_CHILDREN = 1,
35  CR8R_WALK_STOP = 2
37 
43 uint64_t cr8r_default_new_size(cr8r_base_ft*, uint64_t cap);
44 
50 uint64_t cr8r_default_bump_size(cr8r_base_ft*, uint64_t cap);
51 
59 void *cr8r_default_resize(cr8r_base_ft*, void *p, uint64_t cap);
60 
67 void *cr8r_default_resize_pass(cr8r_base_ft*, void *p, uint64_t cap);
68 
78 int cr8r_default_cmp(const cr8r_base_ft*, const void *a, const void *b);
79 
84 void cr8r_default_swap(cr8r_base_ft*, void *a, void *b);
85 
89 uint64_t cr8r_default_hash_u64(const cr8r_base_ft*, const void*);
90 
97 uint64_t cr8r_default_hash(const cr8r_base_ft*, const void*);
98 
102 uint64_t cr8r_default_hash_cstr(const cr8r_base_ft*, const void*);
103 
105 int cr8r_default_cmp_u64(const cr8r_base_ft*, const void*, const void*);
106 
108 int cr8r_default_cmp_u8(const cr8r_base_ft*, const void*, const void*);
109 
111 int cr8r_default_cmp_i64(const cr8r_base_ft*, const void*, const void*);
112 
114 int cr8r_default_cmp_cstr(const cr8r_base_ft*, const void*, const void*);
115 
119 int cr8r_default_replace(cr8r_base_ft*, void *_a, void *_b);
120 
127 
136 
145 
155 
159 void cr8r_default_copy_cstr(cr8r_base_ft*, void*, const void*);
160 
162 uint64_t cr8r_powmod(uint64_t b, uint64_t e, uint64_t n);
163 
165 uint64_t cr8r_pow_u64(uint64_t b, uint64_t e);
166 
168 #define CR8R_FLA_CAST(T, p) (((union{__typeof__(p) data; T a;})(p)).a)
169 
176 #define CR8R_OUTER(ptr, T, memb) ((T*)((void*)(ptr) - offsetof(T, memb)))
177 
184 #define CR8R_OUTER_S(ptr, ft) (((void*)(ptr) - (ft)->base.size))
185 
192 #define CR8R_INNER(ptr, T, memb) (((void*)(ptr) + offsetof(T, memb)))
193 
200 #define CR8R_INNER_S(ptr, ft) (((void*)(ptr) + (ft)->base.size))
201 
203 #if !defined(DOXYGEN) && __has_c_attribute(clang::no_sanitize)
204 #define CR8R_ATTR_NO_SAN(...) [[clang::no_sanitize(__VA_ARGS__)]]
205 #else
206 #define CR8R_ATTR_NO_SAN(...)
207 #endif
208 
int cr8r_default_replace(cr8r_base_ft *, void *_a, void *_b)
"Default" ft->add implementation (for avl trees and hash tables)
uint64_t cr8r_default_bump_size(cr8r_base_ft *, uint64_t cap)
"Default" increase-by-one ft->new_size implementation (for vectors)
void * cr8r_default_resize(cr8r_base_ft *, void *p, uint64_t cap)
"Default" ft->resize implementation (for vectors)
int cr8r_default_cmp_u8(const cr8r_base_ft *, const void *, const void *)
"Default" ft->cmp implementation for uint8_t
void cr8r_default_free(cr8r_base_ft *, void *)
ft->del implementation (for hash tables or vectors)
int cr8r_default_cmp_i64(const cr8r_base_ft *, const void *, const void *)
"Default" ft->cmp implementation for int64_t
uint64_t cr8r_default_hash(const cr8r_base_ft *, const void *)
"Default" ft->hash implementation (for hash tables)
void cr8r_default_free_sla(cr8r_base_ft *, void *)
ft->free implementation (for avl trees or circular lists)
void * cr8r_default_alloc_sla(cr8r_base_ft *)
ft->alloc implementation (for avl trees or circular lists)
cr8r_walk_decision
Enum to allow a callee/visitor to control the behavior of a tree traversal.
Definition: container.h:32
uint64_t cr8r_default_hash_cstr(const cr8r_base_ft *, const void *)
"Default" ft->hash implementation for null terminated strings (for hash tables)
void * cr8r_default_resize_pass(cr8r_base_ft *, void *p, uint64_t cap)
"Default" do-nothing ft->resize implementation (for vectors)
uint64_t cr8r_pow_u64(uint64_t b, uint64_t e)
Raise b to the power of e using binary exponentiation.
int cr8r_default_cmp_u64(const cr8r_base_ft *, const void *, const void *)
"Default" ft->cmp implementation for uint64_t
void cr8r_default_swap(cr8r_base_ft *, void *a, void *b)
"Default" ft->swap implementation (for vectors)
uint64_t cr8r_default_hash_u64(const cr8r_base_ft *, const void *)
"Default" ft->hash implementation for uint64_t (for hash tables)
int cr8r_default_cmp(const cr8r_base_ft *, const void *a, const void *b)
"Default" ft->cmp implementation
void cr8r_default_free_pass(cr8r_base_ft *, void *)
ft->free implementation (for avl trees or circular lists) that does nothing
int cr8r_default_cmp_cstr(const cr8r_base_ft *, const void *, const void *)
"Default" ft->cmp implementation for null terminated strings
uint64_t cr8r_powmod(uint64_t b, uint64_t e, uint64_t n)
Raise b to the power of e modulo n using binary exponentiation.
void cr8r_default_copy_cstr(cr8r_base_ft *, void *, const void *)
ft->copy implementation for null terminated strings
uint64_t cr8r_default_new_size(cr8r_base_ft *, uint64_t cap)
"Default" ft->new_size implementation (for vectors)
Base function table for all Crater containers.
Definition: container.h:22
uint64_t size
how large each element is, in bytes
Definition: container.h:28
void * data
Custom "class" data which is passed to the callbacks in this table.
Definition: container.h:26