summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraappleby@google.com <aappleby@google.com@77a7d1d3-4c08-bdc2-d393-d5859734b01a>2011-04-08 20:49:43 +0000
committeraappleby@google.com <aappleby@google.com@77a7d1d3-4c08-bdc2-d393-d5859734b01a>2011-04-08 20:49:43 +0000
commitcc592168c77f4f357d593456e7d094d786866f38 (patch)
tree2329a851a01a5c3096b4be0ffb83100028a34c43
parent7af0ee099b7f8d3a5b628791951ffb9680082583 (diff)
downloadsrc-cc592168c77f4f357d593456e7d094d786866f38.tar.gz
Build fixes for clang, etc
git-svn-id: http://smhasher.googlecode.com/svn/trunk@128 77a7d1d3-4c08-bdc2-d393-d5859734b01a
-rw-r--r--Bitvec.cpp4
-rw-r--r--Stats.h175
-rw-r--r--SuperFastHash.cpp13
-rw-r--r--Types.cpp4
-rw-r--r--Types.h60
-rw-r--r--sha1.cpp4
6 files changed, 136 insertions, 124 deletions
diff --git a/Bitvec.cpp b/Bitvec.cpp
index 2160060..16feaa7 100644
--- a/Bitvec.cpp
+++ b/Bitvec.cpp
@@ -104,7 +104,7 @@ uint32_t popcount ( uint32_t v )
{
v = v - ((v >> 1) & 0x55555555); // reuse input as temporary
v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp
- uint32_t c = ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
+ uint32_t c = ((v + ((v >> 4) & 0xF0F0F0F)) * 0x1010101) >> 24; // count
return c;
}
@@ -184,7 +184,7 @@ int countbits ( uint32_t v )
{
v = v - ((v >> 1) & 0x55555555); // reuse input as temporary
v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp
- int c = ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
+ int c = ((v + ((v >> 4) & 0xF0F0F0F)) * 0x1010101) >> 24; // count
return c;
}
diff --git a/Stats.h b/Stats.h
index 5106299..c80393e 100644
--- a/Stats.h
+++ b/Stats.h
@@ -100,6 +100,92 @@ int PrintCollisions ( hashfunc<hashtype> hash, std::vector<keytype> & keys )
}
//----------------------------------------------------------------------------
+// Measure the distribution "score" for each possible N-bit span up to 20 bits
+
+template< typename hashtype >
+double TestDistribution ( std::vector<hashtype> & hashes, bool drawDiagram )
+{
+ printf("Testing distribution - ");
+
+ if(drawDiagram) printf("\n");
+
+ const int hashbits = sizeof(hashtype) * 8;
+
+ int maxwidth = 20;
+
+ // We need at least 5 keys per bin to reliably test distribution biases
+ // down to 1%, so don't bother to test sparser distributions than that
+
+ while(double(hashes.size()) / double(1 << maxwidth) < 5.0)
+ {
+ maxwidth--;
+ }
+
+ std::vector<int> bins;
+ bins.resize(1 << maxwidth);
+
+ double worst = 0;
+ int worstStart = -1;
+ int worstWidth = -1;
+
+ for(int start = 0; start < hashbits; start++)
+ {
+ int width = maxwidth;
+ int bincount = (1 << width);
+
+ memset(&bins[0],0,sizeof(int)*bincount);
+
+ for(size_t j = 0; j < hashes.size(); j++)
+ {
+ hashtype & hash = hashes[j];
+
+ uint32_t index = window(&hash,sizeof(hash),start,width);
+
+ bins[index]++;
+ }
+
+ // Test the distribution, then fold the bins in half,
+ // repeat until we're down to 256 bins
+
+ if(drawDiagram) printf("[");
+
+ while(bincount >= 256)
+ {
+ double n = calcScore(&bins[0],bincount,(int)hashes.size());
+
+ if(drawDiagram) plot(n);
+
+ if(n > worst)
+ {
+ worst = n;
+ worstStart = start;
+ worstWidth = width;
+ }
+
+ width--;
+ bincount /= 2;
+
+ if(width < 8) break;
+
+ for(int i = 0; i < bincount; i++)
+ {
+ bins[i] += bins[i+bincount];
+ }
+ }
+
+ if(drawDiagram) printf("]\n");
+ }
+
+ double pct = worst * 100.0;
+
+ printf("Worst bias is the %3d-bit window at bit %3d - %5.3f%%",worstWidth,worstStart,pct);
+ if(pct >= 1.0) printf(" !!!!! ");
+ printf("\n");
+
+ return worst;
+}
+
+//----------------------------------------------------------------------------
template < typename hashtype >
bool TestHashList ( std::vector<hashtype> & hashes, std::vector<hashtype> & collisions, bool testDist, bool drawDiagram )
@@ -261,93 +347,6 @@ double TestDistributionBytepairs ( std::vector<hashtype> & hashes, bool drawDiag
return worst;
}
-
-//----------------------------------------------------------------------------
-// Measure the distribution "score" for each possible N-bit span up to 20 bits
-
-template< typename hashtype >
-double TestDistribution ( std::vector<hashtype> & hashes, bool drawDiagram )
-{
- printf("Testing distribution - ");
-
- if(drawDiagram) printf("\n");
-
- const int hashbits = sizeof(hashtype) * 8;
-
- int maxwidth = 20;
-
- // We need at least 5 keys per bin to reliably test distribution biases
- // down to 1%, so don't bother to test sparser distributions than that
-
- while(double(hashes.size()) / double(1 << maxwidth) < 5.0)
- {
- maxwidth--;
- }
-
- std::vector<int> bins;
- bins.resize(1 << maxwidth);
-
- double worst = 0;
- int worstStart = -1;
- int worstWidth = -1;
-
- for(int start = 0; start < hashbits; start++)
- {
- int width = maxwidth;
- int bincount = (1 << width);
-
- memset(&bins[0],0,sizeof(int)*bincount);
-
- for(size_t j = 0; j < hashes.size(); j++)
- {
- hashtype & hash = hashes[j];
-
- uint32_t index = window(&hash,sizeof(hash),start,width);
-
- bins[index]++;
- }
-
- // Test the distribution, then fold the bins in half,
- // repeat until we're down to 256 bins
-
- if(drawDiagram) printf("[");
-
- while(bincount >= 256)
- {
- double n = calcScore(&bins[0],bincount,(int)hashes.size());
-
- if(drawDiagram) plot(n);
-
- if(n > worst)
- {
- worst = n;
- worstStart = start;
- worstWidth = width;
- }
-
- width--;
- bincount /= 2;
-
- if(width < 8) break;
-
- for(int i = 0; i < bincount; i++)
- {
- bins[i] += bins[i+bincount];
- }
- }
-
- if(drawDiagram) printf("]\n");
- }
-
- double pct = worst * 100.0;
-
- printf("Worst bias is the %3d-bit window at bit %3d - %5.3f%%",worstWidth,worstStart,pct);
- if(pct >= 1.0) printf(" !!!!! ");
- printf("\n");
-
- return worst;
-}
-
//-----------------------------------------------------------------------------
// Simplified test - only check 64k distributions, and only on byte boundaries
@@ -376,7 +375,7 @@ void TestDistributionFast ( std::vector<hashtype> & hashes, double & dworst, dou
bins[index]++;
}
- double n = calcScore((int*)bins.begin(),(int)bins.size(),(int)hashes.size());
+ double n = calcScore(&bins.front(),(int)bins.size(),(int)hashes.size());
davg += n;
diff --git a/SuperFastHash.cpp b/SuperFastHash.cpp
index 8fd74cc..38d030d 100644
--- a/SuperFastHash.cpp
+++ b/SuperFastHash.cpp
@@ -7,6 +7,7 @@
http://www.azillionmonkeys.com/qed/hash.html */
+/*
#undef get16bits
#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
|| defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
@@ -17,8 +18,14 @@
#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
+(uint32_t)(((const uint8_t *)(d))[0]) )
#endif
+*/
-uint32_t SuperFastHash (const char * data, int len) {
+FORCE_INLINE uint16_t get16bits ( const void * p )
+{
+ return *(const uint16_t*)p;
+}
+
+uint32_t SuperFastHash (const signed char * data, int len) {
uint32_t hash = 0, tmp;
int rem;
@@ -65,5 +72,5 @@ int rem;
void SuperFastHash ( const void * key, int len, uint32_t /*seed*/, void * out )
{
- *(uint32_t*)out = SuperFastHash((const char*)key,len);
-} \ No newline at end of file
+ *(uint32_t*)out = SuperFastHash((const signed char*)key,len);
+}
diff --git a/Types.cpp b/Types.cpp
index 43544f2..46051a6 100644
--- a/Types.cpp
+++ b/Types.cpp
@@ -8,7 +8,9 @@ uint32_t MurmurOAAT ( const void * blob, int len, uint32_t seed );
//-----------------------------------------------------------------------------
+#if defined(_MSC_VER)
#pragma optimize( "", off )
+#endif
void blackhole ( uint32_t )
{
@@ -19,7 +21,9 @@ uint32_t whitehole ( void )
return 0;
}
+#if defined(_MSC_VER)
#pragma optimize( "", on )
+#endif
uint32_t g_verify = 1;
diff --git a/Types.h b/Types.h
index a100787..8814093 100644
--- a/Types.h
+++ b/Types.h
@@ -96,7 +96,11 @@ struct KeyCallback
{
}
- virtual void operator() ( const uint8_t * key, int len )
+ virtual ~KeyCallback()
+ {
+ }
+
+ virtual void operator() ( const void * key, int len )
{
m_count++;
}
@@ -115,14 +119,16 @@ struct HashCallback : public KeyCallback
{
typedef std::vector<hashtype> hashvec;
- HashCallback ( pfHash hash, hashvec & hashes ) : m_pfHash(hash), m_hashes(hashes)
+ HashCallback ( pfHash hash, hashvec & hashes ) : m_hashes(hashes), m_pfHash(hash)
{
m_hashes.clear();
}
- virtual void operator () ( const uint8_t * key, int len )
+ virtual void operator () ( const void * key, int len )
{
- m_hashes.resize(m_hashes.size() + 1);
+ size_t newsize = m_hashes.size() + 1;
+
+ m_hashes.resize(newsize);
m_pfHash(key,len,0,&m_hashes.back());
}
@@ -157,7 +163,7 @@ struct CollisionCallback : public KeyCallback
{
}
- virtual void operator () ( const uint8_t * key, int len )
+ virtual void operator () ( const void * key, int len )
{
hashtype h;
@@ -189,11 +195,15 @@ public:
Blob()
{
+ for(int i = 0; i < sizeof(bytes); i++)
+ {
+ bytes[i] = 0;
+ }
}
Blob ( int x )
{
- for(int i = 0; i < nbytes; i++)
+ for(int i = 0; i < sizeof(bytes); i++)
{
bytes[i] = 0;
}
@@ -203,7 +213,7 @@ public:
Blob ( const Blob & k )
{
- for(int i = 0; i < nbytes; i++)
+ for(int i = 0; i < sizeof(bytes); i++)
{
bytes[i] = k.bytes[i];
}
@@ -211,7 +221,7 @@ public:
Blob & operator = ( const Blob & k )
{
- for(int i = 0; i < nbytes; i++)
+ for(int i = 0; i < sizeof(bytes); i++)
{
bytes[i] = k.bytes[i];
}
@@ -229,14 +239,14 @@ public:
{
const uint8_t * k = (const uint8_t*)blob;
- len = len > nbytes ? nbytes : len;
+ len = len > sizeof(bytes) ? sizeof(bytes) : len;
for(int i = 0; i < len; i++)
{
bytes[i] = k[i];
}
- for(int i = len; i < nbytes; i++)
+ for(int i = len; i < sizeof(bytes); i++)
{
bytes[i] = 0;
}
@@ -257,7 +267,7 @@ public:
bool operator < ( const Blob & k ) const
{
- for(int i = 0; i < nbytes; i++)
+ for(int i = 0; i < sizeof(bytes); i++)
{
if(bytes[i] < k.bytes[i]) return true;
if(bytes[i] > k.bytes[i]) return false;
@@ -268,7 +278,7 @@ public:
bool operator == ( const Blob & k ) const
{
- for(int i = 0; i < nbytes; i++)
+ for(int i = 0; i < sizeof(bytes); i++)
{
if(bytes[i] != k.bytes[i]) return false;
}
@@ -288,7 +298,7 @@ public:
{
Blob t;
- for(int i = 0; i < nbytes; i++)
+ for(int i = 0; i < sizeof(bytes); i++)
{
t.bytes[i] = bytes[i] ^ k.bytes[i];
}
@@ -298,7 +308,7 @@ public:
Blob & operator ^= ( const Blob & k )
{
- for(int i = 0; i < nbytes; i++)
+ for(int i = 0; i < sizeof(bytes); i++)
{
bytes[i] ^= k.bytes[i];
}
@@ -313,7 +323,7 @@ public:
Blob & operator &= ( const Blob & k )
{
- for(int i = 0; i < nbytes; i++)
+ for(int i = 0; i < sizeof(bytes); i++)
{
bytes[i] &= k.bytes[i];
}
@@ -323,7 +333,7 @@ public:
{
Blob t = *this;
- lshift(&t.bytes[0],nbytes,c);
+ lshift(&t.bytes[0],sizeof(bytes),c);
return t;
}
@@ -332,40 +342,30 @@ public:
{
Blob t = *this;
- rshift(&t.bytes[0],nbytes,c);
+ rshift(&t.bytes[0],sizeof(bytes),c);
return t;
}
Blob & operator <<= ( int c )
{
- lshift(&bytes[0],nbytes,c);
+ lshift(&bytes[0],sizeof(bytes),c);
return *this;
}
Blob & operator >>= ( int c )
{
- rshift(&bytes[0],nbytes,c);
+ rshift(&bytes[0],sizeof(bytes),c);
return *this;
}
//----------
- enum
- {
- nbits = _bits,
- nbytes = (_bits+7)/8,
-
- align4 = (nbytes & 2) ? 0 : 1,
- align8 = (nbytes & 3) ? 0 : 1,
- align16 = (nbytes & 4) ? 0 : 1,
- };
-
private:
- uint8_t bytes[nbytes];
+ uint8_t bytes[(_bits+7)/8];
};
typedef Blob<128> uint128_t;
diff --git a/sha1.cpp b/sha1.cpp
index fceb463..9578438 100644
--- a/sha1.cpp
+++ b/sha1.cpp
@@ -82,9 +82,11 @@ A million repetitions of "a"
#include "sha1.h"
+#if defined(_MSC_VER)
#pragma warning(disable : 4267)
#pragma warning(disable : 4996)
#pragma warning(disable : 4100)
+#endif
void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]);
@@ -320,4 +322,4 @@ int main(int argc, char** argv)
fprintf(stdout, "ok\n");
return(0);
}
-#endif /* TEST */ \ No newline at end of file
+#endif /* TEST */