From cbd21e1da0d763225e7ea3594d4e6d8e96863790 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 30 May 2023 23:05:30 +0200 Subject: Added hash-based approach --- src/lib/list.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/lib/list.c (limited to 'src/lib/list.c') diff --git a/src/lib/list.c b/src/lib/list.c new file mode 100644 index 0000000..db7c5a6 --- /dev/null +++ b/src/lib/list.c @@ -0,0 +1,32 @@ +// Copyright (c) 2023, Marvin Borner +// SPDX-License-Identifier: MIT + +#include + +#include +#include + +static struct list *list_new(void) +{ + struct list *list = malloc(sizeof(*list)); + if (!list) + fatal("out of memory!\n"); + return list; +} + +struct list *list_add(struct list *list, void *data) +{ + struct list *new = list_new(); + new->data = data; + new->next = list; + return new; +} + +void list_free(struct list *list) +{ + while (list) { + struct list *next = list->next; + free(list); + list = next; + } +} -- cgit v1.2.3