Compare commits
2 Commits
trees
...
55c3e451a6
| Author | SHA1 | Date | |
|---|---|---|---|
|
55c3e451a6
|
|||
|
22414addd3
|
30
src/stdlib.c
30
src/stdlib.c
@@ -184,18 +184,16 @@ 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;
|
||||
aksl_ListNode *tail = list;
|
||||
do {
|
||||
if ( fast != NULL && fast->next != NULL ) {
|
||||
while ( slow->next != NULL || fast->next != NULL ) {
|
||||
if ( fast->next != NULL ) {
|
||||
fast = fast->next->next;
|
||||
}
|
||||
tail = slow;
|
||||
slow = slow->next;
|
||||
if ( fast != NULL && fast == slow) {
|
||||
if ( fast == slow ) {
|
||||
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->prev = slow;
|
||||
SUCCEED_RETURN(e);
|
||||
@@ -205,12 +203,9 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_list_pop(aksl_ListNode *node)
|
||||
{
|
||||
PREPARE_ERROR(e);
|
||||
FAIL_ZERO_RETURN(e, node, AKERR_NULLPOINTER, "node");
|
||||
if ( node->prev != NULL ) {
|
||||
node->prev->next = node->next;
|
||||
}
|
||||
if ( node->next != NULL ) {
|
||||
node->next->prev = node->prev;
|
||||
}
|
||||
FAIL_ZERO_RETURN(e, node->prev, AKERR_NULLPOINTER, "node->prev");
|
||||
node->prev->next = node->next;
|
||||
node->next->prev = node->prev;
|
||||
node->next = NULL;
|
||||
node->prev = NULL;
|
||||
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");
|
||||
aksl_ListNode *slow = list;
|
||||
aksl_ListNode *fast = list;
|
||||
aksl_ListNode *tail = list;
|
||||
do {
|
||||
if ( fast != NULL && fast->next != NULL ) {
|
||||
while ( slow->next != NULL || fast->next != NULL ) {
|
||||
if ( fast->next != NULL ) {
|
||||
fast = fast->next->next;
|
||||
}
|
||||
PASS(e, iter(slow, data));
|
||||
slow = slow->next;
|
||||
if ( fast != NULL && fast == slow) {
|
||||
if ( fast == slow && fast->next != NULL ) {
|
||||
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