hash::MurmurHash3 Class Reference

#include <MurmurHash3.h>

List of all members.

Public Types

enum  { kDefaultSeed = 0xe086c5ff }
typedef UInt_t Hash_t
typedef Int_t Length_t
typedef Byte_t Rot_t

Public Member Functions

 MurmurHash3 (unsigned int seed=kDefaultSeed)
void Reset (UInt_t seed=kDefaultSeed)
void Add (MsgPtr_t msg_ptr, Length_t len)
template<typename T >
MurmurHash3Add (T *ptr, Length_t len)
template<typename T >
MurmurHash3Add (const T &thing, Length_t len)
Hash_t Value () const
Hash_t End (UInt_t seed=kDefaultSeed)

Private Member Functions

Hash_tEndImp (Hash_t &hash, UInt_t &tail) const
 Takes parameters by reference and will mush them.
void MixTail (MsgPtr_t &data, Length_t &len)
UInt_t rot32 (UInt_t bits, Rot_t r) const
void mmix (Hash_t &h, UInt_t &bits) const
void final_mix (Hash_t &h) const

Private Attributes

Hash_t fHash
UInt_t fTail
UInt_t fCount
UInt_t fSize

Static Private Attributes

static const UInt_t kMply1 = 0xcc9e2d51
static const UInt_t kMply2 = 0x1b873593

Detailed Description

Definition at line 25 of file MurmurHash3.h.


Member Typedef Documentation

typedef UInt_t hash::MurmurHash3::Hash_t

Definition at line 29 of file MurmurHash3.h.

Definition at line 30 of file MurmurHash3.h.

typedef Byte_t hash::MurmurHash3::Rot_t

Definition at line 31 of file MurmurHash3.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
kDefaultSeed 

Definition at line 27 of file MurmurHash3.h.

00027 {kDefaultSeed = 0xe086c5ff};


Constructor & Destructor Documentation

hash::MurmurHash3::MurmurHash3 ( unsigned int  seed = kDefaultSeed  )  [inline]

Definition at line 33 of file MurmurHash3.h.

00034     : fHash(seed), fTail(0), fCount(0), fSize(0)
00035   {}


Member Function Documentation

template<typename T >
MurmurHash3& hash::MurmurHash3::Add ( const T &  thing,
Length_t  len 
) [inline]

Definition at line 54 of file MurmurHash3.h.

References Add().

00055   {
00056     Add(reinterpret_cast<MsgPtr_t>(&thing), len);
00057     return *this;
00058   }

template<typename T >
MurmurHash3& hash::MurmurHash3::Add ( T *  ptr,
Length_t  len 
) [inline]

Definition at line 47 of file MurmurHash3.h.

References Add().

00048   {
00049     Add(reinterpret_cast<MsgPtr_t>(ptr), len);
00050     return *this;
00051   }

void MurmurHash3::Add ( MsgPtr_t  msg_ptr,
Length_t  len 
)

Definition at line 7 of file MurmurHash3.cpp.

References fHash, fSize, MixTail(), and mmix().

Referenced by Add().

00008 {
00009   fSize += len;
00010   MixTail(msg_ptr,len);
00011   
00012   while(len >= 4) {
00013     UInt_t k = *(reinterpret_cast<const UInt_t*>(msg_ptr));
00014     mmix(fHash, k);
00015     msg_ptr += 4;
00016     len -= 4;
00017   }
00018   
00019   MixTail(msg_ptr,len);
00020 }

MurmurHash3::Hash_t MurmurHash3::End ( UInt_t  seed = kDefaultSeed  ) 

Before returning, add any remaining tail, the message length and mush up the bits a bit more. We never want to apply the end mushing repeatedly - that would be ambiguous - so this also Resets the object.

Definition at line 40 of file MurmurHash3.cpp.

References EndImp(), fHash, fTail, and Reset().

00041 {
00042   Hash_t ret_hash = EndImp(fHash, fTail);
00043   this->Reset(seed);
00044   return ret_hash;
00045 }

MurmurHash3::Hash_t & MurmurHash3::EndImp ( Hash_t hash,
UInt_t &  tail 
) const [inline, private]

Takes parameters by reference and will mush them.

Definition at line 50 of file MurmurHash3.cpp.

References final_mix(), fSize, and mmix().

Referenced by End(), and Value().

00051 {
00052   if (tail) mmix(hash,tail);
00053   hash ^= fSize;
00054   final_mix(hash);
00055   return hash;
00056 }

void hash::MurmurHash3::final_mix ( Hash_t h  )  const [inline, private]

Definition at line 81 of file MurmurHash3.h.

Referenced by EndImp().

00082   {
00083     h ^= h >> 16;   h *= 0x85ebca6b;
00084     h ^= h >> 13;   h *= 0xc2b2ae35;
00085     h ^= h >> 16;
00086   }

void MurmurHash3::MixTail ( MsgPtr_t data,
Length_t len 
) [private]

Definition at line 64 of file MurmurHash3.cpp.

References fCount, fHash, fTail, and mmix().

Referenced by Add().

00065 {
00066   while( len && ((len<4) || fCount)) {
00067     fTail |= (*data++) << (fCount * 8);
00068     fCount++;
00069     len--;
00070     
00071     if(fCount == 4){
00072       mmix(fHash, fTail);
00073       fTail = 0;
00074       fCount = 0;
00075     } // if fCount =4
00076   } // while
00077 }

void hash::MurmurHash3::mmix ( Hash_t h,
UInt_t &  bits 
) const [inline, private]

Definition at line 75 of file MurmurHash3.h.

References kMply1, kMply2, and rot32().

Referenced by Add(), EndImp(), and MixTail().

00076   { 
00077     bits *= kMply1;   bits = rot32(bits, 15);   bits *= kMply2;
00078     h ^= bits;   h = rot32(h, 13) * 5 + 0xe6546b64;
00079   }

void hash::MurmurHash3::Reset ( UInt_t  seed = kDefaultSeed  )  [inline]

Definition at line 37 of file MurmurHash3.h.

References fCount, fHash, fSize, and fTail.

Referenced by End().

00038   {
00039     fHash = seed;
00040     fTail = fCount = fSize = 0;
00041   }

UInt_t hash::MurmurHash3::rot32 ( UInt_t  bits,
Rot_t  r 
) const [inline, private]

Definition at line 70 of file MurmurHash3.h.

Referenced by mmix().

00071   {
00072     return (bits << r) | (bits >> (32 - r));
00073   }

MurmurHash3::Hash_t MurmurHash3::Value (  )  const

Definition at line 27 of file MurmurHash3.cpp.

References EndImp(), fHash, and fTail.

00028 {
00029   //these must be copies so we dont touch our internal state
00030   Hash_t hash = fHash;
00031   UInt_t tail = fTail;
00032   return EndImp(hash, tail);
00033 }


Member Data Documentation

UInt_t hash::MurmurHash3::fCount [private]

Definition at line 101 of file MurmurHash3.h.

Referenced by MixTail(), and Reset().

Definition at line 99 of file MurmurHash3.h.

Referenced by Add(), End(), MixTail(), Reset(), and Value().

UInt_t hash::MurmurHash3::fSize [private]

Definition at line 102 of file MurmurHash3.h.

Referenced by Add(), EndImp(), and Reset().

UInt_t hash::MurmurHash3::fTail [private]

Definition at line 100 of file MurmurHash3.h.

Referenced by End(), MixTail(), Reset(), and Value().

const UInt_t hash::MurmurHash3::kMply1 = 0xcc9e2d51 [static, private]

Definition at line 90 of file MurmurHash3.h.

Referenced by mmix().

const UInt_t hash::MurmurHash3::kMply2 = 0x1b873593 [static, private]

Definition at line 91 of file MurmurHash3.h.

Referenced by mmix().


The documentation for this class was generated from the following files:

Generated on 15 Jun 2016 for AlcapDAQ by  doxygen 1.6.1