Compare commits

..

2 Commits

View File

@@ -184,18 +184,16 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_list_push(aksl_ListNode *list, aksl_List
FAIL_ZERO_RETURN(e, obj, AKERR_NULLPOINTER, "obj"); FAIL_ZERO_RETURN(e, obj, AKERR_NULLPOINTER, "obj");
aksl_ListNode *slow = list; aksl_ListNode *slow = list;
aksl_ListNode *fast = list; aksl_ListNode *fast = list;
aksl_ListNode *tail = list; while ( slow->next != NULL || fast->next != NULL ) {
do { if ( fast->next != NULL ) {
if ( fast != NULL && fast->next != NULL ) {
fast = fast->next->next; fast = fast->next->next;
} }
tail = slow;
slow = slow->next; slow = slow->next;
if ( fast != NULL && fast == slow) { if ( fast == slow ) {
FAIL(e, AKERR_CIRCULAR_REFERENCE, "%p", list); FAIL(e, AKERR_CIRCULAR_REFERENCE, "%p", list);
} }
} while ( slow != NULL || (fast != NULL && fast->next != NULL) ); }
tail->next = obj; slow->next = obj;
obj->next = NULL; obj->next = NULL;
obj->prev = slow; obj->prev = slow;
SUCCEED_RETURN(e); SUCCEED_RETURN(e);
@@ -205,12 +203,9 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_list_pop(aksl_ListNode *node)
{ {
PREPARE_ERROR(e); PREPARE_ERROR(e);
FAIL_ZERO_RETURN(e, node, AKERR_NULLPOINTER, "node"); FAIL_ZERO_RETURN(e, node, AKERR_NULLPOINTER, "node");
if ( node->prev != NULL ) { FAIL_ZERO_RETURN(e, node->prev, AKERR_NULLPOINTER, "node->prev");
node->prev->next = node->next; node->prev->next = node->next;
}
if ( node->next != NULL ) {
node->next->prev = node->prev; node->next->prev = node->prev;
}
node->next = NULL; node->next = NULL;
node->prev = NULL; node->prev = NULL;
SUCCEED_RETURN(e); SUCCEED_RETURN(e);
@@ -306,16 +301,15 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_list_iterate(aksl_ListNode *list, aksl_L
FAIL_ZERO_RETURN(e, iter, AKERR_NULLPOINTER, "iter"); FAIL_ZERO_RETURN(e, iter, AKERR_NULLPOINTER, "iter");
aksl_ListNode *slow = list; aksl_ListNode *slow = list;
aksl_ListNode *fast = list; aksl_ListNode *fast = list;
aksl_ListNode *tail = list; while ( slow->next != NULL || fast->next != NULL ) {
do { if ( fast->next != NULL ) {
if ( fast != NULL && fast->next != NULL ) {
fast = fast->next->next; fast = fast->next->next;
} }
PASS(e, iter(slow, data)); PASS(e, iter(slow, data));
slow = slow->next; slow = slow->next;
if ( fast != NULL && fast == slow) { if ( fast == slow && fast->next != NULL ) {
FAIL(e, AKERR_CIRCULAR_REFERENCE, "%p", list); FAIL(e, AKERR_CIRCULAR_REFERENCE, "%p", list);
} }
} while ( slow != NULL || (fast != NULL && fast->next != NULL) ); }
SUCCEED_RETURN(e); SUCCEED_RETURN(e);
} }