58 lines
1.2 KiB
C
58 lines
1.2 KiB
C
#include "tlibc/collections/LList.h"
|
|
|
|
LLNode_* _LList_detatch(LList_* l, LLNode_* n){
|
|
if(n == l->first){
|
|
l->first = n->next;
|
|
}
|
|
else {
|
|
assert(n->prev != NULL);
|
|
n->prev->next = n->next;
|
|
}
|
|
|
|
if(n == l->last){
|
|
l->last = n->prev;
|
|
}
|
|
else {
|
|
assert(n->next != NULL);
|
|
n->next->prev = n->prev;
|
|
}
|
|
|
|
l->count--;
|
|
n->prev = NULL;
|
|
n->next = NULL;
|
|
return n;
|
|
}
|
|
|
|
void _LList_insertAfter(LList_* l, NULLABLE(LLNode_*) target, LLNode_* detatched)
|
|
{
|
|
if(target == NULL){
|
|
assert(l->first == NULL && l->last == NULL);
|
|
l->first = detatched;
|
|
l->last = detatched;
|
|
return;
|
|
}
|
|
|
|
detatched->prev = target;
|
|
detatched->next = target->next;
|
|
target->next = detatched;
|
|
if(detatched->next){
|
|
detatched->next->prev = detatched;
|
|
}
|
|
}
|
|
|
|
void _LList_insertBefore(LList_* l, NULLABLE(LLNode_*) target, LLNode_* detatched)
|
|
{
|
|
if(target == NULL){
|
|
assert(l->first == NULL && l->last == NULL);
|
|
l->first = detatched;
|
|
l->last = detatched;
|
|
return;
|
|
}
|
|
|
|
detatched->prev = target->prev;
|
|
detatched->next = target;
|
|
target->prev = detatched;
|
|
if(detatched->prev){
|
|
detatched->prev->next = detatched;
|
|
}
|
|
} |