Linear Array data structure. More...
Include dependency graph for array.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Macros | |
| #define | ARRAY_HEADROOM 25 |
| Additional number of elements to reserve, to prevent frequent reallocations. | |
| #define | ARRAY_HEAD(name, type) |
| Define a named struct for arrays of elements of a certain type. | |
| #define | ARRAY_HEAD_INITIALIZER { 0, 0, NULL } |
| Static initializer for arrays. | |
| #define | ARRAY_INIT(head) |
| Initialize an array. | |
| #define | ARRAY_EMPTY(head) |
| Check if an array is empty. | |
| #define | ARRAY_SIZE(head) |
| The number of elements stored. | |
| #define | ARRAY_CAPACITY(head) |
| The number of elements the array can store without reallocation. | |
| #define | ARRAY_GET(head, idx) |
| Return the element at index. | |
| #define | ARRAY_SET(head, idx, elem) |
| Set an element in the array. | |
| #define | ARRAY_FIRST(head) |
| Convenience method to get the first element. | |
| #define | ARRAY_LAST(head) |
| Convenience method to get the last element. | |
| #define | ARRAY_ADD(head, elem) |
| Add an element at the end of the array. | |
| #define | ARRAY_SHRINK(head, num) |
| Mark a number of slots at the end of the array as unused. | |
| #define | ARRAY_ELEM_SIZE(head) |
| Number of bytes occupied by an element of this array. | |
| #define | ARRAY_RESERVE(head, num) |
| Reserve memory for the array. | |
| #define | ARRAY_FREE(head) |
| Release all memory. | |
| #define | ARRAY_FOREACH(elem, head) |
| Iterate over all elements of the array. | |
| #define | ARRAY_FOREACH_FROM(elem, head, from) |
| Iterate from an index to the end. | |
| #define | ARRAY_FOREACH_TO(elem, head, to) |
| Iterate from the beginning to an index. | |
| #define | ARRAY_FOREACH_FROM_TO(elem, head, from, to) |
| Iterate between two indexes. | |
| #define | ARRAY_FOREACH_REVERSE(elem, head) |
| Iterate backwards over all elements of the array. | |
| #define | ARRAY_FOREACH_REVERSE_FROM(elem, head, from) |
| Iterate from an index to the beginning. | |
| #define | ARRAY_FOREACH_REVERSE_TO(elem, head, to) |
| Iterate from the end to an index. | |
| #define | ARRAY_FOREACH_REVERSE_FROM_TO(elem, head, from, to) |
| Iterate between two indexes. | |
| #define | ARRAY_IDX(head, elem) |
| Return the index of an element of the array. | |
| #define | ARRAY_REMOVE(head, elem) |
| Remove an entry from the array, shifting down the subsequent entries. | |
| #define | ARRAY_SORT(head, fn, sdata) |
| Sort an array. | |
| #define | ARRAY_SET_NORESERVE(head, idx, elem) |
| #define | __coverity_escape__(x) |
| #define | ARRAY_ADD_NORESERVE(head, elem) |
Linear Array data structure.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file array.h.
| #define ARRAY_HEADROOM 25 |
| #define ARRAY_HEAD | ( | name, | |
| type ) |
Define a named struct for arrays of elements of a certain type.
| name | Name of the resulting struct |
| type | Type of the elements stored in the array |
Definition at line 47 of file array.h.
| #define ARRAY_HEAD_INITIALIZER { 0, 0, NULL } |
| #define ARRAY_INIT | ( | head | ) |
Initialize an array.
| head | Pointer to a struct defined using ARRAY_HEAD() |
Definition at line 65 of file array.h.
| #define ARRAY_EMPTY | ( | head | ) |
Check if an array is empty.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| true | The array is empty |
| false | The array is not empty |
Definition at line 74 of file array.h.
| #define ARRAY_SIZE | ( | head | ) |
The number of elements stored.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| num | Number of elements stored |
Definition at line 87 of file array.h.
| #define ARRAY_CAPACITY | ( | head | ) |
The number of elements the array can store without reallocation.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| num | The capacity of the array |
Definition at line 95 of file array.h.
| #define ARRAY_GET | ( | head, | |
| idx ) |
Return the element at index.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| idx | Index, between 0 and ARRAY_SIZE()-1 |
| ptr | Pointer to the element at the given index |
| NULL | Index was out of bounds |
Definition at line 109 of file array.h.
| #define ARRAY_SET | ( | head, | |
| idx, | |||
| elem ) |
Set an element in the array.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| idx | Index, between 0 and ARRAY_SIZE()-1 |
| elem | Element to copy |
| true | Element was inserted |
| false | Element was not inserted, array was full |
Definition at line 123 of file array.h.
| #define ARRAY_FIRST | ( | head | ) |
Convenience method to get the first element.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| ptr | Pointer to the first element |
| NULL | Array is empty |
Definition at line 135 of file array.h.
| #define ARRAY_LAST | ( | head | ) |
Convenience method to get the last element.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| ptr | Pointer to the last element |
| NULL | Array is empty |
Definition at line 144 of file array.h.
| #define ARRAY_ADD | ( | head, | |
| elem ) |
Add an element at the end of the array.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| elem | Element to copy |
| true | Element was added |
| false | Element was not added, array was full |
Definition at line 156 of file array.h.
| #define ARRAY_SHRINK | ( | head, | |
| num ) |
Mark a number of slots at the end of the array as unused.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| num | Number of slots to mark as unused |
| num | New size of the array |
Definition at line 172 of file array.h.
| #define ARRAY_ELEM_SIZE | ( | head | ) |
Number of bytes occupied by an element of this array.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| num | Number of bytes per element |
Definition at line 180 of file array.h.
| #define ARRAY_RESERVE | ( | head, | |
| num ) |
Reserve memory for the array.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| num | Number of elements to make room for |
| num | New capacity of the array |
Definition at line 189 of file array.h.
| #define ARRAY_FREE | ( | head | ) |
Release all memory.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| 0 | Always |
Definition at line 204 of file array.h.
| #define ARRAY_FOREACH | ( | elem, | |
| head ) |
Iterate over all elements of the array.
| elem | Variable to be used as pointer to the element at each iteration |
| head | Pointer to a struct defined using ARRAY_HEAD() |
Definition at line 214 of file array.h.
| #define ARRAY_FOREACH_FROM | ( | elem, | |
| head, | |||
| from ) |
Iterate from an index to the end.
| elem | Variable to be used as pointer to the element at each iteration |
| head | Pointer to a struct defined using ARRAY_HEAD() |
| from | Starting index (inclusive) |
Definition at line 226 of file array.h.
| #define ARRAY_FOREACH_TO | ( | elem, | |
| head, | |||
| to ) |
Iterate from the beginning to an index.
| elem | Variable to be used as pointer to the element at each iteration |
| head | Pointer to a struct defined using ARRAY_HEAD() |
| to | Terminating index (exclusive) |
Definition at line 238 of file array.h.
| #define ARRAY_FOREACH_FROM_TO | ( | elem, | |
| head, | |||
| from, | |||
| to ) |
Iterate between two indexes.
| elem | Variable to be used as pointer to the element at each iteration |
| head | Pointer to a struct defined using ARRAY_HEAD() |
| from | Starting index (inclusive) |
| to | Terminating index (exclusive) |
Definition at line 252 of file array.h.
| #define ARRAY_FOREACH_REVERSE | ( | elem, | |
| head ) |
Iterate backwards over all elements of the array.
| elem | Variable to be used as pointer to the element at each iteration |
| head | Pointer to a struct defined using ARRAY_HEAD() |
Definition at line 265 of file array.h.
| #define ARRAY_FOREACH_REVERSE_FROM | ( | elem, | |
| head, | |||
| from ) |
Iterate from an index to the beginning.
| elem | Variable to be used as pointer to the element at each iteration |
| head | Pointer to a struct defined using ARRAY_HEAD() |
| from | Starting index (exclusive) |
Definition at line 277 of file array.h.
| #define ARRAY_FOREACH_REVERSE_TO | ( | elem, | |
| head, | |||
| to ) |
Iterate from the end to an index.
| elem | Variable to be used as pointer to the element at each iteration |
| head | Pointer to a struct defined using ARRAY_HEAD() |
| to | Terminating index (inclusive) |
Definition at line 289 of file array.h.
| #define ARRAY_FOREACH_REVERSE_FROM_TO | ( | elem, | |
| head, | |||
| from, | |||
| to ) |
Iterate between two indexes.
| elem | Variable to be used as pointer to the element at each iteration |
| head | Pointer to a struct defined using ARRAY_HEAD() |
| from | Starting index (exclusive) |
| to | Terminating index (inclusive) |
Definition at line 303 of file array.h.
| #define ARRAY_IDX | ( | head, | |
| elem ) |
Return the index of an element of the array.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| elem | Pointer to an element of the array |
| num | The index of element in the array |
Definition at line 315 of file array.h.
| #define ARRAY_REMOVE | ( | head, | |
| elem ) |
Remove an entry from the array, shifting down the subsequent entries.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| elem | Pointer to the element of the array to remove |
Definition at line 323 of file array.h.
| #define ARRAY_SORT | ( | head, | |
| fn, | |||
| sdata ) |
Sort an array.
| head | Pointer to a struct defined using ARRAY_HEAD() |
| fn | Sort function, see sort_t |
| sdata | Opaque argument to pass to sort function |
Definition at line 335 of file array.h.
| #define ARRAY_SET_NORESERVE | ( | head, | |
| idx, | |||
| elem ) |
Definition at line 342 of file array.h.
| #define ARRAY_ADD_NORESERVE | ( | head, | |
| elem ) |
Definition at line 352 of file array.h.