1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4
5 #ifndef ICE_HASH_UTIL_H
6 #define ICE_HASH_UTIL_H
7
8 namespace IceInternal
9 {
10
11 inline void
hashAdd(Ice::Int & hashCode,Ice::Int value)12 hashAdd(Ice::Int& hashCode, Ice::Int value)
13 {
14 hashCode = ((hashCode << 5) + hashCode) ^ (2654435761u * value);
15 }
16
17 inline void
hashAdd(Ice::Int & hashCode,bool value)18 hashAdd(Ice::Int& hashCode, bool value)
19 {
20 hashCode = ((hashCode << 5) + hashCode) ^ (value ? 1 : 0);
21 }
22
23 inline void
hashAdd(Ice::Int & hashCode,const std::string & value)24 hashAdd(Ice::Int& hashCode, const std::string& value)
25 {
26 for(std::string::const_iterator p = value.begin(); p != value.end(); ++p)
27 {
28 hashCode = ((hashCode << 5) + hashCode) ^ *p;
29 }
30 }
31
32 template<typename T> void
hashAdd(Ice::Int & hashCode,const std::vector<T> & seq)33 hashAdd(Ice::Int& hashCode, const std::vector<T>& seq)
34 {
35 for(typename std::vector<T>::const_iterator p = seq.begin(); p != seq.end(); ++p)
36 {
37 hashAdd(hashCode, *p);
38 }
39 }
40
41 template<typename K, typename V> void
hashAdd(Ice::Int & hashCode,const std::map<K,V> & map)42 hashAdd(Ice::Int& hashCode, const std::map<K, V>& map)
43 {
44 for(typename std::map<K, V>::const_iterator p = map.begin(); p != map.end(); ++p)
45 {
46 hashAdd(hashCode, p->first);
47 hashAdd(hashCode, p->second);
48 }
49 }
50
51 }
52
53 #endif
54