Files
libcdsb/src/array/comparison.c
T

36 lines
767 B
C
Raw Normal View History

2022-08-19 13:41:19 +03:00
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "include.h"
int array_compare(const arr_t* s0, const arr_t* s1) {
void *e, *p0, *p1;
int cmp;
if (s0 == s1 || (!s0->size && !s0->size))
return 0;
if (s0->type != s1->type)
return (s0->type < s1->type) ? -1 : 1;
if (s0->size != s1->size)
return (s0->size < s1->size) ? -1 : 1;
p0 = s0->mem;
p1 = s1->mem;
e = array_end(s0);
do {
cmp = vtype_compare_eq(p0, p1, s0->type);
if (cmp == 0) {
p0 += vtype_size(s0->type);
p1 += vtype_size(s0->type);
} else return cmp;
} while (p0 < e);
return 0;
}