ensure links only belong to 1 list
also some small documentation changes.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user