00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef INCLUDE_HASH_STREAMHASHER_H
00015 #define INCLUDE_HASH_STREAMHASHER_H
00016
00017 #include "base/inttypes.h"
00018
00019 namespace hash
00020 {
00021
00022
00023
00024
00025 class StreamHasher
00026 {
00027 public:
00028
00029
00030
00031
00032
00033 StreamHasher(uint32_t initVal)
00034 : hashValue(initVal)
00035 {}
00036
00037
00038
00039
00040
00041 void addValue(uint32_t value)
00042 {
00043 hashValue = (hashValue ^ value) +
00044 ((hashValue << 26) + (hashValue >> 6));
00045 }
00046
00047
00048
00049
00050
00051 void addValue(int32_t value)
00052 {
00053 addValue((uint32_t)value);
00054 }
00055
00056
00057
00058
00059
00060 uint32_t hash()
00061 {
00062 return hashValue;
00063 }
00064
00065
00066 private:
00067 uint32_t hashValue;
00068 };
00069
00070 }
00071
00072 #endif // INCLUDE_HASH_STREAMHASHER_H