ensure links only belong to 1 list

also some small documentation changes.
This commit is contained in:
2026-01-14 10:41:54 -05:00
parent e498c821bf
commit 4db7dfeb5d
3 changed files with 18 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <assert.h>
#include "nickel/linkedlist.h"
@@ -19,6 +20,10 @@ bool ni_list__is_empty(ni_list* l) {
}
void ni_list__insert_after(ni_list* l, ni_list_node* entry, ni_list_node* n) {
// n must not be in a list already,
// if you need an object in multiple lists, use multiple links.
assert(n->next == NULL && n->prev == NULL);
// setup our incomming node as the next node after the insert point
n->next = entry->next;
n->prev = entry;
@@ -32,6 +37,10 @@ void ni_list__insert_after(ni_list* l, ni_list_node* entry, ni_list_node* n) {
}
void ni_list__insert_before(ni_list* l, ni_list_node* entry, ni_list_node* n) {
// n must not be in a list already,
// if you need an object in multiple lists, use multiple links.
assert(n->next == NULL && n->prev == NULL);
// setup our incomming node as the next node before the insert point
n->prev = entry->prev;
n->next = entry;