MGE General C Library - Full Internal Documentation  v1.6.8
Library of general C functions.
sllist.h File Reference

Singly linked list header file. More...

#include <portability.h>
Include dependency graph for sllist.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sllistnode
 Singly linked list node. More...
 

Macros

#define for_each_sll_node(focus, head)    for (focus = head; focus != NULL; focus = focus->next)
 Iterate over the list. More...
 

Functions

struct sllistnodeadd_head_sll_node (struct sllistnode *head, const void *object, size_t objsize)
 Add a node to the start of the singly linked list. More...
 
struct sllistnodeadd_tail_sll_node (struct sllistnode *head, const void *object, size_t objsize)
 Add a node to the tail of the singly linked list. More...
 
void * find_sll_node (struct sllistnode *head, const void *searchobj, int(*comp)(const void *, const void *))
 Find a node. More...
 
static struct sllistnodefind_next_sll_node (struct sllistnode *focus)
 Find the next node in the list. More...
 
struct sllistnodefree_sllist (struct sllistnode *head)
 Free the entire list. More...
 

Detailed Description

Singly linked list header file.

Header file for singly linked lists in the libmgec shared library.

Author
Copyright (C) 2016-2019, 2021 Mark Grant

Released under the GPLv3 only.
SPDX-License-Identifier: GPL-3.0-only

Version
v1.0.8 ==== 03/12/2021

Macro Definition Documentation

◆ for_each_sll_node

#define for_each_sll_node (   focus,
  head 
)     for (focus = head; focus != NULL; focus = focus->next)

Iterate over the list.

Parameters
focusThe current node in focus.
headThe head of the list.

Function Documentation

◆ add_head_sll_node()

struct sllistnode* add_head_sll_node ( struct sllistnode head,
const void *  object,
size_t  objsize 
)

Add a node to the start of the singly linked list.

On error mge_errno will be set.

Parameters
headA pointer to the current root node or NULL if the list is not yet started.
objectThe object to attach to the node.
objsizeThe size of the attached object.
Returns
head, a pointer to the new root node or NULL on error

◆ add_tail_sll_node()

struct sllistnode* add_tail_sll_node ( struct sllistnode head,
const void *  object,
size_t  objsize 
)

Add a node to the tail of the singly linked list.

On error mge_errno will be set.

Parameters
headA pointer to the root node or NULL if the list is not yet started.
objectThe object to attach to the node.
objsizeThe size of the attached object.
Returns
head, a pointer to the root node or NULL on error

◆ find_next_sll_node()

static struct sllistnode* find_next_sll_node ( struct sllistnode focus)
inlinestatic

Find the next node in the list.

Parameters
focusThe current node.
Returns
A pointer to the next node found in the list, or NULL if no subsequent node exists.

◆ find_sll_node()

void* find_sll_node ( struct sllistnode head,
const void *  searchobj,
int(*)(const void *, const void *)  comp 
)

Find a node.

On error mge_errno will be set, otherwise it will be 0.

Parameters
headA pointer to the current root node.
searchobjThe object to find. It does not need to be a fully populated object. It only needs enough inforamtion to support the comparison function, eg a key.
compA pointer to the comparison function to be used. This must have the same shape as strcmp.
Returns
A pointer to the object found, (the fully populated object), or NULL if not found or an error was encountered.

◆ free_sllist()

struct sllistnode* free_sllist ( struct sllistnode head)

Free the entire list.

Walks the list deleting nodes.

Parameters
headThe root node.
Returns
NULL