Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* magic numbers from http://www.isthe.com/chongo/tech/comp/fnv/ */
- static const size_t InitialFNV = 2166136261U;
- static const size_t FNVMultiple = 16777619;
- /* Fowler / Noll / Vo (FNV) Hash */
- size_t myhash(const string &s)
- {
- size_t hash = InitialFNV;
- for(size_t i = 0; i < s.length(); i++)
- {
- hash = hash ^ (s[i]); /* xor the low 8 bits */
- hash = hash * FNVMultiple; /* multiply by the magic number */
- }
- return hash;
- }
- unsigned int
- hash(
- const char* s,
- unsigned int seed = 0)
- {
- unsigned hash = seed;
- while (*s)
- {
- hash = hash * 101 + *s++;
- }
- return hash;
- }
- template <> struct myhash{};
- template <> struct myhash<string>
- {
- size_t operator()(string &to_hash) const
- {
- const char * in = to_hash.c_str();
- size_t out=0;
- while(NULL != *in)
- {
- out*= 53; //just a prime number
- out+= *in;
- ++in;
- }
- return out;
- }
- };
- hash_map<string, int, myhash<string> > my_hash_map;
Add Comment
Please, Sign In to add comment