You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2013/03/08 23:12:36 UTC
git commit: TS-1743 Implement our own hash mechanism for
traffic_logstats,
since C++11 does not provide a sensical hash. Thanks amc and
PSUdaemon for saving the day.
Updated Branches:
refs/heads/master 2fe05e2e0 -> dc3f8ffaa
TS-1743 Implement our own hash mechanism for traffic_logstats, since
C++11 does not provide a sensical hash<const char*>. Thanks amc
and PSUdaemon for saving the day.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/dc3f8ffa
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/dc3f8ffa
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/dc3f8ffa
Branch: refs/heads/master
Commit: dc3f8ffaa9e44c1ad319f6560f4777276c8d6f0f
Parents: 2fe05e2
Author: Leif Hedstrom <zw...@apache.org>
Authored: Fri Mar 8 15:11:36 2013 -0700
Committer: Leif Hedstrom <zw...@apache.org>
Committed: Fri Mar 8 15:11:36 2013 -0700
----------------------------------------------------------------------
CHANGES | 3 +++
proxy/logstats.cc | 37 ++++++++++++++++++-------------------
2 files changed, 21 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/dc3f8ffa/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 93c6a4d..cb926b5 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,9 @@
Changes with Apache Traffic Server 3.3.1
+ *) [TS-1743] Implement our own hash mechanism for traffic_logstats, since
+ C++11 does not provide a sensical hash<const char*>.
+
*) [TS-1628] In validate_unmapped_url(), pristine_url can be invalid().
*) [TS-1714] Fix some build problems for gcc v4.8.
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/dc3f8ffa/proxy/logstats.cc
----------------------------------------------------------------------
diff --git a/proxy/logstats.cc b/proxy/logstats.cc
index 48707e5..7998949 100644
--- a/proxy/logstats.cc
+++ b/proxy/logstats.cc
@@ -71,16 +71,6 @@
#if defined(__GNUC__)
using __gnu_cxx::hash_map;
using __gnu_cxx::hash_set;
-
-// GCC 4.7 appears to want the std::hash implementation from <functional>, whereas previous gcc versions
-// use the __gnu_cxx::hash GNU extension. Clang (at least on OS X) is happy with the GNU extension as long
-// as it is using the GNU libstdc++.
-#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 7)
-using std::hash;
-#else
-using __gnu_cxx::hash;
-#endif
-
#endif
using namespace std;
@@ -120,13 +110,6 @@ const int PLAI_AS_INT = 1767992432; // For "plain"
const int IMAG_AS_INT = 1734438249; // For "image"
const int HTTP_AS_INT = 1886680168; // For "http" followed by "s://" or "://"
-/*
-#include <stdio.h>
-int main(int argc, char** argv) {
- printf("%s is %d\n", argv[1], *((int*)argv[1]));
-}
-*/
-
// Store our "state" (position in log file etc.)
struct LastState
{
@@ -361,8 +344,24 @@ struct eqstr
}
};
-typedef hash_map <const char *, OriginStats *, hash <const char *>, eqstr> OriginStorage;
-typedef hash_set <const char *, hash <const char *>, eqstr> OriginSet;
+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 hash_map <const char *, OriginStats *, hash_fnv32, eqstr> OriginStorage;
+typedef hash_set <const char *, hash_fnv32, eqstr> OriginSet;
// LRU class for the URL data