53 #ifndef generic_hash_h_
54 #define generic_hash_h_
78 template <
class Iterator,
class HashType,
class UnaryOp>
86 while (start != finish){
88 sum += ((op(*start))+1) * ((op(*start))+1);
95 template <
class Iterator,
class HashType,
class UnaryOp>
102 while (start != finish) {
103 hash ^= ((hash << 5) + op(*start) + (hash >> 2));
110 template <
class Iterator,
class HashType,
class UnaryOp>
115 const HashType nBits = (HashType)(
sizeof(HashType) * 8);
116 const HashType nTimes3Div4 = (HashType)((nBits * 3) / 4);
117 const HashType nDiv8 = (HashType)(nBits / 8);
118 const HashType BitMaskHigh = (HashType)(0xFFFFFFFF) << (nBits - nDiv8);
123 while (start != finish) {
124 hash = (hash << nDiv8) + op(*start);
126 if((test = hash & BitMaskHigh) != 0) {
127 hash = (( hash ^ (test >> nTimes3Div4)) & (~BitMaskHigh));
136 template <
class Iterator,
class HashType,
class UnaryOp>
144 while (start != finish) {
145 hash = (hash << 4) + op(*start);
146 if((tmp = hash & 0xF0000000L) != 0) {
155 template <
class Iterator,
class HashType,
class UnaryOp>
160 HashType magic_number = 131;
163 while (start != finish) {
164 hash = (hash * magic_number) + op(*start);
170 template <
class Iterator,
class HashType,
class UnaryOp>
177 while (start != finish) {
178 hash = op(*start) + (hash << 6) + (hash << 16) - hash;
185 template <
class Iterator,
class HashType,
class UnaryOp>
192 while (start != finish) {
193 hash = ((hash << 5) + hash) + op(*start);
200 template <
class Iterator,
class HashType,
class UnaryOp>
206 hash =
static_cast<HashType
>(std::distance(start, finish));
208 while (start != finish) {
209 hash = ((hash << 5) ^ (hash >> 27)) ^ op(*start);
219 template <
class ValueType>
222 template <
class ValueType>
223 const ValueType&
operator()(
const ValueType& val)
const {
return val; }
229 template <
class ValueType>
233 template <
class Iterator,
class HashType,
class HashTag>
242 template <
class Iterator,
class HashType,
243 class AlgTag, HashType BitMask = 0x7FFFFFFF>
257 return (--hash &
mask);
261 template <
class VectorType,
class HashType,
262 class AlgTag, HashType BitMask = 0x7FFFFFFF>
273 return hash_op(vec.begin(), vec.end());