texdepends/strhash.c

29 lines
404 B
C
Raw Normal View History

2017-10-25 18:35:04 +02:00
/*
* strhash.c
*
* Created on: 21.10.2017
* Author: julian
*/
#include "strhash.h"
// use rule:
// hash(i) = hash(i - 1) * 33 ^ str[i]
// see: http://www.cse.yorku.ca/~oz/hash.html
strhash_t hash_add(strhash_t hash, char c) {
return hash * 33 ^ c;
}
strhash_t hash_str(const char * str) {
strhash_t hash = 0;
while(*str) {
hash = hash_add(hash, *str);
str++;
}
return hash;
}