File: str_util.h

package info (click to toggle)
bowtie 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 14,864 kB
  • ctags: 5,533
  • sloc: cpp: 32,737; perl: 2,084; ansic: 1,241; sh: 1,066; makefile: 344; python: 133
file content (28 lines) | stat: -rw-r--r-- 414 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef STR_UTIL_H_
#define STR_UTIL_H_

#include <string>

/**
 * Given a string, return an int hash for it.
 */
static inline int
hash_string(const std::string& s) {
	int ret = 0;
	int a = 63689;
	int b = 378551;
	for(size_t i = 0; i < s.length(); i++) {
		ret = (ret * a) + (int)s[i];
		if(a == 0) {
			a += b;
		} else {
			a *= b;
		}
		if(a == 0) {
			a += b;
		}
	}
	return ret;
}

#endif /* STR_UTIL_H_ */