Skip to content

Commit

Permalink
Explicitly make the hash type a 64bit integer
Browse files Browse the repository at this point in the history
  • Loading branch information
antialize committed May 30, 2012
1 parent ec3dbf5 commit f9a4951
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 3 additions & 4 deletions tpie/prime.cpp
Expand Up @@ -61,8 +61,8 @@ struct is_prime_t {
return true;
}

inline size_t prime_hash(const std::string & x) {
size_t r=42;
inline hash_type prime_hash(const std::string & x) {
hash_type r=42;
for(size_t i=0; i < x.size(); ++i)
r = r*m_pr[i % m_pr.size()] + x[i];
return r;
Expand All @@ -80,8 +80,7 @@ void finish_prime() {is_prime_ins.free();}

bool is_prime(size_type i) {return is_prime_ins(i);}

size_t prime_hash(const std::string & s) {return is_prime_ins.prime_hash(s);}

hash_type prime_hash(const std::string & s) {return is_prime_ins.prime_hash(s);}

size_t next_prime(size_t i) {
while(!is_prime(i)) ++i;
Expand Down
4 changes: 3 additions & 1 deletion tpie/prime.h
Expand Up @@ -47,13 +47,15 @@ void finish_prime();
///////////////////////////////////////////////////////////////////////////////
bool is_prime(size_type i);

typedef boost::uint64_t hash_type;

///////////////////////////////////////////////////////////////////////////////
/// \brief Calculate a fairly good string hash based on prime numbers.
///
/// \param s The string to hash.
/// \return The hash value.
///////////////////////////////////////////////////////////////////////////////
size_t prime_hash(const std::string & s);
hash_type prime_hash(const std::string & s);

///////////////////////////////////////////////////////////////////////////////
/// \brief Get next prime.
Expand Down

0 comments on commit f9a4951

Please sign in to comment.