Permalink
Browse files

TS-2012L use string-based fnv hash in logstats

  • Loading branch information...
1 parent 9122cf0 commit 11cba2eb17f71d828aabee2c0ae88e875441352c @jpeach jpeach committed Jul 9, 2013
Showing with 22 additions and 22 deletions.
  1. +22 −22 proxy/logstats.cc
View
@@ -326,14 +326,30 @@ struct eqstr
}
};
+struct hash_fnv32 {
+ inline uint32_t operator()(const char* s) const
+ {
+ uint32_t hval = (uint32_t)0x811c9dc5; /* FNV1_32_INIT */
+
+ if (s) {
+ while (*s) {
+ hval ^= (uint32_t)*s++;
+ hval *= (uint32_t)0x01000193; /* FNV_32_PRIME */
+ }
+ }
+
+ return hval;
+ }
+};
+
typedef std::list<UrlStats> LruStack;
#if HAVE_CXX_11 && HAVE_UNORDERED_MAP && HAVE_UNORDERED_SET
#include <unordered_map>
#include <unordered_set>
-typedef std::unordered_map<const char *, OriginStats *, std::hash<const char *>, eqstr> OriginStorage;
-typedef std::unordered_set<const char *, std::hash<const char *>, eqstr> OriginSet;
-typedef std::unordered_map<const char *, LruStack::iterator, std::hash<const char *>, eqstr> LruHash;
+typedef std::unordered_map<const char *, OriginStats *, hash_fnv32, eqstr> OriginStorage;
+typedef std::unordered_set<const char *, hash_fnv32, eqstr> OriginSet;
+typedef std::unordered_map<const char *, LruStack::iterator, hash_fnv32, eqstr> LruHash;
// Resize a hash-based container.
template <class T, class N>
@@ -346,9 +362,9 @@ rehash(T& container, N size) {
#define _BACKWARD_BACKWARD_WARNING_H // needed for gcc 4.3
#include <ext/hash_map>
#include <ext/hash_set>
-typedef __gnu_cxx::hash_map<const char *, OriginStats *, __gnu_cxx::hash<const char *>, eqstr> OriginStorage;
-typedef __gnu_cxx::hash_set<const char *, __gnu_cxx::hash<const char *>, eqstr> OriginSet;
-typedef __gnu_cxx::hash_map<const char *, LruStack::iterator, __gnu_cxx::hash<const char *>, eqstr> LruHash;
+typedef __gnu_cxx::hash_map<const char *, OriginStats *, hash_fnv32, eqstr> OriginStorage;
+typedef __gnu_cxx::hash_set<const char *, hash_fnv32, eqstr> OriginSet;
+typedef __gnu_cxx::hash_map<const char *, LruStack::iterator, hash_fnv32, eqstr> LruHash;
// Resize a hash-based container.
template <class T, class N>
@@ -362,22 +378,6 @@ rehash(T& container, N size) {
#error no supported hash container
#endif
-struct hash_fnv32 {
- inline uint32_t operator()(const char* s) const
- {
- uint32_t hval = (uint32_t)0x811c9dc5; /* FNV1_32_INIT */
-
- if (s) {
- while (*s) {
- hval ^= (uint32_t)*s++;
- hval *= (uint32_t)0x01000193; /* FNV_32_PRIME */
- }
- }
-
- return hval;
- }
-};
-
// LRU class for the URL data
void update_elapsed(ElapsedStats &stat, const int elapsed, const StatsCounter &counter);

0 comments on commit 11cba2e

Please sign in to comment.