Add cfulist_delete_data
It is important to let the programmer remove a node from the linked list, as it is a very common operation.
This commit is contained in:
parent
1294791f0c
commit
b4faaca915
@ -509,6 +509,11 @@ cfulist_map(). The return value is used to build a new list.
|
|||||||
Pop a value from the end of the list (removing it from the list).
|
Pop a value from the end of the list (removing it from the list).
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
@deftypefun void cfulist_delete_data (cfulist_t * @var{list}, void * @var{data})
|
||||||
|
|
||||||
|
Deletes the entry in the list associated with value.
|
||||||
|
@end deftypefun
|
||||||
|
|
||||||
@deftypefun {int} cfulist_unshift_data (cfulist_t * @var{list}, void * @var{data}, size_t @var{data_size})
|
@deftypefun {int} cfulist_unshift_data (cfulist_t * @var{list}, void * @var{data}, size_t @var{data_size})
|
||||||
|
|
||||||
Add a value at the beginning of the list.
|
Add a value at the beginning of the list.
|
||||||
|
@ -412,6 +412,28 @@ cfulist_pop(cfulist_t *list) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cfulist_delete_data(cfulist_t *list, void *data) {
|
||||||
|
cfulist_entry *ptr = NULL;
|
||||||
|
|
||||||
|
if (!list) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lock_list(list);
|
||||||
|
|
||||||
|
if (list->entries) {
|
||||||
|
for (ptr = list->entries; ptr && ptr->data != data; ptr = ptr->next)
|
||||||
|
;
|
||||||
|
if (ptr && ptr->data == data) {
|
||||||
|
(ptr->prev)->next = ptr->next;
|
||||||
|
free (ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unlock_list(list);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
cfulist_unshift(cfulist_t *list, void *data) {
|
cfulist_unshift(cfulist_t *list, void *data) {
|
||||||
return cfulist_unshift_data(list, data, 0);
|
return cfulist_unshift_data(list, data, 0);
|
||||||
|
@ -81,6 +81,9 @@ int cfulist_push_data(cfulist_t *list, void *data, size_t data_size);
|
|||||||
/* Pop a value from the end of the list. */
|
/* Pop a value from the end of the list. */
|
||||||
int cfulist_pop_data(cfulist_t *list, void **data, size_t *data_size);
|
int cfulist_pop_data(cfulist_t *list, void **data, size_t *data_size);
|
||||||
|
|
||||||
|
/* Deletes the entry in the list associated with value. */
|
||||||
|
void cfulist_delete_data(cfulist_t *list, void *data);
|
||||||
|
|
||||||
/* Add a value at the beginning of the list. */
|
/* Add a value at the beginning of the list. */
|
||||||
int cfulist_unshift_data(cfulist_t *list, void *data, size_t data_size);
|
int cfulist_unshift_data(cfulist_t *list, void *data, size_t data_size);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user