4223
|
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 }
|