ucx/comparator.c

Wed, 27 Feb 2013 10:09:23 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 27 Feb 2013 10:09:23 +0100
changeset 89
47f7fdbddb62
child 91
91595a45fad6
permissions
-rw-r--r--

comparator module

89
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 #include "comparator.h"
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 int ucx_strcmp(void *s1, void *s2, void *data) {
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 return strcmp((char*)s1, (char*)s2);
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 }
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 int ucx_strncmp(void *s1, void *s2, void *n) {
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 return strncmp((char*)s1, (char*)s2, *((size_t*) n));
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 }
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 int ucx_intcmp(void *i1, void *i2, void *data) {
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 int a = *((int*) i1);
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 int b = *((int*) i2);
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 if (a == b) {
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 return 0;
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 } else {
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 return a < b ? -1 : 1;
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 }
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 }
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 int ucx_ptrcmp(void *ptr1, void *ptr2, void *data) {
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 if (ptr1 == ptr2) {
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 return 0;
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 } else {
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 return ptr1 < ptr2 ? -1 : 1;
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 }
47f7fdbddb62 comparator module
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 }

mercurial