Compare commits
1 Commits
55c3e451a6
...
trees
| Author | SHA1 | Date | |
|---|---|---|---|
|
21b2a3955d
|
26
src/stdlib.c
26
src/stdlib.c
@@ -184,16 +184,18 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_list_push(aksl_ListNode *list, aksl_List
|
||||
FAIL_ZERO_RETURN(e, obj, AKERR_NULLPOINTER, "obj");
|
||||
aksl_ListNode *slow = list;
|
||||
aksl_ListNode *fast = list;
|
||||
while ( slow->next != NULL || fast->next != NULL ) {
|
||||
if ( fast->next != NULL ) {
|
||||
aksl_ListNode *tail = list;
|
||||
do {
|
||||
if ( fast != NULL && fast->next != NULL ) {
|
||||
fast = fast->next->next;
|
||||
}
|
||||
tail = slow;
|
||||
slow = slow->next;
|
||||
if ( fast == slow ) {
|
||||
if ( fast != NULL && fast == slow) {
|
||||
FAIL(e, AKERR_CIRCULAR_REFERENCE, "%p", list);
|
||||
}
|
||||
}
|
||||
slow->next = obj;
|
||||
} while ( slow != NULL || (fast != NULL && fast->next != NULL) );
|
||||
tail->next = obj;
|
||||
obj->next = NULL;
|
||||
obj->prev = slow;
|
||||
SUCCEED_RETURN(e);
|
||||
@@ -203,9 +205,12 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_list_pop(aksl_ListNode *node)
|
||||
{
|
||||
PREPARE_ERROR(e);
|
||||
FAIL_ZERO_RETURN(e, node, AKERR_NULLPOINTER, "node");
|
||||
FAIL_ZERO_RETURN(e, node->prev, AKERR_NULLPOINTER, "node->prev");
|
||||
if ( node->prev != NULL ) {
|
||||
node->prev->next = node->next;
|
||||
}
|
||||
if ( node->next != NULL ) {
|
||||
node->next->prev = node->prev;
|
||||
}
|
||||
node->next = NULL;
|
||||
node->prev = NULL;
|
||||
SUCCEED_RETURN(e);
|
||||
@@ -301,15 +306,16 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_list_iterate(aksl_ListNode *list, aksl_L
|
||||
FAIL_ZERO_RETURN(e, iter, AKERR_NULLPOINTER, "iter");
|
||||
aksl_ListNode *slow = list;
|
||||
aksl_ListNode *fast = list;
|
||||
while ( slow->next != NULL || fast->next != NULL ) {
|
||||
if ( fast->next != NULL ) {
|
||||
aksl_ListNode *tail = list;
|
||||
do {
|
||||
if ( fast != NULL && fast->next != NULL ) {
|
||||
fast = fast->next->next;
|
||||
}
|
||||
PASS(e, iter(slow, data));
|
||||
slow = slow->next;
|
||||
if ( fast == slow && fast->next != NULL ) {
|
||||
if ( fast != NULL && fast == slow) {
|
||||
FAIL(e, AKERR_CIRCULAR_REFERENCE, "%p", list);
|
||||
}
|
||||
}
|
||||
} while ( slow != NULL || (fast != NULL && fast->next != NULL) );
|
||||
SUCCEED_RETURN(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user