diff options
| author | Simon Glass <[email protected]> | 2024-10-19 09:21:44 -0600 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2024-11-03 21:27:12 -0600 |
| commit | 1d49f78c362981435a88d887c777ccc445f5a4e7 (patch) | |
| tree | ccf9cde5ff3f79eb3d3b5104ddd361d5de809147 /include | |
| parent | eb6e87a7ab9f93596983b57eef08509beeedf3fb (diff) | |
alist: Add a way to get the next element
Add a new function which returns the next element after the one
provided, if it exists in the list.
Signed-off-by: Simon Glass <[email protected]>
Diffstat (limited to 'include')
| -rw-r--r-- | include/alist.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/include/alist.h b/include/alist.h index 2c78ede201e..97523af37a6 100644 --- a/include/alist.h +++ b/include/alist.h @@ -72,6 +72,21 @@ static inline bool alist_has(struct alist *lst, uint index) } /** + * alist_calc_index() - Calculate the index of an item in the list + * + * The returned element number will be -1 if the list is empty or the pointer + * pointers to before the list starts. + * + * If the pointer points to after the last item, the calculated element-number + * will be returned, even though it is greater than lst->count + * + * @lst: alist to check + * @ptr: pointer to check + * Return: element number of the pointer + */ +int alist_calc_index(const struct alist *lst, const void *ptr); + +/** * alist_err() - Check if the alist is still valid * * @lst: List to check @@ -190,6 +205,25 @@ bool alist_expand_by(struct alist *lst, uint inc_by); #define alist_add(_lst, _obj) \ ((typeof(_obj) *)alist_add_ptr(_lst, &(_obj))) +/** get next entry as a constant */ +#define alist_next(_lst, _objp) \ + ((const typeof(_objp))alist_next_ptrd(_lst, _objp)) + +/** get next entry, which can be written to */ +#define alist_nextw(_lst, _objp) \ + ((typeof(_objp))alist_next_ptrd(_lst, _objp)) + +/** + * alist_next_ptrd() - Get a pointer to the next list element + * + * This returns NULL if the requested element is beyond lst->count + * + * @lst: List to check + * @ptr: Pointer to current element (must be valid) + * Return: Pointer to next element, or NULL if @ptr is the last + */ +const void *alist_next_ptrd(const struct alist *lst, const void *ptr); + /** * alist_init() - Set up a new object list * |
