comparison src/ploki/strutil.c @ 4223:ac0403686959

<oerjan> rm -rf src/ploki; mv ploki src
author HackBot
date Fri, 20 Dec 2013 22:18:50 +0000
parents
children
comparison
equal deleted inserted replaced
4222:b0f3e267bb1e 4223:ac0403686959
1 #include "strutil.h"
2
3 #include <string.h>
4
5 /* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins
6 * from requirements by Colin Plumb.
7 * (http://burtleburtle.net/bob/hash/doobs.html) */
8 size_t u_hash(const char *s, size_t l, size_t h) {
9 size_t i;
10
11 for (i = 0; i < l; ++i) {
12 h += (unsigned char)s[i];
13 h += h << 10;
14 h ^= h >> 6;
15 }
16 h += h << 3;
17 h ^= h >> 11;
18 h += h << 15;
19
20 return h;
21 }
22
23 int u_cmp(const char *as, size_t al, const char *bs, size_t bl) {
24 int tmp;
25 if (as == bs && al == bl)
26 return 0;
27 if ((tmp = memcmp(as, bs, al < bl ? al : bl)))
28 return tmp;
29 if (al < bl)
30 return -1;
31 if (al > bl)
32 return 1;
33 return 0;
34 }