Files
libcdsb/src/array/compute.c
T
2022-08-19 20:00:10 +03:00

47 lines
889 B
C

/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "include.h"
#include "../__internal/assert.h"
size_t array_nmemb(const arr_t* x) {
return x->size*vtype_size(x->type);
}
hash_t array_hash(const arr_t* s) {
hash_t hash = 0;
if (s->size > 0)
hash = vtype_hash(s->mem, s->type);
if (s->size > 1)
hash += vtype_hash(array_internal_at(s, s->size - 1), s->type);
hash ^= s->size;
return hash + VTYPE_ARRAY;
}
size_t libcdsb_array_count(const arr_t* s, const void* v, vtype t) {
void *p;
void *e;
int cmp;
size_t n;
p = s->mem;
e = array_end(s);
n = 0;
do {
cmp = vtype_compare(p, s->type, v, t);
if (cmp == 0) ++n;
p += vtype_size(s->type);
} while (p < e);
return n;
}