58 lines
1020 B
C
58 lines
1020 B
C
|
|
/* This software is licensed by the MIT License, see LICENSE file */
|
||
|
|
/* Copyright © 2022 Gregory Lirent */
|
||
|
|
|
||
|
|
#include "include.h"
|
||
|
|
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
hash_t list_hash(const list_t* s) {
|
||
|
|
|
||
|
|
hash_t hash = 0;
|
||
|
|
|
||
|
|
if (!is_null(s->first)) {
|
||
|
|
hash = vnode_hash(&s->first->node, s->first->type);
|
||
|
|
|
||
|
|
if (s->first != s->last) {
|
||
|
|
hash += vnode_hash(&s->first->node, s->first->type);
|
||
|
|
hash ^= list_size(s);
|
||
|
|
} else hash ^= 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
return hash + VTYPE_LIST;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
size_t libcdsb_list_count(const list_t* s, const void* v, vtype t) {
|
||
|
|
|
||
|
|
lnode_t* c;
|
||
|
|
size_t n;
|
||
|
|
int cmp;
|
||
|
|
|
||
|
|
c = s->first;
|
||
|
|
n = 0;
|
||
|
|
|
||
|
|
while (!is_null(c)) {
|
||
|
|
cmp = vtype_compare(vnode_peek(&c->node, c->type), c->type, v, t);
|
||
|
|
|
||
|
|
if (cmp == 0) ++n;
|
||
|
|
|
||
|
|
c = c->next;
|
||
|
|
}
|
||
|
|
|
||
|
|
return n;
|
||
|
|
}
|