mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
list: added list_set()
This commit is contained in:
parent
f01b098e8d
commit
1e5c143ff9
2 changed files with 14 additions and 1 deletions
|
@ -97,4 +97,7 @@ int list_count(struct list *l, cmp_cb_t cmp, void *ctx);
|
|||
int list_contains(struct list *l, void *p);
|
||||
|
||||
/** Sort the list using the quicksort algorithm of libc */
|
||||
void list_sort(struct list *l, cmp_cb_t cmp);
|
||||
void list_sort(struct list *l, cmp_cb_t cmp);
|
||||
|
||||
/** Set single element in list */
|
||||
int list_set(struct list *l, int index, void *value);
|
10
lib/list.c
10
lib/list.c
|
@ -188,4 +188,14 @@ void list_sort(struct list *l, cmp_cb_t cmp)
|
|||
qsort_r(l->array, l->length, sizeof(void *), cmp_sort, (void *) cmp);
|
||||
|
||||
pthread_mutex_unlock(&l->lock);
|
||||
}
|
||||
|
||||
int list_set(struct list *l, int index, void *value)
|
||||
{
|
||||
if (index >= l->length)
|
||||
return -1;
|
||||
|
||||
l->array[index] = value;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue