|
myMPD
Internal API documentation
|
Linked list implementation. More...
#include "dist/sds/sds.h"#include <stdbool.h>

Go to the source code of this file.
Data Structures | |
| struct | t_list_node |
| struct | t_list |
Typedefs | |
| typedef void(* | user_data_callback) (struct t_list_node *current) |
| typedef sds(* | list_node_to_line_callback) (sds buffer, struct t_list_node *current, bool newline) |
| typedef bool(* | list_sort_callback) (struct t_list_node *current, struct t_list_node *next, enum list_sort_direction direction) |
Enumerations | |
| enum | list_sort_direction { LIST_SORT_ASC = 0 , LIST_SORT_DESC = 1 } |
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) |
| void * | list_node_free_user_data (struct t_list_node *n, user_data_callback free_cb) |
| void * | list_node_free (struct t_list_node *n) |
| 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_crop (struct t_list *l, unsigned length, user_data_callback free_cb) |
| bool | list_shuffle (struct t_list *l) |
| bool | list_swap_item (struct t_list_node *n1, struct t_list_node *n2) |
| bool | list_move_item_pos (struct t_list *l, unsigned from, unsigned to) |
| 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) |
| struct t_list_node * | list_node_prev_at (const struct t_list *l, unsigned idx, struct t_list_node **previous) |
| struct t_list_node * | list_shift_first (struct t_list *l) |
| struct t_list_node * | list_node_extract (struct t_list *l, unsigned idx) |
| 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) |
| bool | list_write_to_disk (sds filepath, struct t_list *l, list_node_to_line_callback node_to_line_cb) |
| bool | list_sort_by_callback (struct t_list *l, enum list_sort_direction direction, list_sort_callback sort_cb) |
| bool | list_sort_by_value_i (struct t_list *l, enum list_sort_direction direction) |
| bool | list_sort_by_value_p (struct t_list *l, enum list_sort_direction direction) |
| bool | list_sort_by_key (struct t_list *l, enum list_sort_direction direction) |
Linked list implementation.
| typedef sds(* list_node_to_line_callback) (sds buffer, struct t_list_node *current, bool newline) |
Definition of list to line callback
| typedef bool(* list_sort_callback) (struct t_list_node *current, struct t_list_node *next, enum list_sort_direction direction) |
Definition of sort callback
| typedef void(* user_data_callback) (struct t_list_node *current) |
Definition of user data callback
| enum list_sort_direction |
Sort direction
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_item_pos | ( | 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
| l | list |
| idx | node index to get |
| struct t_list_node * list_node_extract | ( | 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 |
| struct t_list_node * list_node_prev_at | ( | const struct t_list * | l, |
| unsigned | idx, | ||
| struct t_list_node ** | previous | ||
| ) |
Gets the list node at idx and its previous node.
| l | list |
| idx | node index to get |
| previous | pointer to previous node |
| 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_shuffle | ( | struct t_list * | l | ) |
Shuffles the list.
| l | list |
| bool list_sort_by_callback | ( | struct t_list * | l, |
| enum list_sort_direction | direction, | ||
| list_sort_callback | sort_cb | ||
| ) |
The list sorting function. Note that the sort is not very efficient, use it only for short lists.
| l | pointer to list to sort |
| direction | sort direction |
| sort_cb | compare function |
| bool list_sort_by_key | ( | struct t_list * | l, |
| enum list_sort_direction | direction | ||
| ) |
Sorts the list by key
| l | pointer to list to sort |
| direction | sort direction |
| bool list_sort_by_value_i | ( | struct t_list * | l, |
| enum list_sort_direction | direction | ||
| ) |
Sorts the list by value_i
| l | pointer to list to sort |
| direction | sort direction |
| bool list_sort_by_value_p | ( | struct t_list * | l, |
| enum list_sort_direction | direction | ||
| ) |
Sorts the list by value_p
| l | pointer to list to sort |
| direction | sort direction |
| bool list_swap_item | ( | struct t_list_node * | n1, |
| struct t_list_node * | n2 | ||
| ) |
Swaps two list nodes values.
| n1 | first node |
| n2 | second node |
| 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 |