mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-07 09:22:03 +00:00
lib: add listnode_add_head()
Provide a new convenience function that adds an element to the beginning of a list. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
27982ebc9d
commit
9ea82f28d4
@ -70,6 +70,26 @@ void listnode_add(struct list *list, void *val)
|
|||||||
list->count++;
|
list->count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void listnode_add_head(struct list *list, void *val)
|
||||||
|
{
|
||||||
|
struct listnode *node;
|
||||||
|
|
||||||
|
assert(val != NULL);
|
||||||
|
|
||||||
|
node = listnode_new();
|
||||||
|
|
||||||
|
node->next = list->head;
|
||||||
|
node->data = val;
|
||||||
|
|
||||||
|
if (list->head == NULL)
|
||||||
|
list->head = node;
|
||||||
|
else
|
||||||
|
list->head->prev = node;
|
||||||
|
list->head = node;
|
||||||
|
|
||||||
|
list->count++;
|
||||||
|
}
|
||||||
|
|
||||||
void listnode_add_sort(struct list *list, void *val)
|
void listnode_add_sort(struct list *list, void *val)
|
||||||
{
|
{
|
||||||
struct listnode *n;
|
struct listnode *n;
|
||||||
|
@ -82,6 +82,19 @@ extern struct list *list_new(void);
|
|||||||
*/
|
*/
|
||||||
extern void listnode_add(struct list *list, void *data);
|
extern void listnode_add(struct list *list, void *data);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add a new element to the beginning of a list.
|
||||||
|
*
|
||||||
|
* Runtime is O(1).
|
||||||
|
*
|
||||||
|
* list
|
||||||
|
* list to operate on
|
||||||
|
*
|
||||||
|
* data
|
||||||
|
* element to add
|
||||||
|
*/
|
||||||
|
extern void listnode_add_head(struct list *list, void *data);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Insert a new element into a list with insertion sort.
|
* Insert a new element into a list with insertion sort.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user