00001 #ifndef HASH_AC_H
00002 #define HASH_AC_H
00003
00004 #include "Rtypes.h"
00005
00006
00007 namespace hash_utils{
00010 struct murmurhash2 {
00011 murmurhash2(UInt_t seed) : fSeed(seed) {};
00012 UInt_t operator()(const void* key, int len) const;
00013 const UInt_t fSeed;
00014 };
00015
00016 inline UInt_t void_to_int(const void* key, int length)
00017 {
00018 static murmurhash2 pet(0xe086c5ff);
00019 return pet(key, length);
00020 }
00021
00022 class MurmurHash3;
00023
00024
00025 };
00026
00027 class hash_utils::MurmurHash3{
00028 public:
00029 typedef const Byte_t* MsgPtr_t;
00030 typedef UInt_t Hash_t;
00031 typedef Int_t Length_t;
00032 typedef Byte_t Rot_t;
00033
00034 MurmurHash3(unsigned int seed = 0xe086c5ff)
00035 : fHash(seed), fTail(0), fCount(0), fSize(0)
00036 {}
00037
00038 void Add(MsgPtr_t msg_ptr, Length_t len);
00039 Hash_t End();
00040
00041 private:
00042 void MixTail (MsgPtr_t& data, Length_t& len);
00043
00044 inline UInt_t rot32(UInt_t bits, Rot_t r)
00045 {
00046 return (bits << r) | (bits >> (32 - r));
00047 }
00048
00049 inline void mmix(Hash_t& h, UInt_t& bits)
00050 {
00051 bits *= kMply1; bits = rot32(bits, 15); bits *= kMply2;
00052 h ^= bits; h = rot32(h, 13) * 5 + 0xe6546b64;
00053 }
00054
00055 inline void final_mix(Hash_t& h)
00056 {
00057 h ^= h >> 16; h *= 0x85ebca6b;
00058 h ^= h >> 13; h *= 0xc2b2ae35;
00059 h ^= h >> 16;
00060 }
00061
00062 static const UInt_t kMply1 = 0xcc9e2d51;
00063 static const UInt_t kMply2 = 0x1b873593;
00064
00065
00066
00067
00068
00069
00070 Hash_t fHash;
00071 UInt_t fTail;
00072 UInt_t fCount;
00073 UInt_t fSize;
00074 };
00075
00076 #endif //HASH_AC_H