libcute 0.1
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions
list.h File Reference
#include "macro.h"
#include "memory/allocator.h"
#include "object/optional.h"
#include "object/result.h"
#include "object/destructor.h"
#include "utility.h"
#include <nostd.h>
#include <stddef.h>
Include dependency graph for list.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cu_List_Node
 Node within a singly linked list. More...
 
struct  cu_List
 Singly linked list container. More...
 

Typedefs

typedef struct cu_List_Node cu_List_Node
 Node within a singly linked list.
 

Enumerations

enum  cu_List_Error {
  CU_LIST_ERROR_NONE = 0 , CU_LIST_ERROR_OOM , CU_LIST_ERROR_INVALID_LAYOUT , CU_LIST_ERROR_INVALID ,
  CU_LIST_ERROR_EMPTY
}
 Error codes returned by list operations. More...
 

Functions

cu_List_Result cu_List_create (cu_Allocator allocator, cu_Layout layout, cu_Destructor_Optional destructor)
 Create an empty list.
 
void cu_List_destroy (cu_List *list)
 Destroy a list and free all nodes.
 
cu_List_Error_Optional cu_List_push_front (cu_List *list, void *elem)
 
cu_List_Error_Optional cu_List_pop_front (cu_List *list, void *out_elem)
 
cu_List_Error_Optional cu_List_insert_after (cu_List *list, cu_List_Node *node, void *elem)
 
cu_List_Error_Optional cu_List_insert_before (cu_List *list, struct cu_List_Node *node, void *elem)
 
bool cu_List_iter (const cu_List *list, cu_List_Node **node, void **out_elem)
 Iterate over the list.
 

Detailed Description

Singly linked list container.

Enumeration Type Documentation

◆ cu_List_Error

Error codes returned by list operations.

Enumerator
CU_LIST_ERROR_NONE 

success

CU_LIST_ERROR_OOM 

out of memory

CU_LIST_ERROR_INVALID_LAYOUT 

invalid element layout

CU_LIST_ERROR_INVALID 

invalid argument

CU_LIST_ERROR_EMPTY 

list has no elements

Function Documentation

◆ cu_List_create()

cu_List_Result cu_List_create ( cu_Allocator  allocator,
cu_Layout  layout,
cu_Destructor_Optional  destructor 
)

Create an empty list.

Parameters
allocatorallocator used for node storage
layoutlayout describing each element
destructoroptional element destructor
Returns
Result containing the created list on success

◆ cu_List_insert_after()

cu_List_Error_Optional cu_List_insert_after ( cu_List list,
cu_List_Node node,
void *  elem 
)

Insert a new element after node.

Here is the caller graph for this function:

◆ cu_List_insert_before()

cu_List_Error_Optional cu_List_insert_before ( cu_List list,
struct cu_List_Node node,
void *  elem 
)

Insert a new element before node.

Here is the call graph for this function:

◆ cu_List_iter()

bool cu_List_iter ( const cu_List list,
cu_List_Node **  node,
void **  out_elem 
)

Iterate over the list.

The iteration state is held in node. Pass NULL for the first call.

Parameters
listlist to iterate
nodecurrent node, updated on success
out_elempointer receiving the element data
Returns
true when another element was produced

◆ cu_List_pop_front()

cu_List_Error_Optional cu_List_pop_front ( cu_List list,
void *  out_elem 
)

Remove the first element and copy it into out_elem.

◆ cu_List_push_front()

cu_List_Error_Optional cu_List_push_front ( cu_List list,
void *  elem 
)

Add an element to the front of the list.