Linked list functions

group group_linkedlist_func

This is a generic linked list library with helper functions to add, insert, delete and find nodes in a list.

Functions

cy_rslt_t cy_linked_list_init(cy_linked_list_t *list)

Initialize list.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

Parameters
  • [in] list: - Pointer to a list

cy_rslt_t cy_linked_list_deinit(cy_linked_list_t *list)

De-initialize list.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

Parameters
  • [in] list: - Pointer to a list

cy_rslt_t cy_linked_list_get_count(cy_linked_list_t *list, uint32_t *count)

Get the count for number of nodes present in list.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

Parameters
  • [in] list: - Pointer to an initialized list

  • [out] count: - number of nodes present in list

cy_rslt_t cy_linked_list_set_node_data(cy_linked_list_node_t *node, const void *data)

Set the data for linked list node.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

Parameters
  • [in] node: - linked list node for which data need to be set

  • [in] data: - data value for node

cy_rslt_t cy_linked_list_get_front_node(cy_linked_list_t *list, cy_linked_list_node_t **front_node)

Get the front node in list.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

Parameters
  • [in] list: - Pointer to an initialized list

  • [out] front_node: - front node in the list

cy_rslt_t cy_linked_list_get_rear_node(cy_linked_list_t *list, cy_linked_list_node_t **rear_node)

Get the rear node in list.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

Parameters
  • [in] list: - Pointer to an initialized list

  • [out] rear_node: - rear node in the list

cy_rslt_t cy_linked_list_find_node(cy_linked_list_t *list, cy_linked_list_compare_callback_t callback, void *user_data, cy_linked_list_node_t **node_found)

Find particular node in the list.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

  • CY_RSLT_LINKED_LIST_NOT_FOUND

Parameters
  • [in] list: - Pointer to an initialized list

  • [in] callback: - callback to compare node data in the list

  • [in] user_data: - user data

  • [out] node_found: - node_found in the list

cy_rslt_t cy_linked_list_insert_node_at_front(cy_linked_list_t *list, cy_linked_list_node_t *node)

Insert node at the front of the list.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

Parameters
  • [in] list: - Pointer to an initialized list

  • [in] node: - node to be added at the front of the list

cy_rslt_t cy_linked_list_insert_node_at_rear(cy_linked_list_t *list, cy_linked_list_node_t *node)

Insert node at the rear of the list.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

Parameters
  • [in] list: - Pointer to an initialized list

  • [in] node: - node to be added at the rear of the list

cy_rslt_t cy_linked_list_insert_node_before(cy_linked_list_t *list, cy_linked_list_node_t *reference_node, cy_linked_list_node_t *node_to_insert)

Insert node before reference node.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

  • CY_RSLT_LINKED_LIST_NOT_FOUND

Parameters
  • [in] list: - Pointer to an initialized list

  • [in] reference_node: - Pointer to a node before which you want to add new node

  • [in] node_to_insert: - Pointer to a node to be inserted

cy_rslt_t cy_linked_list_insert_node_after(cy_linked_list_t *list, cy_linked_list_node_t *reference_node, cy_linked_list_node_t *node_to_insert)

Insert node after reference node.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

  • CY_RSLT_LINKED_LIST_NOT_FOUND

Parameters
  • [in] list: - Pointer to an initialized list

  • [in] reference_node: - Pointer to a node after which you want to add new node

  • [in] node_to_insert: - Pointer to a node to be inserted

cy_rslt_t cy_linked_list_remove_node(cy_linked_list_t *list, cy_linked_list_node_t *node)

Remove the node from the list.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

  • CY_RSLT_LINKED_LIST_NOT_FOUND

Parameters
  • [in] list: - Pointer to an initialized list

  • [in] node: - Pointer to a linked list node to be deleted

cy_rslt_t cy_linked_list_remove_node_from_front(cy_linked_list_t *list, cy_linked_list_node_t **removed_node)

Remove node from front of the list.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

  • CY_RSLT_LINKED_LIST_NOT_FOUND

Parameters
  • [in] list: - Pointer to an initialized list

  • [out] removed_node: - removed node

cy_rslt_t cy_linked_list_remove_node_from_rear(cy_linked_list_t *list, cy_linked_list_node_t **removed_node)

Remove node from rear of the list.

Return

on success - CY_RSLT_SUCCESS on failure - CY_RSLT_LINKED_LIST_BADARG

  • CY_RSLT_LINKED_LIST_NOT_FOUND

Parameters
  • [in] list: - Pointer to an initialized list

  • [out] removed_node: - removed node