le_doublyLinkedList.h File Reference

Go to the source code of this file.

Data Structures

struct  le_dls_Link_t
 
struct  le_dls_List_t
 

Macros

#define LE_DLS_LIST_DECL_INIT   {NULL}
 
#define LE_DLS_LIST_INIT   (le_dls_List_t)LE_DLS_LIST_DECL_INIT
 
#define LE_DLS_LINK_INIT   (le_dls_Link_t){NULL, NULL}
 
#define LE_DLS_FOREACH(listPtr, iteratorPtr, type, member)
 

Typedefs

typedef bool(* le_dls_LessThanFunc_t) (le_dls_Link_t *a, le_dls_Link_t *b)
 

Functions

void le_dls_Stack (le_dls_List_t *listPtr, le_dls_Link_t *newLinkPtr)
 
void le_dls_Queue (le_dls_List_t *listPtr, le_dls_Link_t *newLinkPtr)
 
void le_dls_AddAfter (le_dls_List_t *listPtr, le_dls_Link_t *currentLinkPtr, le_dls_Link_t *newLinkPtr)
 
void le_dls_AddBefore (le_dls_List_t *listPtr, le_dls_Link_t *currentLinkPtr, le_dls_Link_t *newLinkPtr)
 
le_dls_Link_tle_dls_Pop (le_dls_List_t *listPtr)
 
le_dls_Link_tle_dls_PopTail (le_dls_List_t *listPtr)
 
void le_dls_Remove (le_dls_List_t *listPtr, le_dls_Link_t *linkToRemovePtr)
 
le_dls_Link_tle_dls_Peek (const le_dls_List_t *listPtr)
 
le_dls_Link_tle_dls_PeekTail (const le_dls_List_t *listPtr)
 
LE_DECLARE_INLINE bool le_dls_IsEmpty (const le_dls_List_t *listPtr)
 
le_dls_Link_tle_dls_PeekNext (const le_dls_List_t *listPtr, const le_dls_Link_t *currentLinkPtr)
 
le_dls_Link_tle_dls_PeekPrev (const le_dls_List_t *listPtr, const le_dls_Link_t *currentLinkPtr)
 
void le_dls_Swap (le_dls_List_t *listPtr, le_dls_Link_t *linkPtr, le_dls_Link_t *otherLinkPtr)
 
void le_dls_Sort (le_dls_List_t *listPtr, le_dls_LessThanFunc_t comparatorPtr)
 
bool le_dls_IsInList (const le_dls_List_t *listPtr, const le_dls_Link_t *linkPtr)
 
LE_DECLARE_INLINE bool le_dls_IsHead (const le_dls_List_t *listPtr, const le_dls_Link_t *linkPtr)
 
LE_DECLARE_INLINE bool le_dls_IsTail (const le_dls_List_t *listPtr, const le_dls_Link_t *linkPtr)
 
size_t le_dls_NumLinks (const le_dls_List_t *listPtr)
 
bool le_dls_IsListCorrupted (const le_dls_List_t *listPtr)
 

Detailed Description

Legato Doubly Linked List API include file.

Macro Definition Documentation

◆ LE_DLS_FOREACH

#define LE_DLS_FOREACH (   listPtr,
  iteratorPtr,
  type,
  member 
)
Value:
for ((iteratorPtr) = CONTAINER_OF(le_dls_Peek(listPtr), type, member); \
&((iteratorPtr)->member); \
(iteratorPtr) = CONTAINER_OF(le_dls_PeekNext((listPtr),&((iteratorPtr)->member)), \
type, member))
le_dls_Link_t * le_dls_PeekNext(const le_dls_List_t *listPtr, const le_dls_Link_t *currentLinkPtr)
#define CONTAINER_OF(memberPtr, type, member)
Definition: le_basics.h:135
le_dls_Link_t * le_dls_Peek(const le_dls_List_t *listPtr)

Simple iteration through a doubly linked list

◆ LE_DLS_LINK_INIT

#define LE_DLS_LINK_INIT   (le_dls_Link_t){NULL, NULL}

When a link is created it must be initialized by assigning this macro to the link before it can be used.

◆ LE_DLS_LIST_DECL_INIT

#define LE_DLS_LIST_DECL_INIT   {NULL}

When a list is created it must be initialized to this macro in the declaration, or have LE_DLS_LIST_INIT assigned to it, before being used

◆ LE_DLS_LIST_INIT

#define LE_DLS_LIST_INIT   (le_dls_List_t)LE_DLS_LIST_DECL_INIT

When a list is created it must be initialized by assigning this macro to the list, or initializing to LE_DLS_LIST_DECL_INIT in the declaration, before the list can be used.

Typedef Documentation

◆ le_dls_LessThanFunc_t

typedef bool(* le_dls_LessThanFunc_t) (le_dls_Link_t *a, le_dls_Link_t *b)

This is a comparator function for sorting a list.

This must return true if a goes before b in the list.

Function Documentation

◆ le_dls_AddAfter()

void le_dls_AddAfter ( le_dls_List_t listPtr,
le_dls_Link_t currentLinkPtr,
le_dls_Link_t newLinkPtr 
)

Adds a link after currentLinkPtr. User must ensure that currentLinkPtr is in the list otherwise the behaviour of this function is undefined.

Parameters
[in]listPtrList to add to.
[in]currentLinkPtrNew link will be inserted after this link.
[in]newLinkPtrNew link to add.

◆ le_dls_AddBefore()

void le_dls_AddBefore ( le_dls_List_t listPtr,
le_dls_Link_t currentLinkPtr,
le_dls_Link_t newLinkPtr 
)

Adds a link after currentLinkPtr. User must ensure that currentLinkPtr is in the list otherwise the behaviour of this function is undefined.

Parameters
[in]listPtrList to add to.
[in]currentLinkPtrNew link will be inserted before this link.
[in]newLinkPtrNew link to add.

◆ le_dls_IsEmpty()

LE_DECLARE_INLINE bool le_dls_IsEmpty ( const le_dls_List_t listPtr)

Checks if a list is empty.

Returns
true if empty, false if not empty.
Parameters
[in]listPtrThe list.

◆ le_dls_IsHead()

LE_DECLARE_INLINE bool le_dls_IsHead ( const le_dls_List_t listPtr,
const le_dls_Link_t linkPtr 
)

Checks if a link is at the head of the list (next to be popped).

Returns
  • true if the link is at the head of the list.
  • false if not.
Parameters
[in]listPtrList to check.
[in]linkPtrCheck if this link is at the head of the list.

◆ le_dls_IsInList()

bool le_dls_IsInList ( const le_dls_List_t listPtr,
const le_dls_Link_t linkPtr 
)

Checks if a link is in the list.

Returns
true if the link is in the list. false if the link is not in the list.
Parameters
[in]listPtrList to check.
[in]linkPtrCheck if this link is in the list.

◆ le_dls_IsListCorrupted()

bool le_dls_IsListCorrupted ( const le_dls_List_t listPtr)

Checks if the list is corrupted.

Returns
true if the list is corrupted. false if the list is not corrupted.
Parameters
[in]listPtrList to check.

◆ le_dls_IsTail()

LE_DECLARE_INLINE bool le_dls_IsTail ( const le_dls_List_t listPtr,
const le_dls_Link_t linkPtr 
)

Checks if a link is at the tail of the list (last to be popped).

Returns
  • true if the link is at the tail of the list.
  • false if not.
Parameters
[in]listPtrList to check.
[in]linkPtrCheck if this link is at the tail of the list.

◆ le_dls_NumLinks()

size_t le_dls_NumLinks ( const le_dls_List_t listPtr)

Returns the number of links in a list.

Returns
Number of links.
Parameters
[in]listPtrList to count.

◆ le_dls_Peek()

le_dls_Link_t* le_dls_Peek ( const le_dls_List_t listPtr)

Returns the link at the head of the list without removing it from the list.

Returns
Pointer to the head link if successful. NULL if the list is empty.
Parameters
[in]listPtrThe list.

◆ le_dls_PeekNext()

le_dls_Link_t* le_dls_PeekNext ( const le_dls_List_t listPtr,
const le_dls_Link_t currentLinkPtr 
)

Returns the link next to currentLinkPtr (i.e., the link beside currentLinkPtr that is closer to the tail) without removing it from the list. User must ensure that currentLinkPtr is in the list otherwise the behaviour of this function is undefined.

Returns
Pointer to the next link if successful. NULL if there is no link next to the currentLinkPtr (currentLinkPtr is at the tail of the list).
Parameters
[in]listPtrList containing currentLinkPtr.
[in]currentLinkPtrGet the link that is relative to this link.

◆ le_dls_PeekPrev()

le_dls_Link_t* le_dls_PeekPrev ( const le_dls_List_t listPtr,
const le_dls_Link_t currentLinkPtr 
)

Returns the link previous to currentLinkPtr without removing it from the list. User must ensure that currentLinkPtr is in the list otherwise the behaviour of this function is undefined.

Returns
Pointer to the previous link if successful. NULL if there is no link previous to the currentLinkPtr (currentLinkPtr is at the head of the list).
Parameters
[in]listPtrList containing currentLinkPtr.
[in]currentLinkPtrGet the link that is relative to this link.

◆ le_dls_PeekTail()

le_dls_Link_t* le_dls_PeekTail ( const le_dls_List_t listPtr)

Returns the link at the tail of the list without removing it from the list.

Returns
A pointer to the tail link if successful. NULL if the list is empty.
Parameters
[in]listPtrThe list.

◆ le_dls_Pop()

le_dls_Link_t* le_dls_Pop ( le_dls_List_t listPtr)

Removes and returns the link at the head of the list.

Returns
Removed link. NULL if the link is not available because the list is empty.
Parameters
[in]listPtrList to remove from.

◆ le_dls_PopTail()

le_dls_Link_t* le_dls_PopTail ( le_dls_List_t listPtr)

Removes and returns the link at the tail of the list.

Returns
The removed link. NULL if the link is not available because the list is empty.
Parameters
[in]listPtrList to remove from.

◆ le_dls_Queue()

void le_dls_Queue ( le_dls_List_t listPtr,
le_dls_Link_t newLinkPtr 
)

Adds a link to the tail of the list.

Parameters
[in]listPtrList to add to.
[in]newLinkPtrNew link to add.

◆ le_dls_Remove()

void le_dls_Remove ( le_dls_List_t listPtr,
le_dls_Link_t linkToRemovePtr 
)

Removes the specified link from the list. Ensure the link is in the list otherwise the behaviour of this function is undefined.

Parameters
[in]listPtrList to remove from.
[in]linkToRemovePtrLink to remove.

◆ le_dls_Sort()

void le_dls_Sort ( le_dls_List_t listPtr,
le_dls_LessThanFunc_t  comparatorPtr 
)

Sort a list in ascending order.

Parameters
[in]listPtrList to sort
[in]comparatorPtrComparator function for sorting

◆ le_dls_Stack()

void le_dls_Stack ( le_dls_List_t listPtr,
le_dls_Link_t newLinkPtr 
)

Adds a link at the head of the list.

Parameters
[in]listPtrList to add to.
[in]newLinkPtrNew link to add.

◆ le_dls_Swap()

void le_dls_Swap ( le_dls_List_t listPtr,
le_dls_Link_t linkPtr,
le_dls_Link_t otherLinkPtr 
)

Swaps the position of two links in the list. User must ensure that both links are in the list otherwise the behaviour of this function is undefined.

Parameters
[in]listPtrList containing the links to swap.
[in]linkPtrOne of the two link pointers to swap.
[in]otherLinkPtrOther link pointer to swap.