Graphviz 13.1.3~dev.20250831.0023
|
internal implementation details of list.h More...
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <util/api.h>
Go to the source code of this file.
Data Structures | |
struct | list_t_ |
Macros | |
#define | LIST_DTOR_(list, slot) |
Functions | |
static size_t | gv_list_size_ (const list_t_ list) |
UTIL_API bool | gv_list_try_reserve_ (list_t_ *list, size_t capacity, size_t item_size) |
UTIL_API size_t | gv_list_append_slot_ (list_t_ *list, size_t item_size) |
UTIL_API size_t | gv_list_prepend_slot_ (list_t_ *list, size_t item_size) |
UTIL_API size_t | gv_list_get_ (const list_t_ list, size_t index) |
UTIL_API size_t | gv_list_find_ (const list_t_ list, const void *needle, size_t item_size) |
UTIL_API void | gv_list_remove_ (list_t_ *list, size_t index, size_t item_size) |
UTIL_API void | gv_list_clear_ (list_t_ *list, size_t item_size) |
UTIL_API void | gv_list_reserve_ (list_t_ *list, size_t capacity, size_t item_size) |
UTIL_API bool | gv_list_contains_ (const list_t_ list, const void *needle, size_t item_size) |
UTIL_API list_t_ | gv_list_copy_ (const list_t_ list, size_t item_size) |
UTIL_API bool | gv_list_is_contiguous_ (const list_t_ list) |
UTIL_API void | gv_list_sync_ (list_t_ *list, size_t item_size) |
UTIL_API void | gv_list_sort_ (list_t_ *list, int(*cmp)(const void *, const void *), size_t item_size) |
UTIL_API void | gv_list_reverse_ (list_t_ *list, size_t item_size) |
UTIL_API void | gv_list_shrink_to_fit_ (list_t_ *list, size_t item_size) |
UTIL_API void | gv_list_free_ (list_t_ *list) |
UTIL_API void | gv_list_pop_front_ (list_t_ *list, void *into, size_t item_size) |
UTIL_API void | gv_list_pop_back_ (list_t_ *list, void *into, size_t item_size) |
Everything in this header should be considered “private” in the sense that it should not be called except by macros in list.h.
Definition in file list-private.h.
#define LIST_DTOR_ | ( | list, | |
slot | |||
) |
run the destructor of a list on a given slot
Though this uses the public type LIST(<type>)
defined in list.h, this is an internal API not expected to be called by anything other than the macros in list.h.
You can think of this macro as having the following C type:
void LIST_DTOR_(LIST(<type>) *list, size_t slot);
list | List to operate on |
slot | Slot to destruct |
Definition at line 87 of file list-private.h.
add an empty space for an item to the end of a list
This function calls exit
on failure.
list | List to operate on |
item_size | Byte size of each list item |
Definition at line 54 of file list.c.
References ASAN_UNPOISON, list_t_::capacity, gv_list_reserve_(), list_t_::head, INDEX_TO, NULL, and list_t_::size.
remove all items from a list
list | List to operate on |
item_size | Byte size of list items |
Definition at line 197 of file list.c.
References ASAN_POISON, gv_list_get_(), list_t_::head, INDEX_TO, NULL, and list_t_::size.
does a list contain a given item?
list | List to search |
needle | Item to search for |
item_size | Byte size of each list item |
Definition at line 223 of file list.c.
References gv_list_find_(), and SIZE_MAX.
make a copy of a list
This function calls exit
on failure.
list | List to copy |
item_size | Byte size of each list item |
Definition at line 228 of file list.c.
References ASAN_POISON, list_t_::base, list_t_::capacity, gv_calloc(), gv_list_get_(), INDEX_TO, and list_t_::size.
find the slot containing the given item
list | List to search |
needle | Item to search for |
item_size | Byte size of each list item |
SIZE_MAX
if not found Definition at line 166 of file list.c.
References gv_list_get_(), INDEX_TO, list_t_::size, and SIZE_MAX.
Referenced by gv_list_contains_().
free resources associated with a list
list | List to operate on |
Definition at line 333 of file list.c.
References list_t_::base, free(), and NULL.
get the slot index of a given list item index
list | List to operate on |
index | Index of item to lookup |
Definition at line 161 of file list.c.
References list_t_::capacity, list_t_::head, and list_t_::size.
Referenced by gv_list_clear_(), gv_list_copy_(), gv_list_find_(), gv_list_pop_back_(), gv_list_pop_front_(), gv_list_remove_(), and gv_list_reverse_().
does the list wrap past its end?
This checks whether the list is discontiguous in how its elements appear in memory:
┌───┬───┬───┬───┬───┬───┬───┬───┐
a contiguous list: │ │ │ w │ x │ y │ z │ │ │ └───┴───┴───┴───┴───┴───┴───┴───┘ 0 1 2 3
┌───┬───┬───┬───┬───┬───┬───┬───┐ a discontiguous list: │ y │ z │ │ │ │ │ x │ y │ └───┴───┴───┴───┴───┴───┴───┴───┘ 2 3 0 1
list | List to inspect |
Definition at line 250 of file list.c.
References list_t_::capacity, list_t_::head, and list_t_::size.
Referenced by gv_list_sync_().
remove and return the last item of a list
list | List to operate on | |
[out] | into | Destination to pop the item into |
item_size | Byte size of each list item |
Definition at line 353 of file list.c.
References ASAN_POISON, gv_list_get_(), INDEX_TO, NULL, and list_t_::size.
remove and return the first item of a list
list | List to operate on | |
[out] | into | Destination to pop the item into |
item_size | Byte size of each list item |
Definition at line 339 of file list.c.
References ASAN_POISON, list_t_::capacity, gv_list_get_(), list_t_::head, INDEX_TO, NULL, and list_t_::size.
add an empty space for an item to the beginning of a list
This function calls exit
on failure.
list | List to operate on |
item_size | Byte size of each list item |
Definition at line 75 of file list.c.
References ASAN_UNPOISON, list_t_::capacity, gv_list_reserve_(), list_t_::head, INDEX_TO, NULL, and list_t_::size.
remove a slot from a list
list | List to operate on |
index | Slot index to remove |
item_size | Byte size of each list item |
Definition at line 179 of file list.c.
References ASAN_POISON, gv_list_get_(), INDEX_TO, NULL, and list_t_::size.
reserve space for new items in a list
This function is a no-op if sufficient space is already available.
list | List to operate on |
capacity | Total number of slots to make available |
item_size | Byte size of list items |
Definition at line 212 of file list.c.
References err, graphviz_exit(), PRISIZE_T, and try_reserve().
Referenced by gv_list_append_slot_(), and gv_list_prepend_slot_().
reverse the item order of a list
list | List to operate on |
item_size | Byte size of each list item |
Definition at line 309 of file list.c.
References exchange, gv_list_get_(), INDEX_TO, NULL, and list_t_::size.
decrease the allocated capacity of a list to minimum
list | List to operate on |
item_size | Byte size of list items |
Definition at line 322 of file list.c.
References list_t_::base, list_t_::capacity, gv_list_sync_(), gv_recalloc(), NULL, and list_t_::size.
|
inlinestatic |
get the number of elements in a list
list | List to inspect |
Definition at line 39 of file list-private.h.
References list_t_::size.
UTIL_API void gv_list_sort_ | ( | list_t_ * | list, |
int(*)(const void *, const void *) | cmp, | ||
size_t | item_size | ||
) |
sort a list
list | List to operate on |
cmp | Comparator for ordering list items |
item_size | Byte size of each list item |
Definition at line 285 of file list.c.
References list_t_::base, cmp(), gv_list_sync_(), NULL, and list_t_::size.
shuffle the populated contents to reset head
to 0
See the gv_list_is_contiguous_
leading comment for a better understanding of what it means for head
to be non-zero.
list | List to operate on |
item_size | Byte size of each list item |
Definition at line 254 of file list.c.
References ASAN_POISON, ASAN_UNPOISON, list_t_::base, list_t_::capacity, gv_list_is_contiguous_(), list_t_::head, INDEX_TO, NULL, and list_t_::size.
Referenced by gv_list_shrink_to_fit_(), and gv_list_sort_().
try to reserve the given capacity for usage
list | List to operate on |
capacity | Requested size to expand to |
item_size | Byte size of each list item |
Definition at line 156 of file list.c.
References NULL, and try_reserve().