cr8r_cll_ft Struct Reference

Function table for linked list. More...

#include <cll.h>

Data Fields

cr8r_base_ft base
 Base function table values (data and size)
 
void *(* alloc )(cr8r_base_ft *)
 allocate a new node. More...
 
void(* del )(cr8r_base_ft *, void *p)
 deallocate a node, first cleaning up anything owned by its element if necessary. More...
 
void(* copy )(cr8r_base_ft *, void *dest, const void *src)
 copy an element of the vector. More...
 
int(* cmp )(const cr8r_base_ft *, const void *a, const void *b)
 compare two elements of the vector. More...
 

Detailed Description

Function table for linked list.

Imagine this struct as the class of the linked list. This struct specifies the size of the elements in a list in bytes, as well as how to perform necessary operations (compare, copy, etc). Remember that function tables must be initialized manually. In particular, the cr8r_vec_default_* functions can be used as decent defaults, but must be explicitly set.

Definition at line 40 of file cll.h.

Field Documentation

◆ alloc

void*(* cr8r_cll_ft::alloc) (cr8r_base_ft *)

allocate a new node.

should allocate offsetof(cr8r_cll_node, data) + data->size bytes. the slab allocator in this library is a good option for this.

Definition at line 45 of file cll.h.

◆ del

void(* cr8r_cll_ft::del) (cr8r_base_ft *, void *p)

deallocate a node, first cleaning up anything owned by its element if necessary.

to be safe, the allocation scheme should either zero out allocated memory before returning it OR not have elements own anything, since if neither of these things is done it's possible for this function to try to clean up a pointer in uninitialized memory, which is Very Bad.

Definition at line 51 of file cll.h.

◆ copy

void(* cr8r_cll_ft::copy) (cr8r_base_ft *, void *dest, const void *src)

copy an element of the vector.

Can be NULL if memcpy is sufficient, otherwise this function must perform the role of memcpy plus whatever else it needs to do.

Definition at line 54 of file cll.h.

◆ cmp

int(* cr8r_cll_ft::cmp) (const cr8r_base_ft *, const void *a, const void *b)

compare two elements of the vector.

cr8r_default_cmp is a suitable default if needed. should return <0 if a < b, 0 if a == b, and >0 if a > b. should not return INT_MIN.

Definition at line 57 of file cll.h.


The documentation for this struct was generated from the following file: