2022-06-04 21:59:01 +03:00
|
|
|
/* This software is licensed by the MIT License, see LICENSE file */
|
|
|
|
/* Copyright © 2022 Gregory Lirent */
|
|
|
|
|
|
|
|
#include "include.h"
|
|
|
|
|
|
|
|
/*#####################################################################################################################*/
|
|
|
|
|
|
|
|
void list_init(list_t* x) {
|
|
|
|
memset(x, 0, sizeof(*x));
|
|
|
|
}
|
|
|
|
|
|
|
|
void list_free(list_t* x) {
|
|
|
|
lnode_t* c;
|
|
|
|
lnode_t* next;
|
|
|
|
|
|
|
|
c = x->first;
|
|
|
|
|
|
|
|
while (!is_null(c)) {
|
|
|
|
next = c->next;
|
2022-06-05 18:35:58 +03:00
|
|
|
vnode_free(&c->node, c->type);
|
2022-06-04 21:59:01 +03:00
|
|
|
free(c);
|
|
|
|
c = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(x, 0, sizeof(*x));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*#####################################################################################################################*/
|
|
|
|
|
|
|
|
size_t list_size(const list_t* x) {
|
|
|
|
lnode_t* c;
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
c = x->first;
|
|
|
|
n = 0;
|
|
|
|
|
|
|
|
while (!is_null(c)) {
|
|
|
|
c = c->next;
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*#####################################################################################################################*/
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|