GRU - Generic Reusable Utilities
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
gru_list.h File Reference
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common/gru_base.h"
#include "common/gru_status.h"
#include "gru_collection_callbacks.h"
#include "gru_node.h"
#include "gru_node_info.h"

Go to the source code of this file.

Data Structures

struct  gru_list_t_
 

Typedefs

typedef void(* gru_nodedata_destructor) (void **)
 Reusable destructor for cleaning list data. More...
 
typedef struct gru_list_t_ gru_list_t
 

Functions

gru_export gru_list_tgru_list_new (gru_status_t *status)
 Creates a new list. More...
 
gru_export void gru_list_destroy (gru_list_t **list)
 Ensures that the list is properly destroyed. More...
 
gru_export uint32_t gru_list_count (const gru_list_t *list)
 Returns the number of items in a list. More...
 
gru_export const gru_node_tgru_list_append (gru_list_t *list, const void *data)
 Appends an item in the list. More...
 
gru_export gru_node_tgru_list_insert (gru_list_t *list, const void *data, uint32_t position)
 Inserts an item in the list. More...
 
gru_export gru_node_tgru_list_remove (gru_list_t *list, uint32_t position)
 Removes an item from a list. More...
 
gru_export gru_node_tgru_list_remove_node (gru_list_t *list, gru_node_t *node)
 Removes a node from a list. More...
 
gru_export bool gru_list_remove_item (gru_list_t *list, compare_function_t comparable, const void *other)
 Removes a node that matches a given data as returned by comparable. More...
 
gru_export const gru_node_tgru_list_get (const gru_list_t *list, uint32_t position)
 Gets a node from the list at the given position. More...
 
gru_export void gru_list_for_each_compare (const gru_list_t *list, bool uniqueness, compare_function_t comparable, const void *compare, void *result)
 Traverses the list comparing the data. More...
 
gru_export void gru_list_for_each (const gru_list_t *list, handle_function_t handle, void *data)
 Traverses the list executing a set of operations. More...
 
gru_export void gru_list_for_each_ex (const gru_list_t *list, handle_function_info_t handle, void *data)
 Traverses the list executing a set of operations and passes through node information (ie.: its position) More...
 
gru_export const void * gru_list_get_item (const gru_list_t *list, compare_function_t comparable, const void *other)
 Traverses the list comparing the data. More...
 
gru_export void gru_list_clean (gru_list_t *list, gru_nodedata_destructor destructor)
 

Typedef Documentation

◆ gru_list_t

typedef struct gru_list_t_ gru_list_t

◆ gru_nodedata_destructor

typedef void(* gru_nodedata_destructor) (void **)

Reusable destructor for cleaning list data.

Function Documentation

◆ gru_list_append()

gru_export const gru_node_t * gru_list_append ( gru_list_t list,
const void *  data 
)

Appends an item in the list.

Parameters
listThe list to receive the new item
dataThe data for the new node
Note
It's up to the application to make sure that the data pointer remains valid throughout the lifetime of the list
Returns
A pointer to the new node or NULL if there's not enough memory for the new node

◆ gru_list_clean()

gru_export void gru_list_clean ( gru_list_t list,
gru_nodedata_destructor  destructor 
)

◆ gru_list_count()

gru_export uint32_t gru_list_count ( const gru_list_t list)

Returns the number of items in a list.

Parameters
listA given list to check the number of items
Returns
The number of items
Note
The list must not be NULL

◆ gru_list_destroy()

gru_export void gru_list_destroy ( gru_list_t **  list)

Ensures that the list is properly destroyed.

Parameters
listthe list to destroy

◆ gru_list_for_each()

gru_export void gru_list_for_each ( const gru_list_t list,
handle_function_t  handle,
void *  data 
)

Traverses the list executing a set of operations.

Parameters
listThe list to be traversed
handleA pointer to a function of type handle_function_t
dataPayload data for the true_handle and false_handle functions

◆ gru_list_for_each_compare()

gru_export void gru_list_for_each_compare ( const gru_list_t list,
bool  uniqueness,
compare_function_t  comparable,
const void *  compare,
void *  result 
)

Traverses the list comparing the data.

It aborts if the uniqueness is true and the comparison returns true

Parameters
list
comparable
other
result

◆ gru_list_for_each_ex()

gru_export void gru_list_for_each_ex ( const gru_list_t list,
handle_function_info_t  handle,
void *  data 
)

Traverses the list executing a set of operations and passes through node information (ie.: its position)

Parameters
listThe list to be traversed
handleA pointer to a function of type handle_function_info_t
dataPayload data for the true_handle and false_handle functions

◆ gru_list_get()

gru_export const gru_node_t * gru_list_get ( const gru_list_t list,
uint32_t  position 
)

Gets a node from the list at the given position.

Parameters
listthe list
positionthe position
Returns
the node or NULL if not existent

◆ gru_list_get_item()

gru_export const void * gru_list_get_item ( const gru_list_t list,
compare_function_t  comparable,
const void *  other 
)

Traverses the list comparing the data.

It aborts if the uniqueness is true and the comparison returns true

Parameters
list
comparable
other
result

◆ gru_list_insert()

gru_export gru_node_t * gru_list_insert ( gru_list_t list,
const void *  data,
uint32_t  position 
)

Inserts an item in the list.

Parameters
listThe list to receive the new item
dataThe data for the new node
positionThe position to insert the data
Returns
A pointer to the new node

◆ gru_list_new()

gru_export gru_list_t * gru_list_new ( gru_status_t status)

Creates a new list.

Returns
A new gru_list_t object

◆ gru_list_remove()

gru_export gru_node_t * gru_list_remove ( gru_list_t list,
uint32_t  position 
)

Removes an item from a list.

Parameters
listThe list to remove the item
positionThe position of the item to be removed
Returns
A pointer to the removed node

◆ gru_list_remove_item()

gru_export bool gru_list_remove_item ( gru_list_t list,
compare_function_t  comparable,
const void *  other 
)

Removes a node that matches a given data as returned by comparable.

Parameters
listThe list to remove the node from
comparableThe comparison function (void *result will be NULL)
otherThe data to compare the node with
Returns
true if the node was removed or false if it was not found

◆ gru_list_remove_node()

gru_export gru_node_t * gru_list_remove_node ( gru_list_t list,
gru_node_t node 
)

Removes a node from a list.

Parameters
listThe list to remove the item
nodeThe node to be removed
Returns
A pointer to the removed node