cll.h
Go to the documentation of this file.
1 #pragma once
2 
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 #include <stdbool.h>
17 
18 #include <crater/container.h>
19 #include <crater/sla.h>
20 
26 typedef struct cr8r_cll_node cr8r_cll_node;
31  char data[];
32 };
33 
40 typedef struct{
45  void *(*alloc)(cr8r_base_ft*);
51  void (*del)(cr8r_base_ft*, void *p);
54  void (*copy)(cr8r_base_ft*, void *dest, const void *src);
57  int (*cmp)(const cr8r_base_ft*, const void *a, const void *b);
58 } cr8r_cll_ft;
59 
60 
74  void *data, uint64_t size,
75  void *(*alloc)(cr8r_base_ft*),
76  void (*del)(cr8r_base_ft*, void*),
77  void (*copy)(cr8r_base_ft*, void *dest, const void *src),
78  int (*cmp)(const cr8r_base_ft*, const void*, const void*)
79 );
80 
99  cr8r_sla *sla, uint64_t size, uint64_t reserve,
100  void (*copy)(cr8r_base_ft*, void *dest, const void *src),
101  int (*cmp)(const cr8r_base_ft*, const void*, const void*)
102 );
103 
104 
111 
116 
122 
129 cr8r_cll_node *cr8r_cll_from(cr8r_cll_ft*, uint64_t len, const void *a);
130 
131 
138 bool cr8r_cll_pushl(cr8r_cll_node **self, cr8r_cll_ft*, const void *val);
139 
146 bool cr8r_cll_popl(cr8r_cll_node **self, cr8r_cll_ft*, void *out);
147 
154 bool cr8r_cll_pushr(cr8r_cll_node **self, cr8r_cll_ft*, const void *val);
155 
164 bool cr8r_cll_popr(cr8r_cll_node **self, cr8r_cll_ft*, void *out);
165 
166 
173 bool cr8r_cll_filtered(cr8r_cll_node **dest, const cr8r_cll_node *src, cr8r_cll_ft*, bool (*pred)(const void*));
174 
179 void cr8r_cll_filter(cr8r_cll_node **self, cr8r_cll_ft*, bool (*pred)(const void*));
180 
190 bool cr8r_cll_mapped(cr8r_cll_node **dest, const cr8r_cll_node *src, cr8r_cll_ft *dest_ft, void (*f)(void *o, const void *e));
191 
197 void cr8r_cll_forEach(cr8r_cll_node*, cr8r_cll_ft*, void (*f)(void*));
198 
207 
208 
214 bool cr8r_cll_all(const cr8r_cll_node*, cr8r_cll_ft*, bool (*pred)(const void*));
215 
223 bool cr8r_cll_any(const cr8r_cll_node*, cr8r_cll_ft*, bool (*pred)(const void*));
224 
225 
232 
247 void *cr8r_cll_foldr(const cr8r_cll_node*, cr8r_cll_ft*, void *init, void *(*f)(void *acc, const void *e));
248 
249 
255 
262 
267 
273 
bool cr8r_cll_pushr(cr8r_cll_node **self, cr8r_cll_ft *, const void *val)
Add a node with a given value at the end of the list.
void cr8r_cll_delete(cr8r_cll_node *, cr8r_cll_ft *)
Delete a list.
cr8r_cll_node * cr8r_cll_combine(cr8r_cll_node *a, cr8r_cll_node *b, cr8r_cll_ft *)
Stitch together two lists, one after the other.
bool cr8r_cll_mapped(cr8r_cll_node **dest, const cr8r_cll_node *src, cr8r_cll_ft *dest_ft, void(*f)(void *o, const void *e))
Create a new list by applying a transformation function to every element in a list.
cr8r_cll_node * cr8r_cll_new(cr8r_cll_ft *, const void *data)
Allocate a new list node and initialize it with given data.
cr8r_cll_node * cr8r_cll_lsearch(cr8r_cll_node *, cr8r_cll_ft *, const void *e)
Find the first node in a list with an element matching a given element according to ft->cmp.
cr8r_cll_node * cr8r_cll_sorted(const cr8r_cll_node *, cr8r_cll_ft *)
Create a sorted copy of a list.
void * cr8r_cll_foldr(const cr8r_cll_node *, cr8r_cll_ft *, void *init, void *(*f)(void *acc, const void *e))
Perform a right fold on a list.
cr8r_cll_node * cr8r_cll_reversed(const cr8r_cll_node *, cr8r_cll_ft *)
Creates a reversed copy of a list.
cr8r_cll_node * cr8r_cll_copy(const cr8r_cll_node *, cr8r_cll_ft *)
Create a copy of a list.
bool cr8r_cll_filtered(cr8r_cll_node **dest, const cr8r_cll_node *src, cr8r_cll_ft *, bool(*pred)(const void *))
Create a new list from the subsequence of a given list satisfying a predicate.
void cr8r_cll_reverse(cr8r_cll_node **self, cr8r_cll_ft *)
Reverse a list in place.
bool cr8r_cll_popl(cr8r_cll_node **self, cr8r_cll_ft *, void *out)
Remove the first node in the list.
bool cr8r_cll_pushl(cr8r_cll_node **self, cr8r_cll_ft *, const void *val)
Add a node with a given value at the beginning of the list.
bool cr8r_cll_all(const cr8r_cll_node *, cr8r_cll_ft *, bool(*pred)(const void *))
Test if a predicate holds for all elements in a list.
void cr8r_cll_filter(cr8r_cll_node **self, cr8r_cll_ft *, bool(*pred)(const void *))
Filter a list in place by deleting all nodes that don't match a predicate.
void cr8r_cll_forEach(cr8r_cll_node *, cr8r_cll_ft *, void(*f)(void *))
Execute a given function on each element in a list.
bool cr8r_cll_any(const cr8r_cll_node *, cr8r_cll_ft *, bool(*pred)(const void *))
Test if a predicate holds for any element in a list.
cr8r_cll_node * cr8r_cll_from(cr8r_cll_ft *, uint64_t len, const void *a)
Create a list from an array.
bool cr8r_cll_ft_initsla(cr8r_cll_ft *, cr8r_sla *sla, uint64_t size, uint64_t reserve, void(*copy)(cr8r_base_ft *, void *dest, const void *src), int(*cmp)(const cr8r_base_ft *, const void *, const void *))
Convenience function to initialize a cr8r_cll_ft and associated slab allocator.
void cr8r_cll_sort(cr8r_cll_node **self, cr8r_cll_ft *)
Sort a list in place.
bool cr8r_cll_popr(cr8r_cll_node **self, cr8r_cll_ft *, void *out)
Remove the first node in the list.
bool cr8r_cll_ft_init(cr8r_cll_ft *, void *data, uint64_t size, void *(*alloc)(cr8r_base_ft *), void(*del)(cr8r_base_ft *, void *), void(*copy)(cr8r_base_ft *, void *dest, const void *src), int(*cmp)(const cr8r_base_ft *, const void *, const void *))
Convenience function to initialize a cr8r_cll_ft.
Base function table for all Crater containers.
Definition: container.h:22
Function table for linked list.
Definition: cll.h:40
cr8r_base_ft base
Base function table values (data and size)
Definition: cll.h:42
A circular linked list node, or an entire circular linked list by synecdoche Note that a pointer to t...
Definition: cll.h:27
char data[]
flexible length array holding element
Definition: cll.h:31
cr8r_cll_node * next
pointer to the next node in the list
Definition: cll.h:29
Slab allocator.
Definition: sla.h:22