summaryrefslogtreecommitdiff
path: root/Types.h
diff options
context:
space:
mode:
authortanjent@gmail.com <tanjent@gmail.com@77a7d1d3-4c08-bdc2-d393-d5859734b01a>2010-11-05 01:20:58 +0000
committertanjent@gmail.com <tanjent@gmail.com@77a7d1d3-4c08-bdc2-d393-d5859734b01a>2010-11-05 01:20:58 +0000
commitad4b363201477cb33966510b850c2193b1f825fe (patch)
tree9b4bdb1b5d9ed22197655b796a205f3c458ab4fc /Types.h
parent2e8984f1e39b91dae37a23aea35d30b78f46c096 (diff)
downloadsrc-ad4b363201477cb33966510b850c2193b1f825fe.tar.gz
MurmurHash3 is released to beta
(potentially some constant-tweaking yet to be done, but it is quite usable and all variants pass all tests) git-svn-id: http://smhasher.googlecode.com/svn/trunk@5 77a7d1d3-4c08-bdc2-d393-d5859734b01a
Diffstat (limited to 'Types.h')
-rw-r--r--Types.h238
1 files changed, 17 insertions, 221 deletions
diff --git a/Types.h b/Types.h
index 7dd7cda..d31a647 100644
--- a/Types.h
+++ b/Types.h
@@ -2,13 +2,20 @@
#include "pstdint.h"
#include "Bitvec.h"
-#include <vector>
-#include <assert.h>
+
+//-----------------------------------------------------------------------------
+// If the optimizer detects that a value in a speed test is constant or unused,
+// the optimizer may remove references to it or otherwise create code that
+// would not occur in a real-world application. To prevent the optimizer from
+// doing this we declare two trivial functions that either sink or source data,
+// and bar the compiler from optimizing them.
void blackhole ( uint32_t x );
uint32_t whitehole ( void );
-typedef void (*pfHash) ( const void * blob, int len, uint32_t seed, void * out );
+//-----------------------------------------------------------------------------
+
+typedef void (*pfHash) ( const void * blob, const int len, const uint32_t seed, void * out );
template < typename T >
void swap ( T & a, T & b )
@@ -29,7 +36,7 @@ public:
{
}
- inline void operator () ( const void * key, int len, uint32_t seed, uint32_t * out )
+ inline void operator () ( const void * key, const int len, const uint32_t seed, uint32_t * out )
{
m_hash(key,len,seed,out);
}
@@ -39,7 +46,7 @@ public:
return m_hash;
}
- inline T operator () ( const void * key, int len, uint32_t seed )
+ inline T operator () ( const void * key, const int len, const uint32_t seed )
{
T result;
@@ -48,43 +55,11 @@ public:
return result;
}
- /*
- T operator () ( T const & key )
- {
- T result;
-
- m_hash(&key,sizeof(T),0,&result);
-
- return result;
- }
- */
-
pfHash m_hash;
};
//-----------------------------------------------------------------------------
-template < class T >
-class mixfunc
-{
-public:
-
- typedef T (*pfMix) ( T key );
-
- mixfunc ( pfMix m ) : m_mix(m)
- {
- }
-
- T operator () ( T key )
- {
- return m_mix(key);
- }
-
- pfMix m_mix;
-};
-
-//-----------------------------------------------------------------------------
-
template < int _bits >
class Blob
{
@@ -220,7 +195,7 @@ public:
{
Blob t = *this;
- lshift(t.bytes,nbytes,c);
+ lshift(&t.bytes[0],nbytes,c);
return t;
}
@@ -229,21 +204,21 @@ public:
{
Blob t = *this;
- rshift(t.bytes,nbytes,c);
+ rshift(&t.bytes[0],nbytes,c);
return t;
}
Blob & operator <<= ( int c )
{
- lshift(bytes,nbytes,c);
+ lshift(&bytes[0],nbytes,c);
return *this;
}
Blob & operator >>= ( int c )
{
- rshift(bytes,nbytes,c);
+ rshift(&bytes[0],nbytes,c);
return *this;
}
@@ -265,185 +240,6 @@ private:
uint8_t bytes[nbytes];
};
-typedef Blob<128> u128;
-
-//-----------------------------------------------------------------------------
-
-class VBlob : public std::vector<uint8_t>
-{
-public:
-
- VBlob( int len ) : std::vector<uint8_t>(len,0)
- {
- }
-
- /*
- VBlob ( const VBlob & k )
- {
- for(size_t i = 0; i < size(); i++)
- {
- at(i) = k.at(i);
- }
- }
- */
-
- /*
- VBlob & operator = ( const VBlob & k )
- {
- for(size_t i = 0; i < size(); i++)
- {
- at(i) = k.at(i);
- }
-
- return *this;
- }
- */
-
- void set ( const void * VBlob, int len )
- {
- assert(size() == (size_t)len);
-
- const uint8_t * k = (const uint8_t*)VBlob;
-
- len = len > (int)size() ? (int)size() : len;
-
- for(int i = 0; i < len; i++)
- {
- at(i) = k[i];
- }
-
- for(size_t i = len; i < size(); i++)
- {
- at(i) = 0;
- }
- }
-
- //----------
- // boolean operations
-
- bool operator < ( const VBlob & k ) const
- {
- assert(size() == k.size());
-
- for(size_t i = 0; i < size(); i++)
- {
- if(at(i) < k.at(i)) return true;
- if(at(i) > k.at(i)) return false;
- }
-
- return false;
- }
-
- bool operator == ( const VBlob & k ) const
- {
- assert(size() == k.size());
-
- for(size_t i = 0; i < size(); i++)
- {
- if(at(i) != k.at(i)) return false;
- }
-
- return true;
- }
-
- bool operator != ( const VBlob & k ) const
- {
- assert(size() == k.size());
-
- return !(*this == k);
- }
-
- //----------
- // bitwise operations
-
- VBlob operator ^ ( const VBlob & k ) const
- {
- assert(size() == k.size());
-
- VBlob t((int)k.size());
-
- for(size_t i = 0; i < size(); i++)
- {
- t.at(i) = at(i) ^ k.at(i);
- }
-
- return t;
- }
-
- VBlob & operator ^= ( const VBlob & k )
- {
- assert(size() == k.size());
-
- for(size_t i = 0; i < size(); i++)
- {
- at(i) ^= k.at(i);
- }
-
- return *this;
- }
-
- VBlob & operator &= ( const VBlob & k )
- {
- assert(size() == k.size());
-
- for(size_t i = 0; i < size(); i++)
- {
- at(i) &= k.at(i);
- }
- }
-
- VBlob & operator <<= ( int c )
- {
- lshift(&at(0),(int)size(),c);
-
- return *this;
- }
-
- VBlob & operator >>= ( int c )
- {
- rshift(&at(0),(int)size(),c);
-
- return *this;
- }
-};
-
-//-----------------------------------------------------------------------------
-
-/*
-class Blobvec
-{
-public:
-
- Blobvec ( int stride, int size )
- {
- m_data = new uint8_t[stride*size];
- }
-
- ~Blobvec ( void )
- {
- delete [] m_data;
- }
-
- int size ( void ) const
- {
- return m_size;
- }
-
- const void * operator [] ( const int index ) const
- {
- return &m_data[index * m_stride];
- }
-
- void * operator [] ( const int index )
- {
- return &m_data[index * m_stride];
- }
-
- int m_stride;
- int m_size;
-
- uint8_t * m_data;
-};
-*/
+typedef Blob<128> uint128_t;
//-----------------------------------------------------------------------------