File: str_util.h

package info (click to toggle)
bowtie 1.3.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 15,792 kB
  • sloc: cpp: 37,066; perl: 5,806; ansic: 1,465; sh: 1,194; python: 463; makefile: 430
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_ */