37 lines
754 B
C
37 lines
754 B
C
|
|
/* This software is licensed by the MIT License, see LICENSE file */
|
||
|
|
/* Copyright © 2022 Gregory Lirent */
|
||
|
|
|
||
|
|
#include "include.h"
|
||
|
|
|
||
|
|
int list_compare(const list_t* s0, const list_t* s1) {
|
||
|
|
lnode_t *c0, *c1;
|
||
|
|
int c;
|
||
|
|
|
||
|
|
if (s0 == s1) return 0;
|
||
|
|
|
||
|
|
c0 = s0->first;
|
||
|
|
c1 = s1->first;
|
||
|
|
|
||
|
|
for (;;) {
|
||
|
|
if (is_null(c0) || is_null(c1)) {
|
||
|
|
return (c0 == c1) ? 0 : (ssize_t)c0 - (ssize_t)c1;
|
||
|
|
}
|
||
|
|
|
||
|
|
c = lnode_compare(c0, c1);
|
||
|
|
|
||
|
|
if (c != 0) break;
|
||
|
|
|
||
|
|
c0 = c0->next;
|
||
|
|
c1 = c1->next;
|
||
|
|
}
|
||
|
|
|
||
|
|
for (;;) {
|
||
|
|
c0 = c0->next;
|
||
|
|
c1 = c1->next;
|
||
|
|
|
||
|
|
if (is_null(c0) || is_null(c1)) {
|
||
|
|
return (c0 == c1) ? 0 : (ssize_t)c0 - (ssize_t)c1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|