Imported Upstream version 0.12.7
[bowtie.git] / str_util.h
1 #ifndef STR_UTIL_H_
2 #define STR_UTIL_H_
3
4 #include <string>
5
6 /**
7  * Given a string, return an int hash for it.
8  */
9 static inline int
10 hash_string(const std::string& s) {
11         int ret = 0;
12         int a = 63689;
13         int b = 378551;
14         for(size_t i = 0; i < s.length(); i++) {
15                 ret = (ret * a) + (int)s[i];
16                 if(a == 0) {
17                         a += b;
18                 } else {
19                         a *= b;
20                 }
21                 if(a == 0) {
22                         a += b;
23                 }
24         }
25         return ret;
26 }
27
28 #endif /* STR_UTIL_H_ */