texdepends/strhash.c

29 lines
413 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 strhash_add(strhash_t hash, char c) {
2017-10-25 18:35:04 +02:00
return hash * 33 ^ c;
}
strhash_t strhash_str(const char * str) {
2017-10-25 18:35:04 +02:00
strhash_t hash = 0;
while(*str) {
hash = strhash_add(hash, *str);
2017-10-25 18:35:04 +02:00
str++;
}
return hash;
}