Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 330 vs 331 for /trunk/Source Code/Utility/Headers/HashMap.h

Diff revisions: vs.
  @@ -30,28 +30,37 @@
30 30
31 31 namespace hashAlg = boost;
32 32
33 - template<typename K, typename V, typename HashFun = hashAlg::hash<K> >
34 - using hashMapImpl = hashAlg::unordered_map<K, V, HashFun>;
33 + template<typename K, typename V, typename HashFun = boost::hash<K> >
34 + using hashMapImpl = boost::unordered_map<K, V, HashFun>;
35 35
36 36 namespace boost {
37 +
38 + # if defined(STRING_IMP) && STRING_IMP == 0
39 + template<>
40 + struct hash<stringImpl>
41 + {
42 + size_t operator()(const stringImpl& v) const {
43 + return std::hash<std::string>()(v.c_str());
44 + }
45 + };
46 + # endif
47 +
48 + template<typename K, typename V, typename HashFun = boost::hash<K> >
49 + using hashPairReturn = std::pair<typename hashMapImpl<K, V, HashFun>::iterator, bool>;
50 +
37 51 template<typename T1, typename T2>
38 52 using pair = std::pair<T1, T2>;
39 - #if defined(STRING_IMP) && STRING_IMP == 0
40 - template<>
41 - struct hash<stringImpl>
42 - {
43 - size_t operator()(const stringImpl& v) const {
44 - return std::hash<std::string>()(v.c_str());
45 - }
46 - };
47 - #endif
53 +
48 54 template<typename K, typename V, typename HashFun = hashAlg::hash<K> >
49 - inline std::pair<typename hashMapImpl<K, V, HashFun>::iterator, bool> emplace(hashMapImpl<K, V, HashFun>& map, K key, const V& val){
55 + inline hashPairReturn<K, V, HashFun> emplace(hashMapImpl<K, V, HashFun>& map,
56 + K key,
57 + const V& val) {
50 58 return map.emplace(key, val);
51 59 }
52 60
53 61 template<typename K, typename V, typename HashFun = hashAlg::hash<K> >
54 - inline std::pair<typename hashMapImpl<K, V, HashFun>::iterator, bool> insert(hashMapImpl<K, V, HashFun>& map, const typename hashMapImpl<K, V, HashFun>::value_type& valuePair) {
62 + inline hashPairReturn<K, V, HashFun> insert(hashMapImpl<K, V, HashFun>& map,
63 + const typename hashMapImpl<K, V, HashFun>::value_type& valuePair) {
55 64 return map.insert(valuePair);
56 65 }
57 66
  @@ -59,6 +68,7 @@
59 68 inline void fastClear(hashMapImpl<K, V,HashFun>& map){
60 69 map.clear();
61 70 }
71 +
62 72 # ifndef BOOST_PAIR_FUNCS
63 73 # define BOOST_PAIR_FUNCS
64 74 template<typename K, typename V>
  @@ -77,37 +87,46 @@
77 87
78 88 #include <EASTL/hash_map.h>
79 89
80 - namespace hashAlg = eastl;
90 + namespace hashAlg = eastl;
81 91
82 - template<typename K, typename V, typename HashFun = hashAlg::hash<K> >
83 - using hashMapImpl = hashAlg::hash_map<K, V, HashFun>;
92 + template<typename K, typename V, typename HashFun = eastl::hash<K> >
93 + using hashMapImpl = eastl::hash_map<K, V, HashFun>;
84 94
85 95 namespace eastl {
86 96
87 - template<typename K, typename V, typename HashFun = hashAlg::hash<K> >
88 - inline eastl::pair<typename hashMapImpl<K, V, HashFun>::iterator, bool> emplace(hashMapImpl<K, V, HashFun>& map, K key, const V& val) {
97 + template<>
98 + struct hash<std::string>
99 + {
100 + size_t operator()(const std::string & x) const
101 + {
102 + return std::hash<std::string>()(x);
103 + }
104 + };
105 +
106 + template<typename K, typename V, typename HashFun = eastl::hash<K> >
107 + using hashPairReturn = eastl::pair<typename hashMapImpl<K, V, HashFun>::iterator, bool>;
108 +
109 + template<typename K, typename V, typename HashFun = eastl::hash<K> >
110 + inline hashPairReturn<K, V, HashFun> emplace(hashMapImpl<K, V, HashFun>& map,
111 + K key,
112 + const V& val) {
89 113 hashMapImpl<K, V, HashFun>::value_type value(key);
90 114 value.second = val;
91 115 return map.insert(value);
92 116 }
93 117
94 118 template<typename K, typename V, typename HashFun = hashAlg::hash<K> >
95 - inline eastl::pair<typename hashMapImpl<K, V, HashFun>::iterator, bool> insert(hashMapImpl<K, V, HashFun>& map, const typename hashMapImpl<K, V, HashFun>::value_type& valuePair) {
119 + inline hashPairReturn<K, V, HashFun> insert(hashMapImpl<K, V, HashFun>& map,
120 + const typename hashMapImpl<K, V, HashFun>::value_type& valuePair) {
96 121 return map.insert(valuePair);
97 122 }
98 123
99 124 template<typename K, typename V, typename HashFun = hashAlg::hash<K> >
100 125 inline void fastClear(hashMapImpl<K, V, HashFun>& map) {
101 - //map.reset(); <- leaks memory -Ionut
126 + //map.reset(); // leaks memory -Ionut
102 127 map.clear();
103 128 }
104 - template <> struct hash<std::string>
105 - {
106 - size_t operator()(const std::string & x) const
107 - {
108 - return std::hash<std::string>()(x);
109 - }
110 - };
129 +
111 130 # ifndef EASTL_PAIR_FUNCS
112 131 # define EASTL_PAIR_FUNCS
113 132 template<typename K, typename V>
  @@ -127,17 +146,33 @@
127 146
128 147 namespace hashAlg = std;
129 148
130 - template<typename K, typename V, typename HashFun = hashAlg::hash<K> >
131 - using hashMapImpl = hashAlg::unordered_map<K, V, HashFun>;
149 + template<typename K, typename V, typename HashFun = std::hash<K> >
150 + using hashMapImpl = std::unordered_map<K, V, HashFun>;
132 151
133 152 namespace std {
134 - template<typename K, typename V, typename HashFun = hashAlg::hash<K> >
135 - inline std::pair<typename hashMapImpl<K, V, HashFun>::iterator, bool> emplace(hashMapImpl<K, V, HashFun>& map, K key, const V& val){
153 +
154 + template<>
155 + struct hash<eastl::string>
156 + {
157 + size_t operator()(const eastl::string & x) const
158 + {
159 + return std::hash<std::string>()(x.c_str());
160 + }
161 + };
162 +
163 + template<typename K, typename V, typename HashFun = std::hash<K> >
164 + using hashPairReturn = std::pair<typename hashMapImpl<K, V, HashFun>::iterator, bool>;
165 +
166 + template<typename K, typename V, typename HashFun = hashAlg::hash<K> >
167 + inline hashPairReturn<K, V, HashFun> emplace(hashMapImpl<K, V, HashFun>& map,
168 + K key,
169 + const V& val) {
136 170 return map.emplace(key, val);
137 171 }
138 172
139 173 template<typename K, typename V, typename HashFun = hashAlg::hash<K> >
140 - inline std::pair<typename hashMapImpl<K, V, HashFun>::iterator, bool> insert(hashMapImpl<K, V, HashFun>& map, const typename hashMapImpl<K, V, HashFun>::value_type& valuePair) {
174 + inline hashPairReturn<K, V, HashFun> insert(hashMapImpl<K, V, HashFun>& map,
175 + const typename hashMapImpl<K, V, HashFun>::value_type& valuePair) {
141 176 return map.insert(valuePair);
142 177 }
143 178
  @@ -145,6 +180,7 @@
145 180 inline void fastClear(hashMapImpl<K, V, HashFun>& map){
146 181 map.clear();
147 182 }
183 +
148 184 # ifndef STD_PAIR_FUNCS
149 185 # define STD_PAIR_FUNCS
150 186 template<typename K, typename V>