CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
singly_linked_list_api.h File Reference

This file defines all the methods required for a singly linked list. A tail pointer is provided in order to enable use as a FIFO. The implementation is not thread safe. Its simplicity keeps it efficient for O(1) complexity. More...

#include <assert.h>
#include <stdbool.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  CdiSinglyLinkedListEntry
 This structure represents a single list entry. More...
 
struct  CdiSinglyLinkedList
 This structure represents a list. More...
 

Typedefs

typedef struct CdiSinglyLinkedListEntry CdiSinglyLinkedListEntry
 Forward declaration to create pointer to singly linked list entry when used.
 

Functions

static void CdiSinglyLinkedListInit (CdiSinglyLinkedList *list_ptr)
 
static void CdiSinglyLinkedListPushHead (CdiSinglyLinkedList *list_ptr, CdiSinglyLinkedListEntry *new_entry_ptr)
 
static void CdiSinglyLinkedListPushTail (CdiSinglyLinkedList *list_ptr, CdiSinglyLinkedListEntry *new_entry_ptr)
 
static CdiSinglyLinkedListEntryCdiSinglyLinkedListPopHead (CdiSinglyLinkedList *list_ptr)
 
static bool CdiSinglyLinkedListIsEmpty (const CdiSinglyLinkedList *list_ptr)
 
static int CdiSinglyLinkedListSize (const CdiSinglyLinkedList *list_ptr)
 
static CdiSinglyLinkedListEntryCdiSinglyLinkedListGetHead (const CdiSinglyLinkedList *list_ptr)
 
static CdiSinglyLinkedListEntryCdiSinglyLinkedListNextEntry (const CdiSinglyLinkedListEntry *entry_ptr)
 

Detailed Description

This file defines all the methods required for a singly linked list. A tail pointer is provided in order to enable use as a FIFO. The implementation is not thread safe. Its simplicity keeps it efficient for O(1) complexity.

empty list: head_ptr -> NULL tail_ptr -> NULL

single item in list: +-------—+ head_ptr -> | next_ptr | -> NULL +-------—+ ^ tail_ptr ------—+

larger list: +-------—+ +-------—+ +-------—+ head_ptr -> | next_ptr | -> | next_ptr | -> ... -> | next_ptr | -> NULL +-------—+ +-------—+ +-------—+ ^ tail_ptr ---------------------------------------------—+

Function Documentation

◆ CdiSinglyLinkedListGetHead()

static CdiSinglyLinkedListEntry * CdiSinglyLinkedListGetHead ( const CdiSinglyLinkedList * list_ptr)
inlinestatic

Provides a pointer to the head entry of a given list.

Parameters
list_ptrPointer to the list to get the head entry ptr.
Returns
Pointer to the head entry of the list_ptr list.

◆ CdiSinglyLinkedListInit()

static void CdiSinglyLinkedListInit ( CdiSinglyLinkedList * list_ptr)
inlinestatic

Initialize a list. Doesn't need to be inline, since it is only used once for each instance of the list.

Parameters
list_ptrPointer to instance of the list.

◆ CdiSinglyLinkedListIsEmpty()

static bool CdiSinglyLinkedListIsEmpty ( const CdiSinglyLinkedList * list_ptr)
inlinestatic

Check if the list is empty.

Parameters
list_ptrPointer to instance of the list.
Returns
True if the list is empty, otherwise false.

◆ CdiSinglyLinkedListNextEntry()

static CdiSinglyLinkedListEntry * CdiSinglyLinkedListNextEntry ( const CdiSinglyLinkedListEntry * entry_ptr)
inlinestatic

Provides a pointer to the next entry of a list entry.

Parameters
entry_ptrPointer to an entry on a list.
Returns
Pointer to the next entry on the list.

◆ CdiSinglyLinkedListPopHead()

static CdiSinglyLinkedListEntry * CdiSinglyLinkedListPopHead ( CdiSinglyLinkedList * list_ptr)
inlinestatic

Pop an item off the head of the list, removing it from the list.

Parameters
list_ptrPointer to instance of the list.
Returns
Pointer to the popped head list entry or NULL if the list is empty.

◆ CdiSinglyLinkedListPushHead()

static void CdiSinglyLinkedListPushHead ( CdiSinglyLinkedList * list_ptr,
CdiSinglyLinkedListEntry * new_entry_ptr )
inlinestatic

Add a new entry to the head of the list.

Parameters
list_ptrPointer to instance of the list.
new_entry_ptrPointer to new entry to add to the list.

◆ CdiSinglyLinkedListPushTail()

static void CdiSinglyLinkedListPushTail ( CdiSinglyLinkedList * list_ptr,
CdiSinglyLinkedListEntry * new_entry_ptr )
inlinestatic

Add a new entry to the tail of the list.

Parameters
list_ptrPointer to instance of the list.
new_entry_ptrPointer to new entry to add to the list.

◆ CdiSinglyLinkedListSize()

static int CdiSinglyLinkedListSize ( const CdiSinglyLinkedList * list_ptr)
inlinestatic

Report the number of entries currently in the list.

Parameters
list_ptrAddress of the list whose size is of interest.
Returns
int The number of entries in the list; this will always be greater than or equal to zero (empty).