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
Go to the documentation of this file.
1// -------------------------------------------------------------------------------------------
2// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3// This file is part of the AWS CDI-SDK, licensed under the BSD 2-Clause "Simplified" License.
4// License details at: https://github.com/aws/aws-cdi-sdk/blob/mainline/LICENSE
5// -------------------------------------------------------------------------------------------
6
32#ifndef CDI_SINGLY_LINKEDLIST_API_H__
33#define CDI_SINGLY_LINKEDLIST_API_H__
34
35#include <assert.h>
36#include <stdbool.h>
37#include <stddef.h>
38
39//*********************************************************************************************************************
40//***************************************** START OF DEFINITIONS AND TYPES ********************************************
41//*********************************************************************************************************************
42
45
52
61
62//*********************************************************************************************************************
63//*********************************************** START OF VARIABLES **************************************************
64//*********************************************************************************************************************
65
66//*********************************************************************************************************************
67//******************************************* START OF STATIC FUNCTIONS ***********************************************
68//*********************************************************************************************************************
69
70//*********************************************************************************************************************
71//******************************************* START OF PUBLIC FUNCTIONS ***********************************************
72//*********************************************************************************************************************
73
79static inline void CdiSinglyLinkedListInit(CdiSinglyLinkedList* list_ptr)
80{
81 list_ptr->head_ptr = NULL;
82 list_ptr->tail_ptr = NULL;
83 list_ptr->num_entries = 0;
84}
85
93 CdiSinglyLinkedListEntry* new_entry_ptr)
94{
95 new_entry_ptr->next_ptr = list_ptr->head_ptr;
96 list_ptr->head_ptr = new_entry_ptr;
97 if (list_ptr->tail_ptr == NULL) {
98 list_ptr->tail_ptr = new_entry_ptr;
99 }
100 list_ptr->num_entries++;
101}
102
110 CdiSinglyLinkedListEntry* new_entry_ptr)
111{
112 new_entry_ptr->next_ptr = NULL;
113 if (list_ptr->tail_ptr != NULL) {
114 list_ptr->tail_ptr->next_ptr = new_entry_ptr;
115 }
116 list_ptr->tail_ptr = new_entry_ptr;
117 if (list_ptr->head_ptr == NULL) {
118 list_ptr->head_ptr = new_entry_ptr;
119 }
120 list_ptr->num_entries++;
121}
122
131{
132 CdiSinglyLinkedListEntry* p = list_ptr->head_ptr;
133 if (p != NULL) {
134 list_ptr->head_ptr = p->next_ptr;
135 p->next_ptr = NULL;
136
137 // Don't allow value to go negative.
138 assert(list_ptr->num_entries >= 0);
139 if (list_ptr->num_entries) {
140 list_ptr->num_entries--;
141 }
142 }
143 if (list_ptr->head_ptr == NULL) {
144 list_ptr->tail_ptr = NULL;
145 }
146 return p;
147}
148
156static inline bool CdiSinglyLinkedListIsEmpty(const CdiSinglyLinkedList* list_ptr)
157{
158 return list_ptr->head_ptr == NULL;
159}
160
168static inline int CdiSinglyLinkedListSize(const CdiSinglyLinkedList* list_ptr)
169{
170 return list_ptr->num_entries;
171}
172
181{
182 return list_ptr->head_ptr;
183}
184
193{
194 return entry_ptr->next_ptr;
195}
196
197#endif // CDI_SINGLY_LINKED_LIST_API_H__
static bool CdiSinglyLinkedListIsEmpty(const CdiSinglyLinkedList *list_ptr)
Definition singly_linked_list_api.h:156
static void CdiSinglyLinkedListPushTail(CdiSinglyLinkedList *list_ptr, CdiSinglyLinkedListEntry *new_entry_ptr)
Definition singly_linked_list_api.h:109
static int CdiSinglyLinkedListSize(const CdiSinglyLinkedList *list_ptr)
Definition singly_linked_list_api.h:168
static CdiSinglyLinkedListEntry * CdiSinglyLinkedListGetHead(const CdiSinglyLinkedList *list_ptr)
Definition singly_linked_list_api.h:180
static CdiSinglyLinkedListEntry * CdiSinglyLinkedListNextEntry(const CdiSinglyLinkedListEntry *entry_ptr)
Definition singly_linked_list_api.h:192
static CdiSinglyLinkedListEntry * CdiSinglyLinkedListPopHead(CdiSinglyLinkedList *list_ptr)
Definition singly_linked_list_api.h:130
static void CdiSinglyLinkedListPushHead(CdiSinglyLinkedList *list_ptr, CdiSinglyLinkedListEntry *new_entry_ptr)
Definition singly_linked_list_api.h:92
static void CdiSinglyLinkedListInit(CdiSinglyLinkedList *list_ptr)
Definition singly_linked_list_api.h:79
This structure represents a single list entry.
Definition singly_linked_list_api.h:49
struct CdiSinglyLinkedListEntry * next_ptr
Pointer to next item in list, NULL if this is the tail entry.
Definition singly_linked_list_api.h:50
This structure represents a list.
Definition singly_linked_list_api.h:56
CdiSinglyLinkedListEntry * tail_ptr
Tail entry of list item. NULL valid if the list is empty.
Definition singly_linked_list_api.h:58
int num_entries
Number of entries currently in this list.
Definition singly_linked_list_api.h:59
CdiSinglyLinkedListEntry * head_ptr
Head entry of list item. NULL valid if the list is empty.
Definition singly_linked_list_api.h:57