annotate th_datastruct.h @ 751:3091fd1987e9

Rename function argument.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Jan 2023 09:49:13 +0200
parents ca837a4417f5
children 64cb2b1777a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Various data structure functions
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
726
29e44a58bc73 Bump copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 722
diff changeset
4 * (C) Copyright 2002-2022 Tecnic Software productions (TNSP)
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
630
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
8 /// @file
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
9 /// @brief Implementations of common data structures like linked lists, ring buffers, autogrowing buffers, etc.
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #ifndef TH_DATASTRUCT_H
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #define TH_DATASTRUCT_H
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include "th_util.h"
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
459
7fca448847a3 Oops, fix C++ guards in headers.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
15 #ifdef __cplusplus
7fca448847a3 Oops, fix C++ guards in headers.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
16 extern "C" {
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #endif
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
630
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
20 /** @brief
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
21 * Doubly linked list structure.
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 */
630
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
23 typedef struct th_llist_t
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
630
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
25 size_t num; ///< Number of nodes in the list, meaningful ONLY in the current root node of the list
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
26 struct th_llist_t *prev, *next; ///< Pointers to previous and next nodes.
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
27 void *data; ///< Pointer to data payload of this node, if any
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 } th_llist_t;
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
627
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
31 th_llist_t * th_llist_new(void *data);
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
32 void th_llist_free(th_llist_t *list);
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
33 void th_llist_free_func_data(th_llist_t *list, void (*freefunc)(void *data));
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
34 void th_llist_free_func_node(th_llist_t *list, void (*freefunc)(th_llist_t *node));
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
627
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
36 void th_llist_append_node(th_llist_t **list, th_llist_t *node);
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
37 th_llist_t * th_llist_append(th_llist_t **list, void *data);
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
38 void th_llist_prepend_node(th_llist_t **list, th_llist_t *node);
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
39 th_llist_t * th_llist_prepend(th_llist_t **list, void *data);
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
40 void th_llist_delete_node(th_llist_t **list, th_llist_t *node);
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
627
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
42 th_llist_t * th_llist_get_nth(th_llist_t *list, const size_t n);
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
43 size_t th_llist_length(const th_llist_t *list);
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
44 ssize_t th_llist_position(const th_llist_t *list, const th_llist_t *node);
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
627
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
46 void th_llist_foreach(th_llist_t *list, void (*func)(th_llist_t *node, void *userdata), void *data);
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
47 int th_llist_foreach_cond(th_llist_t *list, int (*func)(th_llist_t *node, void *userdata), void *data, th_llist_t **res);
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
627
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
49 th_llist_t * th_llist_find(th_llist_t *list, const void *data);
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
50 th_llist_t * th_llist_find_func(th_llist_t *list, const void *userdata, int (compare)(const void *, const void *));
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
630
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
53 /** @brief
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
54 * Ringbuffer data structure
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 */
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 typedef struct
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 {
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
58 bool is_allocated; ///< True if this structure has been allocated dynamically
629
b695eb769e30 Change ringbuffer data type from (char *) to (void *).
Matti Hamalainen <ccr@tnsp.org>
parents: 627
diff changeset
59 void **data; ///< Array of pointers to the data
630
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
60 size_t size; ///< Size of this ringbuffer in elements (aka pointers to data)
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
61 size_t n; ///< Number of elements currently in the ringbuffer (@p n <= @p size)
d3aace9903fa Doxygen improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 629
diff changeset
62 void (*deallocator)(void *data); ///< De-allocator function that frees one element.
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 } th_ringbuf_t;
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
627
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
65
631
d5221299656a Add new function th_ringbuf_init() and add "allocated" field to th_ringbuf_t
Matti Hamalainen <ccr@tnsp.org>
parents: 630
diff changeset
66 int th_ringbuf_init(th_ringbuf_t *buf, const size_t size, void (*mdeallocator)(void *data));
731
98d12f33da7b Change th_ringbuf_new() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
67 int th_ringbuf_new(th_ringbuf_t **buf, const size_t size, void (*mdeallocator)(void *data));
632
553db886533e Return a THERR_* error value from th_ringbuf_grow() instead of BOOL. This
Matti Hamalainen <ccr@tnsp.org>
parents: 631
diff changeset
68 int th_ringbuf_grow(th_ringbuf_t *buf, const size_t n);
627
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
69 void th_ringbuf_free(th_ringbuf_t *buf);
964657ad0960 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 626
diff changeset
70 void th_ringbuf_add(th_ringbuf_t *buf, void *ptr);
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 /* Growing buffers
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 */
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 #define TH_BUFGROW (32)
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 /* Simple growing string buffer
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 */
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
80 bool th_strbuf_grow(char **buf, size_t *bufsize, size_t *len, const size_t grow);
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
81 bool th_strbuf_putch(char **buf, size_t *bufsize, size_t *len, const uint8_t ch);
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
82 bool th_strbuf_putsn(char **buf, size_t *bufsize, size_t *len, const char *str, const size_t slen);
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
83 bool th_strbuf_puts(char **buf, size_t *bufsize, size_t *len, const char *str);
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
734
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
86 /** @brief
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
87 * Simple growing buffer structure
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
88 */
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
89 typedef struct
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
90 {
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
91 bool is_allocated; ///< True if this structure has been allocated dynamically
734
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
92 uint8_t *data; ///< Pointer to data
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
93 size_t size; ///< Current allocated size of data
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
94 size_t len; ///< Actual used size of data (must be < size)
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
95 size_t mingrow; ///< Minimum amount of bytes to grow allocation by
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
96 ///< If 0, grow by TH_BUFGROW
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
97 } th_growbuf_t;
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
98
2ae1045f6c18 Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 733
diff changeset
99
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 /* Growing byte buffer
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 */
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 void th_growbuf_init(th_growbuf_t *buf, const size_t mingrow);
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 void th_growbuf_clear(th_growbuf_t *buf);
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 th_growbuf_t *th_growbuf_new(const size_t mingrow);
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 void th_growbuf_free(th_growbuf_t *buf);
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
108 bool th_growbuf_grow(th_growbuf_t *buf, const size_t grow);
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
109 bool th_growbuf_puts(th_growbuf_t *buf, const char *str, bool eos);
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
110 bool th_growbuf_putch(th_growbuf_t *buf, const char ch);
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
111 bool th_growbuf_put_str(th_growbuf_t *buf, const void *s, const size_t len);
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
112 bool th_growbuf_put_u8(th_growbuf_t *buf, const uint8_t val);
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
113 bool th_growbuf_put_u16_be(th_growbuf_t *buf, const uint16_t val);
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
114 bool th_growbuf_put_u16_le(th_growbuf_t *buf, const uint16_t val);
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
115 bool th_growbuf_put_u32_be(th_growbuf_t *buf, const uint32_t val);
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 734
diff changeset
116 bool th_growbuf_put_u32_le(th_growbuf_t *buf, const uint32_t val);
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
736
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
119 /** @brief
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
120 * Growing pointerlist/array structure
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
121 */
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
122 typedef struct
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
123 {
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
124 bool is_allocated;
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
125 size_t nitems, nallocated, ngrow;
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
126 void **items;
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
127 } th_ptrlist_t;
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
128
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
129
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
130 int th_ptrlist_init(th_ptrlist_t *list, const size_t ninitial, const size_t ngrow);
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
131 int th_ptrlist_new(th_ptrlist_t **list, const size_t ninitial, const size_t ngrow);
751
3091fd1987e9 Rename function argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 736
diff changeset
132 int th_ptrlist_append(th_ptrlist_t *list, void *data);
736
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
133 void th_ptrlist_free(th_ptrlist_t *list, void (*mdeallocator)(void *data));
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
134
ca837a4417f5 Add simple growing pointerlist data stucture implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
135
269
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 #ifdef __cplusplus
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 }
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 #endif
fcbdc12f5866 Split data structures (linked lists, growbufs, ringbufs, etc.) code into th_datastruct.[ch] module.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 #endif // TH_DATASTRUCT_H