|
myMPD
Internal API documentation
|
Linked list implementation. More...
#include "src/lib/list/list.h"#include "src/lib/filehandler.h"#include "src/lib/log.h"#include "src/lib/mem.h"#include "src/lib/sds/sds_extras.h"#include <limits.h>#include <string.h>
Functions | |
| struct t_list * | list_new (void) |
| struct t_list * | list_dup (struct t_list *l) |
| bool | list_append (struct t_list *dst, struct t_list *src) |
| void | list_init (struct t_list *l) |
| void | list_clear (struct t_list *l) |
| void | list_free (struct t_list *l) |
| void | list_free_void (void *l) |
| void | list_clear_user_data (struct t_list *l, user_data_callback free_cb) |
| void | list_free_user_data (struct t_list *l, user_data_callback free_cb) |
| void | list_free_cb_ignore_user_data (struct t_list_node *current) |
| void | list_free_cb_sds_user_data (struct t_list_node *current) |
| void | list_free_cb_ptr_user_data (struct t_list_node *current) |
| unsigned | list_get_node_idx (const struct t_list *l, const char *key) |
| struct t_list_node * | list_get_node (const struct t_list *l, const char *key) |
| struct t_list_node * | list_node_at (const struct t_list *l, unsigned idx) |
| bool | list_move_node (struct t_list *l, unsigned from, unsigned to) |
| bool | list_push (struct t_list *l, const char *key, int64_t value_i, const char *value_p, void *user_data) |
| bool | list_push_len (struct t_list *l, const char *key, size_t key_len, int64_t value_i, const char *value_p, size_t value_len, void *user_data) |
| bool | list_insert (struct t_list *l, const char *key, int64_t value_i, const char *value_p, void *user_data) |
| bool | list_replace (struct t_list *l, unsigned idx, const char *key, int64_t value_i, const char *value_p, void *user_data) |
| bool | list_replace_len (struct t_list *l, unsigned idx, const char *key, size_t key_len, int64_t value_i, const char *value_p, size_t value_len, void *user_data) |
| bool | list_replace_user_data (struct t_list *l, unsigned idx, const char *key, int64_t value_i, const char *value_p, void *user_data, user_data_callback free_cb) |
| bool | list_replace_len_user_data (struct t_list *l, unsigned idx, const char *key, size_t key_len, int64_t value_i, const char *value_p, size_t value_len, void *user_data, user_data_callback free_cb) |
| void * | list_node_free (struct t_list_node *n) |
| void * | list_node_free_user_data (struct t_list_node *n, user_data_callback free_cb) |
| bool | list_remove_node (struct t_list *l, unsigned idx) |
| bool | list_remove_node_user_data (struct t_list *l, unsigned idx, user_data_callback free_cb) |
| bool | list_remove_node_by_key (struct t_list *l, const char *key) |
| bool | list_remove_node_by_key_user_data (struct t_list *l, const char *key, user_data_callback free_cb) |
| struct t_list_node * | list_shift_first (struct t_list *l) |
| struct t_list_node * | list_node_extract_at (struct t_list *l, unsigned idx) |
| struct t_list_node * | list_node_extract (struct t_list *l, struct t_list_node *node) |
| bool | list_write_to_disk (sds filepath, struct t_list *l, list_node_to_line_callback node_to_line_cb) |
| void | list_crop (struct t_list *l, unsigned length, user_data_callback free_cb) |
Linked list implementation.
Appends a list to another list Leaves user_data pointer in place.
| dst | list to that was append |
| src | list that was append |
| void list_clear | ( | struct t_list * | l | ) |
Clears the list and frees all nodes, ignores user_data
| l | pointer to list |
| void list_clear_user_data | ( | struct t_list * | l, |
| user_data_callback | free_cb ) |
Clears the list and frees all nodes and there values, calls a function to free user_data, set free_cb to NULL, to free a generic pointer.
| l | pointer to list |
| free_cb |
| void list_crop | ( | struct t_list * | l, |
| unsigned | length, | ||
| user_data_callback | free_cb ) |
Crops the list to the defined length
| l | pointer to list to crop |
| length | max length |
| free_cb | callback function to free user_data pointer |
Duplicates a list. Leaves user_data pointer in place.
| l | list to duplicate |
| void list_free | ( | struct t_list * | l | ) |
Clears the list, frees all nodes and the list itself, ignores user_data
| l | pointer to list |
| void list_free_cb_ignore_user_data | ( | struct t_list_node * | current | ) |
Callback function to not free user_data.
| current | list node |
| void list_free_cb_ptr_user_data | ( | struct t_list_node * | current | ) |
Callback function to free user_data of generic pointer.
| current | list node |
| void list_free_cb_sds_user_data | ( | struct t_list_node * | current | ) |
Callback function to free user_data of type sds.
| current | list node |
| void list_free_user_data | ( | struct t_list * | l, |
| user_data_callback | free_cb ) |
Clears the list and frees all nodes and there values, calls a function to free user_data, set free_cb to NULL, to free a generic pointer.
| l | pointer to list |
| free_cb | Callback to free the user data |
| void list_free_void | ( | void * | l | ) |
Clears the list, frees all nodes and the list itself, ignores user_data
| l | pointer to list |
| struct t_list_node * list_get_node | ( | const struct t_list * | l, |
| const char * | key ) |
Gets a list node by key.
| l | list |
| key | key to get |
| unsigned list_get_node_idx | ( | const struct t_list * | l, |
| const char * | key ) |
Gets a list node index by key.
| l | list |
| key | key to get |
| void list_init | ( | struct t_list * | l | ) |
Inits a already allocated list
| l | pointer to list |
| bool list_insert | ( | struct t_list * | l, |
| const char * | key, | ||
| int64_t | value_i, | ||
| const char * | value_p, | ||
| void * | user_data ) |
Creates and inserts a node at the beginning of the list.
| l | list |
| key | key value |
| value_i | int64_t value |
| value_p | sds value |
| user_data | pointer to user_data |
| bool list_move_node | ( | struct t_list * | l, |
| unsigned | from, | ||
| unsigned | to ) |
Moves a node in the list to another position.
| l | list |
| from | from pos |
| to | to pos |
| struct t_list * list_new | ( | void | ) |
Mallocs a new list and inits it.
| struct t_list_node * list_node_at | ( | const struct t_list * | l, |
| unsigned | idx ) |
Gets the list node at idx and its previous node.
| l | list |
| idx | node index to get |
| struct t_list_node * list_node_extract | ( | struct t_list * | l, |
| struct t_list_node * | node ) |
Removes a node directly from the list
| l | list |
| node | node to remove |
| struct t_list_node * list_node_extract_at | ( | struct t_list * | l, |
| unsigned | idx ) |
Removes the node at idx from the list and returns it.
| l | list |
| idx | node index to remove |
| void * list_node_free | ( | struct t_list_node * | n | ) |
Frees a list node, ignoring its user_data pointer.
| n | node to free |
| void * list_node_free_user_data | ( | struct t_list_node * | n, |
| user_data_callback | free_cb ) |
Frees a list node and its user_data pointer
| n | node to free |
| free_cb | callback function to free user_data pointer |
| bool list_push | ( | struct t_list * | l, |
| const char * | key, | ||
| int64_t | value_i, | ||
| const char * | value_p, | ||
| void * | user_data ) |
Creates and appends a node to the end of the list.
| l | list |
| key | key value |
| value_i | int64_t value |
| value_p | sds value |
| user_data | pointer to user_data |
| bool list_push_len | ( | struct t_list * | l, |
| const char * | key, | ||
| size_t | key_len, | ||
| int64_t | value_i, | ||
| const char * | value_p, | ||
| size_t | value_len, | ||
| void * | user_data ) |
Creates and appends a node to the end of the list. key and value_p len must be specified.
| l | list |
| key | key value |
| key_len | key length |
| value_i | int64_t value |
| value_p | sds value |
| value_len | value_p length |
| user_data | pointer to user_data |
| bool list_remove_node | ( | struct t_list * | l, |
| unsigned | idx ) |
Removes the node at idx from the list and frees it. Ignores the user_data pointer.
| l | list |
| idx | node index to free |
| bool list_remove_node_by_key | ( | struct t_list * | l, |
| const char * | key ) |
Removes the node with key Ignores user_data pointer
| l | list |
| key | key |
| bool list_remove_node_by_key_user_data | ( | struct t_list * | l, |
| const char * | key, | ||
| user_data_callback | free_cb ) |
Removes the node with key
| l | list |
| key | key |
| free_cb | Callback to free the user data |
| bool list_remove_node_user_data | ( | struct t_list * | l, |
| unsigned | idx, | ||
| user_data_callback | free_cb ) |
Removes the node at idx from the list and frees it and frees the user_data pointer
| l | list |
| idx | node index to free |
| free_cb | callback function to free user_data pointer |
| bool list_replace | ( | struct t_list * | l, |
| unsigned | idx, | ||
| const char * | key, | ||
| int64_t | value_i, | ||
| const char * | value_p, | ||
| void * | user_data ) |
Replaces a list nodes values at pos. Ignores the old user_data pointer.
| l | list |
| idx | index of node to change |
| key | new key value |
| value_i | new int64_t value |
| value_p | new sds value |
| user_data | new user_data pointer |
| bool list_replace_len | ( | struct t_list * | l, |
| unsigned | idx, | ||
| const char * | key, | ||
| size_t | key_len, | ||
| int64_t | value_i, | ||
| const char * | value_p, | ||
| size_t | value_len, | ||
| void * | user_data ) |
Replaces a list nodes values at pos. Ignores the old user_data pointer.
| l | list |
| idx | index of node to change |
| key | new key value |
| key_len | new key value length |
| value_i | new int64_t value |
| value_p | new sds value |
| value_len | new sds value len |
| user_data | new user_data pointer |
| bool list_replace_len_user_data | ( | struct t_list * | l, |
| unsigned | idx, | ||
| const char * | key, | ||
| size_t | key_len, | ||
| int64_t | value_i, | ||
| const char * | value_p, | ||
| size_t | value_len, | ||
| void * | user_data, | ||
| user_data_callback | free_cb ) |
Replaces a list nodes values at pos. Frees the old user_data pointer.
| l | list |
| idx | index of node to change |
| key | new key value |
| key_len | new key value length |
| value_i | new int64_t value |
| value_p | new sds value |
| value_len | new sds value len |
| user_data | new user_data pointer |
| free_cb | callback function to free old user_data pointer |
| bool list_replace_user_data | ( | struct t_list * | l, |
| unsigned | idx, | ||
| const char * | key, | ||
| int64_t | value_i, | ||
| const char * | value_p, | ||
| void * | user_data, | ||
| user_data_callback | free_cb ) |
Replaces a list nodes values at pos. Frees the old user_data pointer.
| l | list |
| idx | index of node to change |
| key | new key value |
| value_i | new int64_t value |
| value_p | new sds value |
| user_data | new user_data pointer |
| free_cb | callback function to free old user_data pointer |
| struct t_list_node * list_shift_first | ( | struct t_list * | l | ) |
Removes the first node from the list and returns it. This is only a shortcut for list_node_extract.
| l | list |
| bool list_write_to_disk | ( | sds | filepath, |
| struct t_list * | l, | ||
| list_node_to_line_callback | node_to_line_cb ) |
Saves the list to disk
| filepath | filepath to write the list |
| l | list to save |
| node_to_line_cb | callback function to write a list node |