GRU - Generic Reusable Utilities
Loading...
Searching...
No Matches
gru_list.h
Go to the documentation of this file.
1/*
2 Copyright 2016 Otavio Rodolfo Piske
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16#ifndef LIST_H
17#define LIST_H
18
19#include <assert.h>
20#include <inttypes.h>
21#include <stdbool.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
26#include "common/gru_base.h"
27#include "common/gru_status.h"
29#include "gru_node.h"
30#include "gru_node_info.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
39typedef void (*gru_nodedata_destructor)(void **);
40
42
48
54
61gru_export uint32_t gru_list_count(const gru_list_t *list);
62
72gru_export const gru_node_t *gru_list_append(gru_list_t *list, const void *data);
73
82 gru_list_insert(gru_list_t *list, const void *data, uint32_t position);
83
90gru_export gru_node_t *gru_list_remove(gru_list_t *list, uint32_t position);
91
92
100
109 compare_function_t comparable,
110 const void *other);
111
118gru_export const gru_node_t *gru_list_get(const gru_list_t *list, uint32_t position);
119
129 bool uniqueness,
130 compare_function_t comparable,
131 const void *compare,
132 void *result);
133
140gru_export void
141 gru_list_for_each(const gru_list_t *list, handle_function_t handle, void *data);
142
152 void *data);
153
162gru_export const void *gru_list_get_item(const gru_list_t *list,
163 compare_function_t comparable,
164 const void *other);
165
166
168
169#ifdef __cplusplus
170}
171#endif
172
173#endif
bool(* compare_function_t)(const void *, const void *data, void *result)
Comparator function for the collections module.
Definition: gru_collection_callbacks.h:30
void(* handle_function_info_t)(const void *, gru_node_info_t info, void *)
A handler function for the collections module that also receiver node information.
Definition: gru_collection_callbacks.h:40
void(* handle_function_t)(const void *, void *)
Handler function for the collections module.
Definition: gru_collection_callbacks.h:35
gru_export void gru_list_destroy(gru_list_t **list)
Ensures that the list is properly destroyed.
Definition: gru_list.c:35
void(* gru_nodedata_destructor)(void **)
Reusable destructor for cleaning list data.
Definition: gru_list.h:39
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....
Definition: gru_list.c:264
gru_export gru_node_t * gru_list_remove_node(gru_list_t *list, gru_node_t *node)
Removes a node from a list.
Definition: gru_list.c:163
gru_export void gru_list_clean(gru_list_t *list, gru_nodedata_destructor destructor)
Definition: gru_list.c:323
gru_export const gru_node_t * gru_list_append(gru_list_t *list, const void *data)
Appends an item in the list.
Definition: gru_list.c:100
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.
Definition: gru_list.c:214
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.
Definition: gru_list.c:288
gru_export gru_node_t * gru_list_insert(gru_list_t *list, const void *data, uint32_t position)
Inserts an item in the list.
Definition: gru_list.c:118
gru_export gru_list_t * gru_list_new(gru_status_t *status)
Creates a new list.
Definition: gru_list.c:18
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.
Definition: gru_list.c:248
gru_export uint32_t gru_list_count(const gru_list_t *list)
Returns the number of items in a list.
Definition: gru_list.c:83
struct gru_list_t_ gru_list_t
gru_export gru_node_t * gru_list_remove(gru_list_t *list, uint32_t position)
Removes an item from a list.
Definition: gru_list.c:141
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.
Definition: gru_list.c:225
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.
Definition: gru_list.c:187
#define gru_export
Definition: gru_portable.h:19
Definition: gru_list.h:41
gru_node_t * root
Definition: gru_list.h:41
Definition: gru_node.h:25
Status type.
Definition: gru_status.h:47