Mercurial > repo
view src/ploki/strutil.c @ 5983:e9e46956a506
<oerjan> mk wisdom/welcome.sv//Hej och v\xc3\xa4lkommen till den internationella knutpunkten f\xc3\xb6r esoterisk programmeringsspr\xc3\xa5ksdesign och -drifts\xc3\xa4ttning! F\xc3\xb6r mer information, se v\xc3\xa5r wiki: <http://esolangs.org/>. (F\xc3\xb6r den andra sortens esoterism, pr\xc3\xb6va #esoteric p\xc3\xa5 EFnet eller DALnet.)
author | HackBot |
---|---|
date | Mon, 14 Sep 2015 17:49:06 +0000 |
parents | ac0403686959 |
children |
line wrap: on
line source
#include "strutil.h" #include <string.h> /* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins * from requirements by Colin Plumb. * (http://burtleburtle.net/bob/hash/doobs.html) */ size_t u_hash(const char *s, size_t l, size_t h) { size_t i; for (i = 0; i < l; ++i) { h += (unsigned char)s[i]; h += h << 10; h ^= h >> 6; } h += h << 3; h ^= h >> 11; h += h << 15; return h; } int u_cmp(const char *as, size_t al, const char *bs, size_t bl) { int tmp; if (as == bs && al == bl) return 0; if ((tmp = memcmp(as, bs, al < bl ? al : bl))) return tmp; if (al < bl) return -1; if (al > bl) return 1; return 0; }