C Tool Box 0.1.0
Loading...
Searching...
No Matches
ctb_DList.h File Reference
#include "ctb_DListIterator.h"
#include "ctb_DNode.h"
#include <stdbool.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  ctb_DList
 Doubly linked list data structure. More...
 

Typedefs

typedef struct ctb_DList ctb_DList_t
 Doubly linked list type.
 

Functions

ctb_DList_tctb_DList_init (ctb_DList_t *const self)
 Initializes a doubly linked list.
 
void ctb_DList_addByIndex (ctb_DList_t *const self, ctb_DNode_t *const node, size_t const index)
 Adds a node at the specified index.
 
void ctb_DList_addFirst (ctb_DList_t *const self, ctb_DNode_t *const node)
 Adds a node at the beginning.
 
void ctb_DList_addLast (ctb_DList_t *const self, ctb_DNode_t *const node)
 Adds a node at the end.
 
ctb_DNode_tctb_DList_getByIndex (ctb_DList_t *const self, size_t index)
 Returns the node at the specified index.
 
ctb_DNode_tctb_DList_getFirst (ctb_DList_t *const self)
 Returns the first node.
 
ctb_DNode_tctb_DList_getLast (ctb_DList_t *const self)
 Returns the last node.
 
ctb_DNode_tctb_DList_removeByIndex (ctb_DList_t *const self, size_t const index)
 Removes the node at the specified index.
 
ctb_DNode_tctb_DList_removeFirst (ctb_DList_t *const self)
 Removes the first node.
 
ctb_DNode_tctb_DList_removeLast (ctb_DList_t *const self)
 Removes the last node.
 
ctb_DNode_tctb_DList_remove (ctb_DList_t *const self, ctb_DNode_t *const node)
 Removes a node.
 
size_t ctb_DList_getIndexOf (ctb_DList_t *const self, ctb_DNode_t const *const node)
 Returns the index of a node.
 
bool ctb_DList_isEmpty (ctb_DList_t *const self)
 Checks if the doubly linked list is empty.
 
size_t ctb_DList_getSize (ctb_DList_t *const self)
 Returns the size of the doubly linked list.
 
void ctb_DList_clear (ctb_DList_t *const self)
 Clears the doubly linked list.
 
void ctb_DList_forEach (ctb_DList_t *const self, ctb_DListIterator_ForEachOperation_t const operation)
 Applies an operation to each node of the doubly linked list.
 
ctb_DNode_tctb_DList_find (ctb_DList_t *const self, ctb_DListIterator_FindPredicate_t const predicate)
 Finds a node in the doubly linked list that matches a predicate.
 

Function Documentation

◆ ctb_DList_addByIndex()

void ctb_DList_addByIndex ( ctb_DList_t *const self,
ctb_DNode_t *const node,
size_t const index )

Adds a node at the specified index.

Parameters
selfPointer to a doubly linked list
nodePointer to the node to add
indexIndex where to add the node

◆ ctb_DList_addFirst()

void ctb_DList_addFirst ( ctb_DList_t *const self,
ctb_DNode_t *const node )

Adds a node at the beginning.

Parameters
selfPointer to a doubly linked list
nodePointer to the node to add

◆ ctb_DList_addLast()

void ctb_DList_addLast ( ctb_DList_t *const self,
ctb_DNode_t *const node )

Adds a node at the end.

Parameters
selfPointer to a doubly linked list
nodePointer to the node to add

◆ ctb_DList_clear()

void ctb_DList_clear ( ctb_DList_t *const self)

Clears the doubly linked list.

Parameters
selfPointer to a doubly linked list

◆ ctb_DList_find()

ctb_DNode_t * ctb_DList_find ( ctb_DList_t *const self,
ctb_DListIterator_FindPredicate_t const predicate )

Finds a node in the doubly linked list that matches a predicate.

Parameters
selfPointer to a doubly linked list
predicatePredicate to match a node
Returns
Pointer to the first node that matches the predicate, or NULL if no node matches

◆ ctb_DList_forEach()

void ctb_DList_forEach ( ctb_DList_t *const self,
ctb_DListIterator_ForEachOperation_t const operation )

Applies an operation to each node of the doubly linked list.

Parameters
selfPointer to a doubly linked list
operationOperation to apply to each node

◆ ctb_DList_getByIndex()

ctb_DNode_t * ctb_DList_getByIndex ( ctb_DList_t *const self,
size_t index )

Returns the node at the specified index.

Parameters
selfPointer to a doubly linked list
indexIndex of the node to return
Returns
Pointer to the node at the specified index

◆ ctb_DList_getFirst()

ctb_DNode_t * ctb_DList_getFirst ( ctb_DList_t *const self)

Returns the first node.

Parameters
selfPointer to a doubly linked list
Returns
Pointer to the first node

◆ ctb_DList_getIndexOf()

size_t ctb_DList_getIndexOf ( ctb_DList_t *const self,
ctb_DNode_t const *const node )

Returns the index of a node.

Parameters
selfPointer to a doubly linked list
nodePointer to the node
Returns
Index of the node, or SIZE_MAX if the node is not found

◆ ctb_DList_getLast()

ctb_DNode_t * ctb_DList_getLast ( ctb_DList_t *const self)

Returns the last node.

Parameters
selfPointer to a doubly linked list
Returns
Pointer to the last node

◆ ctb_DList_getSize()

size_t ctb_DList_getSize ( ctb_DList_t *const self)

Returns the size of the doubly linked list.

Parameters
selfPointer to a doubly linked list
Returns
Size of the doubly linked list

◆ ctb_DList_init()

ctb_DList_t * ctb_DList_init ( ctb_DList_t *const self)

Initializes a doubly linked list.

Parameters
selfPointer to a doubly linked list
Returns
Pointer to the initialized doubly linked list

◆ ctb_DList_isEmpty()

bool ctb_DList_isEmpty ( ctb_DList_t *const self)

Checks if the doubly linked list is empty.

Parameters
selfPointer to a doubly linked list
Returns
True if the doubly linked list is empty, false otherwise

◆ ctb_DList_remove()

ctb_DNode_t * ctb_DList_remove ( ctb_DList_t *const self,
ctb_DNode_t *const node )

Removes a node.

Parameters
selfPointer to a doubly linked list
nodePointer to the node to remove
Returns
Pointer to the removed node

◆ ctb_DList_removeByIndex()

ctb_DNode_t * ctb_DList_removeByIndex ( ctb_DList_t *const self,
size_t const index )

Removes the node at the specified index.

Parameters
selfPointer to a doubly linked list
indexIndex of the node to remove
Returns
Pointer to the removed node

◆ ctb_DList_removeFirst()

ctb_DNode_t * ctb_DList_removeFirst ( ctb_DList_t *const self)

Removes the first node.

Parameters
selfPointer to a doubly linked list
Returns
Pointer to the removed node

◆ ctb_DList_removeLast()

ctb_DNode_t * ctb_DList_removeLast ( ctb_DList_t *const self)

Removes the last node.

Parameters
selfPointer to a doubly linked list
Returns
Pointer to the removed node