Wed, 27 Feb 2013 10:35:42 +0100
added memcmp to the comparator module
1 #include "comparator.h"
3 int ucx_strcmp(void *s1, void *s2, void *data) {
4 return strcmp((char*)s1, (char*)s2);
5 }
7 int ucx_strncmp(void *s1, void *s2, void *n) {
8 return strncmp((char*)s1, (char*)s2, *((size_t*) n));
9 }
11 int ucx_intcmp(void *i1, void *i2, void *data) {
12 int a = *((int*) i1);
13 int b = *((int*) i2);
14 if (a == b) {
15 return 0;
16 } else {
17 return a < b ? -1 : 1;
18 }
19 }
21 int ucx_ptrcmp(void *ptr1, void *ptr2, void *data) {
22 if (ptr1 == ptr2) {
23 return 0;
24 } else {
25 return ptr1 < ptr2 ? -1 : 1;
26 }
27 }
29 int ucx_memcmp(void *ptr1, void *ptr2, void *n) {
30 return memcmp(ptr1, ptr2, *((size_t*)n));
31 }