The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Tree list implementation. More...
#include <freeradius-devel/util/dlist.h>
Go to the source code of this file.
Data Structures | |
struct | fr_tlist_head_s |
struct | fr_tlist_s |
Macros | |
#define | FR_TLIST_ENTRY(_name) _name ## _entry_t |
Expands to the type name used for the entry wrapper structure. More... | |
#define | fr_tlist_foreach_entry(_list_head, _iter) for (void *_iter = fr_dlist_head(&_list_head->dlist_head); _iter; _iter = fr_dlist_next(&_list_head->dlist_head, _iter)) |
Iterate over the contents of a list, only one level. More... | |
#define | FR_TLIST_FUNCS(_name, _element_type, _element_entry) |
Define type specific wrapper functions for tlists. More... | |
#define | FR_TLIST_HEAD(_name) _name ## _head_t |
Expands to the type name used for the head wrapper structure. More... | |
#define | fr_tlist_init(_head, _type, _field) _Generic((((_type *)0)->_field), fr_tlist_t: _fr_tlist_init(_head, offsetof(_type, _field), NULL)) |
Initialise the head structure of a tlist. More... | |
#define | fr_tlist_talloc_init(_head, _type, _field) _Generic((((_type *)0)->_field), fr_tlist_t: _fr_tlist_init(_head, offsetof(_type, _field), #_type)) |
Initialise the head structure of a tlist. More... | |
#define | FR_TLIST_TYPES(_name) |
Define type specific wrapper structs for tlists. More... | |
#define | FR_TLIST_VERIFY(_head) fr_tlist_verify(__FILE__, __LINE__, _head) |
#define | tlist_type(_list) ((_list)->dlist_head.type) |
Typedefs | |
typedef struct fr_tlist_head_s | fr_tlist_head_t |
typedef struct fr_tlist_s | fr_tlist_t |
Functions | |
static void | _fr_tlist_init (fr_tlist_head_t *list_head, size_t offset, char const *type) |
Initialise common fields in a tlist. More... | |
static int | fr_tlist_add_children (fr_tlist_t *entry, fr_tlist_head_t *children) |
Add a pre-initialized child tlist to a parent entry. More... | |
static void | fr_tlist_clear (fr_tlist_head_t *list_head) |
Remove all elements in a tlist. More... | |
static bool | fr_tlist_empty (fr_tlist_head_t const *list_head) |
Check whether a list has any items. More... | |
static bool | fr_tlist_entry_in_a_list (fr_tlist_t const *entry) |
Check if a list entry is part of a list. More... | |
static void | fr_tlist_entry_init (fr_tlist_t *entry) |
Initialise a linked list without metadata. More... | |
static void * | fr_tlist_entry_to_item (fr_tlist_head_t const *list_head, fr_tlist_t const *entry) |
Get the item from a fr_tlist_t. More... | |
static void | fr_tlist_entry_unlink (fr_tlist_t *entry) |
static void * | fr_tlist_head (fr_tlist_head_t const *list_head) |
Return the HEAD item of a list or NULL if the list is empty. More... | |
static fr_tlist_head_t * | fr_tlist_head_from_dlist (fr_dlist_head_t *dlist_head) |
Get a fr_tlist_head_t from a fr_dlist_head_t. More... | |
static bool | fr_tlist_in_list (fr_tlist_head_t *list_head, void *ptr) |
Check if a list entry is part of a tlist. More... | |
static void | fr_tlist_init_children (fr_tlist_t *entry, fr_tlist_head_t *children) |
Initialize a child tlist based on a parent entry. More... | |
static bool | fr_tlist_initialised (fr_tlist_head_t const *list_head) |
Check if the list head is initialised. More... | |
static int | fr_tlist_insert_after (fr_tlist_head_t *list_head, void *pos, void *ptr) |
Insert an item after an item already in the list. More... | |
static int | fr_tlist_insert_before (fr_tlist_head_t *list_head, void *pos, void *ptr) |
Insert an item after an item already in the list. More... | |
static int | fr_tlist_insert_head (fr_tlist_head_t *list_head, void *ptr) |
Insert an item into the head of a list. More... | |
static int | fr_tlist_insert_tail (fr_tlist_head_t *list_head, void *ptr) |
Insert an item into the tail of a list. More... | |
static fr_tlist_t * | fr_tlist_item_to_entry (fr_tlist_head_t const *list_head, void const *item) |
Find the tlist pointers within a list item. More... | |
static int | fr_tlist_move (fr_tlist_head_t *list_dst, fr_tlist_head_t *list_src) |
Merge two lists, inserting the source at the tail of the destination. More... | |
static int | fr_tlist_move_head (fr_tlist_head_t *list_dst, fr_tlist_head_t *list_src) |
Merge two lists, inserting the source at the head of the destination. More... | |
static void * | fr_tlist_next (fr_tlist_head_t const *list_head, void const *ptr) |
Get the next item in a list. More... | |
static void | fr_tlist_noop (void) |
static unsigned int | fr_tlist_num_elements (fr_tlist_head_t const *list_head) |
Return the number of elements in the tlist. More... | |
static void * | fr_tlist_parent (fr_tlist_head_t *list_head, void const *ptr) |
static void * | fr_tlist_pop_head (fr_tlist_head_t *list_head) |
Remove the head item in a list. More... | |
static void * | fr_tlist_pop_tail (fr_tlist_head_t *list_head) |
Remove the tail item in a list. More... | |
static void * | fr_tlist_prev (fr_tlist_head_t const *list_head, void const *ptr) |
Get the previous item in a list. More... | |
static void | fr_tlist_recursive_sort (fr_tlist_head_t *head, void **ptr, fr_cmp_t cmp) |
Recursive sort routine for tlist. More... | |
static void * | fr_tlist_remove (fr_tlist_head_t *list_head, void *ptr) |
Remove an item from the list. More... | |
static fr_tlist_head_t * | fr_tlist_remove_children (fr_tlist_t *entry) |
Remove a child tlist from a parent entry. More... | |
static void * | fr_tlist_replace (fr_tlist_head_t *list_head, void *item, void *ptr) |
Replace an item in a dlist. More... | |
static void | fr_tlist_sort (fr_tlist_head_t *list, fr_cmp_t cmp) |
Sort a tlist using merge sort. More... | |
static void * | fr_tlist_sort_merge (fr_tlist_head_t *head, void **a, void **b, fr_cmp_t cmp) |
Merge phase of a merge sort of a dlist. More... | |
static void | fr_tlist_sort_split (fr_tlist_head_t *head, void **source, void **front, void **back) |
Split phase of a merge sort of a dlist. More... | |
static void * | fr_tlist_tail (fr_tlist_head_t const *list_head) |
Return the TAIL item of a list or NULL if the list is empty. More... | |
static void | fr_tlist_talloc_free (fr_tlist_head_t *head) |
Free all items in a doubly linked list (with talloc) More... | |
static void | fr_tlist_talloc_free_head (fr_tlist_head_t *list_head) |
Free the first item in the list. More... | |
static void * | fr_tlist_talloc_free_item (fr_tlist_head_t *list_head, void *ptr) |
Free the item specified. More... | |
static void | fr_tlist_talloc_free_tail (fr_tlist_head_t *list_head) |
Free the last item in the list. More... | |
static void | fr_tlist_talloc_free_to_tail (fr_tlist_head_t *head, void *ptr) |
Free items in a doubly linked list (with talloc) More... | |
static void | fr_tlist_talloc_reverse_free (fr_tlist_head_t *head) |
Free all items in a doubly linked list from the tail backwards. More... | |
static void | fr_tlist_verify (char const *file, int line, fr_tlist_head_t const *list_head) |
Check all items in the list are valid. More... | |
Tree list implementation.
Definition in file tlist.h.
struct fr_tlist_head_s |
Data Fields | ||
---|---|---|
fr_dlist_head_t | dlist_head | |
fr_tlist_t * | parent | the parent entry which holds this list. May be NULL. |
struct fr_tlist_s |
Data Fields | ||
---|---|---|
fr_tlist_head_t * | children | any child list |
fr_dlist_t | dlist_entry | the doubly linked list of entries. |
fr_tlist_head_t * | list_head | the list which holds this entry |
#define FR_TLIST_ENTRY | ( | _name | ) | _name ## _entry_t |
#define fr_tlist_foreach_entry | ( | _list_head, | |
_iter | |||
) | for (void *_iter = fr_dlist_head(&_list_head->dlist_head); _iter; _iter = fr_dlist_next(&_list_head->dlist_head, _iter)) |
#define FR_TLIST_FUNCS | ( | _name, | |
_element_type, | |||
_element_entry | |||
) |
Define type specific wrapper functions for tlists.
[in] | _name | Prefix we add to type-specific tlist functions. |
[in] | _element_type | Type of structure that'll be inserted into the tlist. |
[in] | _element_entry | Field in the _element_type that holds the tlist entry information. |
#define FR_TLIST_HEAD | ( | _name | ) | _name ## _head_t |
#define fr_tlist_init | ( | _head, | |
_type, | |||
_field | |||
) | _Generic((((_type *)0)->_field), fr_tlist_t: _fr_tlist_init(_head, offsetof(_type, _field), NULL)) |
Initialise the head structure of a tlist.
This function should only be called for the top level of the list. Please call fr_tlist_add_child() when adding a child list to an existing entry.
[in] | _head | structure to initialise. |
[in] | _type | of item being stored in the list, e.g. fr_value_box_t, fr_dict_attr_t etc... |
[in] | _field | Containing the fr_tlist_t within item being stored. |
#define fr_tlist_talloc_init | ( | _head, | |
_type, | |||
_field | |||
) | _Generic((((_type *)0)->_field), fr_tlist_t: _fr_tlist_init(_head, offsetof(_type, _field), #_type)) |
Initialise the head structure of a tlist.
Initialise the head structure of a tlist.
[in] | _head | structure to initialise. |
[in] | _type | of item being stored in the list, e.g. fr_value_box_t, fr_dict_attr_t etc... |
[in] | _field | Containing the fr_tlist_t within item being stored. |
#define FR_TLIST_TYPES | ( | _name | ) |
Define type specific wrapper structs for tlists.
#define FR_TLIST_VERIFY | ( | _head | ) | fr_tlist_verify(__FILE__, __LINE__, _head) |
#define tlist_type | ( | _list | ) | ((_list)->dlist_head.type) |
typedef struct fr_tlist_head_s fr_tlist_head_t |
typedef struct fr_tlist_s fr_tlist_t |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Check if a list entry is part of a list.
This works because the fr_tlist_head_t has an entry in the list. So if next and prev both point to the entry for the object being passed in, then it can't be part of a list with a fr_tlist_head_t.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Get a fr_tlist_head_t from a fr_dlist_head_t.
Definition at line 69 of file tlist.h.
|
inlinestatic |
Check if a list entry is part of a tlist.
This works because the fr_tlist_head_t has an entry in the list. So if next and prev both point to the entry for the object being passed in, then it can't be part of a list with a fr_tlist_head_t.
Definition at line 206 of file tlist.h.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Insert an item after an item already in the list.
[in] | list_head | to insert ptr into. |
[in] | pos | to insert ptr after. |
[in] | ptr | to insert. |
Definition at line 267 of file tlist.h.
|
inlinestatic |
Insert an item after an item already in the list.
[in] | list_head | to insert ptr into. |
[in] | pos | to insert ptr before. |
[in] | ptr | to insert. |
Definition at line 289 of file tlist.h.
|
inlinestatic |
Insert an item into the head of a list.
[in] | list_head | to insert ptr into. |
[in] | ptr | to insert. |
Definition at line 224 of file tlist.h.
|
inlinestatic |
Insert an item into the tail of a list.
[in] | list_head | to insert ptr into. |
[in] | ptr | to insert. |
Definition at line 245 of file tlist.h.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Get the next item in a list.
[in] | list_head | containing ptr. |
[in] | ptr | to retrieve the next item from. If ptr is NULL, the HEAD of the list will be returned. |
Definition at line 362 of file tlist.h.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Get the previous item in a list.
[in] | list_head | containing ptr. |
[in] | ptr | to retrieve the prev item from. If ptr is NULL, the HEAD of the list will be returned. |
Definition at line 380 of file tlist.h.
|
inlinestatic |
|
inlinestatic |
Remove an item from the list.
When removing items in an iteration loop, the iterator variable must be assigned the item returned by this function.
If the iterator variable is not updated, the item removed will be the last item iterated over, as its prev/prev pointers are set to point to itself.
[in] | list_head | to remove ptr from. |
[in] | ptr | to remove. |
Definition at line 413 of file tlist.h.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Merge phase of a merge sort of a dlist.
[in] | head | of the original list being sorted |
[in] | a | first element of first list being merged |
[in] | b | first element of second list being merged |
[in] | cmp | comparison function for the sort |
Definition at line 723 of file tlist.h.
|
inlinestatic |
Split phase of a merge sort of a dlist.
[in] | head | of the original list being sorted |
[in] | source | first item in the section of the list to split |
[out] | front | first item of the first half of the split list |
[out] | back | first item of the second half of the split list |
Definition at line 708 of file tlist.h.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Check all items in the list are valid.
Checks item talloc headers and types to ensure they're consistent with what we expect.
Does nothing if the list was not initialised with fr_tlist_talloc_init.
Definition at line 489 of file tlist.h.