MQTT C Client Libraries Internals: LinkedList.c File Reference

| MQTT C Client Libraries Internals

Loading...
Searching...
No Matches
Functions
LinkedList.c File Reference

functions which apply to linked list structures. More...

`#include "LinkedList.h"`
`#include <stdlib.h>`
`#include <string.h>`
`#include "Heap.h"`
Include dependency graph for LinkedList.c:

## Functions
static int | ListUnlink (List *aList, void *content, int(*callback)(void *, void *), int freeContent)
| Removes and optionally frees an element in a list by comparing the content.
void | ListZero (List *newl)
| Sets a list structure to empty - all null values.
List * | ListInitialize (void)
| Allocates and initializes a new list structure.
void | ListAppendNoMalloc (List *aList, void *content, ListElement *newel, size_t size)
| Append an already allocated ListElement and content to a list.
ListElement * | ListAppend (List *aList, void *content, size_t size)
| Append an item to a list.
ListElement * | ListInsert (List *aList, void *content, size_t size, ListElement *index)
| Insert an item to a list at a specific position.
ListElement * | ListFind (List *aList, void *content)
| Finds an element in a list by comparing the content pointers, rather than the contents.
ListElement * | ListFindItem (List *aList, void *content, int(*callback)(void *, void *))
| Finds an element in a list by comparing the content or pointer to the content.
int | ListDetach (List *aList, void *content)
| Removes but does not free an item in a list by comparing the pointer to the content.
int | ListRemove (List *aList, void *content)
| Removes and frees an item in a list by comparing the pointer to the content.
void * | ListDetachHead (List *aList)
| Removes and frees an the first item in a list.
int | ListRemoveHead (List *aList)
| Removes and frees an the first item in a list.
void * | ListPopTail (List *aList)
| Removes but does not free the last item in a list.
int | ListDetachItem (List *aList, void *content, int(*callback)(void *, void *))
| Removes but does not free an element in a list by comparing the content.
int | ListRemoveItem (List *aList, void *content, int(*callback)(void *, void *))
| Removes and frees an element in a list by comparing the content.
void | ListEmpty (List *aList)
| Removes and frees all items in a list, leaving the list ready for new items.
void | ListFree (List *aList)
| Removes and frees all items in a list, and frees the list itself.
void | ListFreeNoContent (List *aList)
| Removes and but does not free all items in a list, and frees the list itself.
ListElement * | ListNextElement (List *aList, ListElement **pos)
| Forward iteration through a list.
ListElement * | ListPrevElement (List *aList, ListElement **pos)
| Backward iteration through a list.
int | intcompare (void *a, void *b)
| List callback function for comparing integers.
int | stringcompare (void *a, void *b)
| List callback function for comparing C strings.

## Detailed Description

functions which apply to linked list structures.

These linked lists can hold data of any sort, pointed to by the content pointer of the ListElement structure. ListElements hold the points to the next and previous items in the list.

## Function Documentation

## ◆ intcompare()

int intcompare | ( | void * | a,
|  | void * | b )

List callback function for comparing integers.

Parameters

  a | first integer value
  b | second integer value

Returns
  boolean indicating whether a and b are equal

## ◆ ListAppend()

ListElement * ListAppend | ( | List * | aList,
|  | void * | content,
|  | size_t | size )

Append an item to a list.

Parameters

  aList | the list to which the item is to be added
  content | the list item content itself
  size | the size of the element

Here is the call graph for this function:

## ◆ ListAppendNoMalloc()

void ListAppendNoMalloc | ( | List * | aList,
|  | void * | content,
|  | ListElement * | newel,
|  | size_t | size )

Append an already allocated ListElement and content to a list.

Can be used to move an item from one list to another.

Parameters

  aList | the list to which the item is to be added
  content | the list item content itself
  newel | the ListElement to be used in adding the new item
  size | the size of the element

## ◆ ListDetach()

int ListDetach | ( | List * | aList,
|  | void * | content )

Removes but does not free an item in a list by comparing the pointer to the content.

Parameters

  aList | the list in which the search is to be conducted
  content | pointer to the content to look for

Returns
  1=item removed, 0=item not removed

Here is the call graph for this function:

## ◆ ListDetachHead()

void * ListDetachHead | ( | List * | aList | ) |

Removes and frees an the first item in a list.

Parameters

  aList | the list from which the item is to be removed

Returns
  1=item removed, 0=item not removed

## ◆ ListDetachItem()

int ListDetachItem | ( | List * | aList,
|  | void * | content,
|  | int(* | callback )(void *, void *) )

Removes but does not free an element in a list by comparing the content.

A callback function is used to define the method of comparison for each element.

Parameters

  aList | the list in which the search is to be conducted
  content | pointer to the content to look for
  callback | pointer to a function which compares each element

Returns
  1=item removed, 0=item not removed

Here is the call graph for this function:

## ◆ ListEmpty()

void ListEmpty | ( | List * | aList | ) |

Removes and frees all items in a list, leaving the list ready for new items.

Parameters

  aList | the list to which the operation is to be applied

## ◆ ListFind()

ListElement * ListFind | ( | List * | aList,
|  | void * | content )

Finds an element in a list by comparing the content pointers, rather than the contents.

Parameters

  aList | the list in which the search is to be conducted
  content | pointer to the list item content itself

Returns
  the list item found, or NULL

Here is the call graph for this function:

## ◆ ListFindItem()

ListElement * ListFindItem | ( | List * | aList,
|  | void * | content,
|  | int(* | callback )(void *, void *) )

Finds an element in a list by comparing the content or pointer to the content.

A callback function is used to define the method of comparison for each element.

Parameters

  aList | the list in which the search is to be conducted
  content | pointer to the content to look for
  callback | pointer to a function which compares each element (NULL means compare by content pointer)

Returns
  the list element found, or NULL

Here is the call graph for this function:

## ◆ ListFree()

void ListFree | ( | List * | aList | ) |

Removes and frees all items in a list, and frees the list itself.

Parameters

  aList | the list to which the operation is to be applied

Here is the call graph for this function:

## ◆ ListFreeNoContent()

void ListFreeNoContent | ( | List * | aList | ) |

Removes and but does not free all items in a list, and frees the list itself.

Parameters

  aList | the list to which the operation is to be applied

## ◆ ListInitialize()

List * ListInitialize | ( | void |  | ) |

Allocates and initializes a new list structure.

Returns
  a pointer to the new list structure

Here is the call graph for this function:

## ◆ ListInsert()

ListElement * ListInsert | ( | List * | aList,
|  | void * | content,
|  | size_t | size,
|  | ListElement * | index )

Insert an item to a list at a specific position.

Parameters

  aList | the list to which the item is to be added
  content | the list item content itself
  size | the size of the element
  index | the position in the list. If NULL, this function is equivalent to ListAppend.

Here is the call graph for this function:

## ◆ ListNextElement()

ListElement * ListNextElement | ( | List * | aList,
|  | ListElement ** | pos )

Forward iteration through a list.

Parameters

  aList | the list to which the operation is to be applied
  pos | pointer to the current position in the list. NULL means start from the beginning of the list This is updated on return to the same value as that returned from this function

Returns
  pointer to the current list element

## ◆ ListPopTail()

void * ListPopTail | ( | List * | aList | ) |

Removes but does not free the last item in a list.

Parameters

  aList | the list from which the item is to be removed

Returns
  the last item removed (or NULL if none was)

## ◆ ListPrevElement()

ListElement * ListPrevElement | ( | List * | aList,
|  | ListElement ** | pos )

Backward iteration through a list.

Parameters

  aList | the list to which the operation is to be applied
  pos | pointer to the current position in the list. NULL means start from the end of the list This is updated on return to the same value as that returned from this function

Returns
  pointer to the current list element

## ◆ ListRemove()

int ListRemove | ( | List * | aList,
|  | void * | content )

Removes and frees an item in a list by comparing the pointer to the content.

Parameters

  aList | the list from which the item is to be removed
  content | pointer to the content to look for

Returns
  1=item removed, 0=item not removed

Here is the call graph for this function:

## ◆ ListRemoveHead()

int ListRemoveHead | ( | List * | aList | ) |

Removes and frees an the first item in a list.

Parameters

  aList | the list from which the item is to be removed

Returns
  1=item removed, 0=item not removed

Here is the call graph for this function:

## ◆ ListRemoveItem()

int ListRemoveItem | ( | List * | aList,
|  | void * | content,
|  | int(* | callback )(void *, void *) )

Removes and frees an element in a list by comparing the content.

A callback function is used to define the method of comparison for each element

Parameters

  aList | the list in which the search is to be conducted
  content | pointer to the content to look for
  callback | pointer to a function which compares each element

Returns
  1=item removed, 0=item not removed

Here is the call graph for this function:

## ◆ ListUnlink()

int ListUnlink | ( | List * | aList,
|  | void * | content,
|  | int(* | callback )(void *, void *),
|  | int | freeContent )
| static

Removes and optionally frees an element in a list by comparing the content.

A callback function is used to define the method of comparison for each element.

Parameters

  aList | the list in which the search is to be conducted
  content | pointer to the content to look for
  callback | pointer to a function which compares each element
  freeContent | boolean value to indicate whether the item found is to be freed

Returns
  1=item removed, 0=item not removed

Here is the call graph for this function:

## ◆ ListZero()

void ListZero | ( | List * | newl | ) |

Sets a list structure to empty - all null values.

Does not remove any items from the list.

Parameters

  newl | a pointer to the list structure to be initialized

## ◆ stringcompare()

int stringcompare | ( | void * | a,
|  | void * | b )

List callback function for comparing C strings.

Parameters

  a | first integer value
  b | second integer value

Returns
  boolean indicating whether a and b are equal