Mstdlib-1.24.0
|
Data Structures | |
struct | M_llist_callbacks |
Typedefs | |
typedef struct M_llist | M_llist_t |
typedef struct M_llist_node | M_llist_node_t |
typedef void *(* | M_llist_duplicate_func) (const void *) |
typedef void(* | M_llist_free_func) (void *) |
Enumerations | |
enum | M_llist_flags_t { M_LLIST_NONE = 0 , M_LLIST_SORTED = 1 << 0 , M_LLIST_CIRCULAR = 1 << 1 } |
enum | M_llist_match_type_t { M_LLIST_MATCH_VAL = 0 , M_LLIST_MATCH_PTR = 1 << 0 , M_LLIST_MATCH_ALL = 1 << 1 } |
Linked list for storing values.
This should not be used directly. It is a base implementation that should be used by a type safe wrapper. For example: M_llist_str.
The list can uses a set of callback functions to determine behavior. Such as if it should duplicate or free values.
The list can be used in multiple ways:
A linked list is not indexable. Iteration and find are supported.
Sorted notes:
struct M_llist_callbacks |
Structure of callbacks that can be registered to override default behavior for llist implementation.
Data Fields | ||
---|---|---|
M_sort_compar_t | equality |
Callback to check if two items in the list are equal. If NULL unsorted list |
M_llist_duplicate_func | duplicate_insert |
Callback to duplicate a value on insert. If NULL is pass-thru pointer |
M_llist_duplicate_func | duplicate_copy |
Callback to duplicate a value on copy. If NULL is pass-thru pointer |
M_llist_free_func | value_free |
Callback to free a value. If NULL is pass-thru pointer |
typedef struct M_llist M_llist_t |
typedef struct M_llist_node M_llist_node_t |
typedef void *(* M_llist_duplicate_func) (const void *) |
Function definition to duplicate a value.
typedef void(* M_llist_free_func) (void *) |
Function definition to free a value.
enum M_llist_flags_t |
Flags for controlling the behavior of the list.
enum M_llist_match_type_t |
M_llist_t * M_llist_create | ( | const struct M_llist_callbacks * | callbacks, |
M_uint32 | flags | ||
) |
Create a new list.
A list is a linked list. The list can be, optionally, kept in sorted order. The sorted order is determined by the equality callback function if sorting is enabled.
[in] | callbacks | Register callbacks for overriding default behavior. May pass NULL if not overriding default behavior. |
[in] | flags | M_llist_flags_t flags controlling behavior. |
M_bool M_llist_change_sorting | ( | M_llist_t * | d, |
M_sort_compar_t | equality_cb, | ||
void * | equality_thunk | ||
) |
Use the provided callback and thunk for sorting.
d | the llist to update |
equality_cb | callback that should be used for sorting |
equality_thunk | thunk to pass to callback, may be NULL . Ownership of thunk remains with caller. |
void M_llist_destroy | ( | M_llist_t * | d, |
M_bool | destroy_vals | ||
) |
Destroy the list.
[in] | d | The llist to destory. |
[in] | destroy_vals | Whether the values held in the list should be destroyed. If the list is not duplicating the values it holds then destroying values may not be desirable. |
M_llist_node_t * M_llist_insert | ( | M_llist_t * | d, |
const void * | val | ||
) |
Insert a value into the list.
If sorted the value will be inserted in sorted order. Otherwise it will be appended to the end of the list.
[in,out] | d | The list. |
[in] | val | The value to insert. |
M_llist_node_t * M_llist_insert_first | ( | M_llist_t * | d, |
const void * | val | ||
) |
Insert a value into the list as the first node.
Only applies to unsorted lists.
[in,out] | d | The list. |
[in] | val | The value to insert. |
M_llist_node_t * M_llist_insert_before | ( | M_llist_node_t * | n, |
const void * | val | ||
) |
Insert a value into the list before a given node.
Only applies to unsorted lists.
[in,out] | n | The node to insert before. Cannot be NULL. |
[in] | val | The value to insert. |
M_llist_node_t * M_llist_insert_after | ( | M_llist_node_t * | n, |
const void * | val | ||
) |
Insert a value into the list after a given node.
Only applies to unsorted lists.
[in,out] | n | The node to insert after. Cannot be NULL. |
[in] | val | The value to insert. |
void M_llist_set_first | ( | M_llist_node_t * | n | ) |
Set the node as the first node.
Only applies to unsorted or circular lists.
[in] | n | The node that should be considered first. |
void M_llist_set_last | ( | M_llist_node_t * | n | ) |
Set the node as the last node.
Only applies to unsorted or circular lists.
[in] | n | The node that should be considered last. |
M_bool M_llist_move_before | ( | M_llist_node_t * | move, |
M_llist_node_t * | before | ||
) |
Move a node before another node in the list.
[in] | move | The node to move. |
[in] | before | The node that move should be placed before. |
M_bool M_llist_move_after | ( | M_llist_node_t * | move, |
M_llist_node_t * | after | ||
) |
Move a node after another node in the list.
[in] | move | The node to move. |
[in] | after | The node that move should be placed after. |
size_t M_llist_len | ( | const M_llist_t * | d | ) |
The length of the list.
[in] | d | The list. |
size_t M_llist_count | ( | const M_llist_t * | d, |
const void * | val, | ||
M_uint32 | type | ||
) |
Count the number of times a value occurs in the list.
[in] | d | The list. |
[in] | val | The value to search for. |
[in] | type | M_llist_match_type_t type of how the val should be matched. valid values are:
|
M_llist_node_t * M_llist_first | ( | const M_llist_t * | d | ) |
Get the first node in the list.
[in] | d | The list. |
M_llist_node_t * M_llist_last | ( | const M_llist_t * | d | ) |
Get the last node in the list.
[in] | d | The list. |
M_llist_node_t * M_llist_find | ( | const M_llist_t * | d, |
const void * | val, | ||
M_uint32 | type | ||
) |
Find a node for the given value in the list.
[in] | d | The list. |
[in] | val | The value to search for. |
[in] | type | M_llist_match_type_t type of how the val should be matched. valid values are:
|
void * M_llist_take_node | ( | M_llist_node_t * | n | ) |
Take the node from the list and return its value.
The element will be removed from the list and its value returned. The caller is responsible for freeing the value.
[in] | n | The node. |
M_bool M_llist_remove_node | ( | M_llist_node_t * | n | ) |
Remove a node from the list.
The value will be free'd using the value_free callback.
[in] | n | The node. |
size_t M_llist_remove_val | ( | M_llist_t * | d, |
const void * | val, | ||
M_uint32 | type | ||
) |
Remove node(s) from the list matching a given value.
The value will be free'd using the value_free callback.
[in,out] | d | The list. |
[in] | val | The value to search for. |
[in] | type | M_llist_match_type_t type of how the val should be matched. valid values are:
|
void M_llist_remove_duplicates | ( | M_llist_t * | d, |
M_uint32 | type | ||
) |
Remove duplicate values from the list.
Requires the equality callback to be set. The values will be free'd using the value_free callback.
[in] | d | The list. |
[in] | type | M_llist_match_type_t type of how the val should be matched. valid values are:
|
M_llist_node_t * M_llist_node_next | ( | const M_llist_node_t * | n | ) |
Get the next node, the one after a given node.
[in] | n | The node. |
M_llist_node_t * M_llist_node_prev | ( | const M_llist_node_t * | n | ) |
Get the previous node, the one before a given node.
[in] | n | The node. |
void * M_llist_node_val | ( | const M_llist_node_t * | n | ) |
Get the value for a node.
[in] | n | The node. |
Duplicate an existing list. Will copy all elements of the list as well as any callbacks, etc.
[in] | d | list to duplicate. |
Merge two lists together.
The second (src) list will be destroyed automatically upon completion of this function. Any value pointers for the list will be directly copied over to the destination list, they will not be duplicated.
[in,out] | dest | Pointer by reference to the list receiving the values. if this is NULL, the pointer will simply be switched out for src. |
[in,out] | src | Pointer to the list giving up its values. |
[in] | include_duplicates | When M_TRUE any values in 'dest' that also exist in 'src' will be included in 'dest'. When M_FALSE any duplicate values will not be added to 'dest'. |
[in] | type | M_llist_match_type_t type of how the val should be matched. valid values are:
|