![]() |
MySQL 8.0.40
Source Code Documentation
|
List utilities. More...
Go to the source code of this file.
Classes | |
struct | ut_list_node< Type > |
The two way list node. More... | |
struct | ut_list_base< Type, NodeGetter > |
The two-way list base node. More... | |
class | ut_list_base< Type, NodeGetter >::base_iterator< E > |
class | ut_list_base< Type, NodeGetter >::Removable |
A helper wrapper class for the list, which exposes begin(),end() iterators which let you remove the current item or items after it during the loop, while still having O(1) space and time complexity. More... | |
class | ut_list_base< Type, NodeGetter >::Removable::iterator |
struct | ut_list_base_explicit_getter< Type, node_ptr > |
struct | NullValidate |
Macros | |
#define | UT_LIST_NODE_T(t) ut_list_node<t> |
Macro used for legacy reasons. More... | |
#define | UT_LIST_INITIALISED 0xCAFE |
#define | UT_LIST_IS_INITIALISED(b) ((b).init == UT_LIST_INITIALISED) |
#define | UT_LIST_BASE_NODE_T(t, m) ut_list_base<t, ut_list_base_explicit_getter<t, &t::m>> |
A type of a list storing pointers to t, chained by member m of t. More... | |
#define | UT_LIST_NODE_GETTER(t, m) t##_##m##_node_getter |
A helper for the UT_LIST_BASE_NODE_T_EXTERN which builds a name of a node getter struct from the name of elem type t, and its member name m. More... | |
#define | UT_LIST_NODE_GETTER_DEFINITION(t, m) |
A helper for the UT_LIST_BASE_NODE_T_EXTERN which declares a node getter struct which extracts member m from element of type t. More... | |
#define | UT_LIST_BASE_NODE_T_EXTERN(t, m) ut_list_base<t, struct UT_LIST_NODE_GETTER(t, m)> |
A variant of UT_LIST_BASE_NODE_T to be used in rare cases where the full definition of t is not yet in scope, and thus UT_LIST_BASE_NODE_T can't be used yet as it needs to know how to access member m of t. More... | |
#define | UT_LIST_INIT(b) |
Initializes the base node of a two-way list. More... | |
#define | UT_LIST_ADD_FIRST(LIST, ELEM) ut_list_prepend(LIST, ELEM) |
Adds the node as the first element in a two-way linked list. More... | |
#define | UT_LIST_ADD_LAST(LIST, ELEM) ut_list_append(LIST, ELEM) |
Adds the node as the last element in a two-way linked list. More... | |
#define | UT_LIST_INSERT_AFTER(LIST, ELEM1, ELEM2) ut_list_insert(LIST, ELEM1, ELEM2) |
Inserts a ELEM2 after ELEM1 in a list. More... | |
#define | UT_LIST_REMOVE(LIST, ELEM) ut_list_remove(LIST, ELEM) |
Removes a node from a two-way linked list. More... | |
#define | UT_LIST_GET_NEXT(NAME, N) (((N)->NAME).next) |
Gets the next node in a two-way list. More... | |
#define | UT_LIST_GET_PREV(NAME, N) (((N)->NAME).prev) |
Gets the previous node in a two-way list. More... | |
#define | UT_LIST_GET_LEN(BASE) (BASE).get_length() |
Alternative macro to get the number of nodes in a two-way list, i.e., its length. More... | |
#define | UT_LIST_GET_FIRST(BASE) (BASE).first_element |
Gets the first node in a two-way list. More... | |
#define | UT_LIST_GET_LAST(BASE) (BASE).last_element |
Gets the last node in a two-way list. More... | |
#define | UT_LIST_REVERSE(LIST) ut_list_reverse(LIST) |
#define | UT_LIST_CHECK(LIST) |
Check the consistency of a two-way list. More... | |
Functions | |
template<typename List > | |
void | ut_list_prepend (List &list, typename List::elem_type *elem) |
Adds the node as the first element in a two-way linked list. More... | |
template<typename List > | |
void | ut_list_append (List &list, typename List::elem_type *elem) |
Adds the node as the last element in a two-way linked list. More... | |
template<typename List > | |
void | ut_list_insert (List &list, typename List::elem_type *elem1, typename List::elem_type *elem2) |
Inserts a ELEM2 after ELEM1 in a list. More... | |
template<typename List > | |
void | ut_list_remove (List &list, typename List::elem_type *elem) |
Removes a node from a two-way linked list. More... | |
template<typename List , class Functor > | |
void | ut_list_map (const List &list, Functor &functor) |
Iterate over all the elements and call the functor for each element. More... | |
template<typename List > | |
void | ut_list_reverse (List &list) |
template<typename List , class Functor > | |
void | ut_list_validate (const List &list, Functor &functor) |
Checks the consistency of a two-way list. More... | |
template<typename List > | |
void | ut_list_move_to_front (List &list, typename List::elem_type *elem) |
Move the given element to the beginning of the list. More... | |
template<typename List > | |
bool | ut_list_exists (List &list, typename List::elem_type *elem) |
Check if the given element exists in the list. More... | |
List utilities.
Created 9/10/1995 Heikki Tuuri Rewritten by Sunny Bains Dec 2011.
#define UT_LIST_ADD_FIRST | ( | LIST, | |
ELEM | |||
) | ut_list_prepend(LIST, ELEM) |
Adds the node as the first element in a two-way linked list.
LIST | the base node (not a pointer to it) |
ELEM | the element to add |
#define UT_LIST_ADD_LAST | ( | LIST, | |
ELEM | |||
) | ut_list_append(LIST, ELEM) |
Adds the node as the last element in a two-way linked list.
LIST | list base node (not a pointer to it) |
ELEM | the element to add |
#define UT_LIST_BASE_NODE_T | ( | t, | |
m | |||
) | ut_list_base<t, ut_list_base_explicit_getter<t, &t::m>> |
A type of a list storing pointers to t, chained by member m of t.
NOTE: In cases in which definition of t is not yet in scope and thus you can't refer to t::m at this point yet, use UT_LIST_BASE_NODE_T_EXTERN macro instead.
#define UT_LIST_BASE_NODE_T_EXTERN | ( | t, | |
m | |||
) | ut_list_base<t, struct UT_LIST_NODE_GETTER(t, m)> |
A variant of UT_LIST_BASE_NODE_T to be used in rare cases where the full definition of t is not yet in scope, and thus UT_LIST_BASE_NODE_T can't be used yet as it needs to know how to access member m of t.
The trick used here is to forward declare UT_LIST_NODE_GETTER(t,m) struct to be defined later by the UT_LIST_NODE_GETTER_DEFINITION(t,m) once t::m is defined.
#define UT_LIST_CHECK | ( | LIST | ) |
#define UT_LIST_GET_FIRST | ( | BASE | ) | (BASE).first_element |
Gets the first node in a two-way list.
BASE | the base node (not a pointer to it) |
#define UT_LIST_GET_LAST | ( | BASE | ) | (BASE).last_element |
Gets the last node in a two-way list.
BASE | the base node (not a pointer to it) |
#define UT_LIST_GET_LEN | ( | BASE | ) | (BASE).get_length() |
Alternative macro to get the number of nodes in a two-way list, i.e., its length.
BASE | the base node (not a pointer to it). |
Gets the next node in a two-way list.
NAME | list name |
N | pointer to a node |
Gets the previous node in a two-way list.
NAME | list name |
N | pointer to a node |
#define UT_LIST_INIT | ( | b | ) |
Initializes the base node of a two-way list.
b | the list base node |
#define UT_LIST_INITIALISED 0xCAFE |
#define UT_LIST_INSERT_AFTER | ( | LIST, | |
ELEM1, | |||
ELEM2 | |||
) | ut_list_insert(LIST, ELEM1, ELEM2) |
Inserts a ELEM2 after ELEM1 in a list.
LIST | list base node (not a pointer to it) |
ELEM1 | node after which ELEM2 is inserted |
ELEM2 | node being inserted after ELEM1 |
#define UT_LIST_IS_INITIALISED | ( | b | ) | ((b).init == UT_LIST_INITIALISED) |
#define UT_LIST_NODE_GETTER | ( | t, | |
m | |||
) | t##_##m##_node_getter |
A helper for the UT_LIST_BASE_NODE_T_EXTERN which builds a name of a node getter struct from the name of elem type t, and its member name m.
#define UT_LIST_NODE_GETTER_DEFINITION | ( | t, | |
m | |||
) |
A helper for the UT_LIST_BASE_NODE_T_EXTERN which declares a node getter struct which extracts member m from element of type t.
Note that the definition of the get_node function is inline, so this declaration/definition can appear multiple times in our codebase, and the intent is that you simply put it in the header which defines member m of t for the first time, so that it is accessible. This way all the places in codebase which know how to access m from t, will be also able to use this node getter, and thus iterate over a list chained by it. This also ensures, that for(auto elem: list) loops can be fully inlined by the compiler as it can see through the get_node implementation, because each place in code which knows that get_node exists also knows its implementation.
#define UT_LIST_NODE_T | ( | t | ) | ut_list_node<t> |
Macro used for legacy reasons.
#define UT_LIST_REMOVE | ( | LIST, | |
ELEM | |||
) | ut_list_remove(LIST, ELEM) |
Removes a node from a two-way linked list.
LIST | the base node (not a pointer to it) |
ELEM | node to be removed from the list |
#define UT_LIST_REVERSE | ( | LIST | ) | ut_list_reverse(LIST) |
Adds the node as the last element in a two-way linked list.
list | list |
elem | the element to add |
Check if the given element exists in the list.
[in,out] | list | the list object |
[in] | elem | the element of the list which will be checked |
void ut_list_insert | ( | List & | list, |
typename List::elem_type * | elem1, | ||
typename List::elem_type * | elem2 | ||
) |
Inserts a ELEM2 after ELEM1 in a list.
list | the base node |
elem1 | node after which ELEM2 is inserted |
elem2 | node being inserted after ELEM1 |
Iterate over all the elements and call the functor for each element.
[in] | list | base node (not a pointer to it) |
[in,out] | functor | Functor that is called for each element in the list |
void ut_list_move_to_front | ( | List & | list, |
typename List::elem_type * | elem | ||
) |
Move the given element to the beginning of the list.
[in,out] | list | the list object |
[in] | elem | the element of the list which will be moved to the beginning of the list. |
Adds the node as the first element in a two-way linked list.
list | the base node (not a pointer to it) |
elem | the element to add |
Removes a node from a two-way linked list.
list | the base node (not a pointer to it) |
elem | pointer to the element to remove from the list |