00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #ifndef itk_emulation_hash_map_h
00055 #define itk_emulation_hash_map_h
00056
00057 #if defined(_MSC_VER)
00058 #pragma warning ( disable : 4786 )
00059 #endif
00060
00061 #if (defined(__GNUC__) && (((__GNUC__==3) && (__GNUC_MINOR__>=1) || (__GNUC__>3) ) || ( (__GNUC__==4) && defined(__INTEL_COMPILER) ) )) || (defined(__IBMCPP__) && __IBMCPP__ >= 600)
00062
00063
00064
00065
00066
00067
00068
00069 #include <ext/hash_map>
00070
00071
00072 namespace itk
00073 {
00074 using __gnu_cxx::hash;
00075 using __gnu_cxx::hash_map;
00076 using __gnu_cxx::hash_multimap;
00077 }
00078
00079 #else
00080
00081 #include "itk_hashtable.h"
00082 #include "itk_alloc.h"
00083
00084
00085
00086 #if defined(__MWERKS__)
00087 #include "vcl_functional.h"
00088 #endif
00089
00090 #include "vcl_compiler.h"
00091
00092
00093 namespace itk
00094 {
00095
00096 # define VCL_IMPORT_CONTAINER_TYPEDEFS(super) \
00097 typedef typename super::value_type value_type; \
00098 typedef typename super::reference reference; \
00099 typedef typename super::size_type size_type; \
00100 typedef typename super::const_reference const_reference; \
00101 typedef typename super::difference_type difference_type;
00102
00103 # define VCL_IMPORT_ITERATORS(super) \
00104 typedef typename super::iterator iterator; \
00105 typedef typename super::const_iterator const_iterator;
00106
00107 # define VCL_IMPORT_REVERSE_ITERATORS(super) \
00108 typedef typename super::const_reverse_iterator const_reverse_iterator; \
00109 typedef typename super::reverse_iterator reverse_iterator;
00110
00111 template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
00112 class hash_map;
00113 template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
00114 class hash_multimap;
00115
00116 template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
00117 bool operator==(const hash_map<Key, T, HashFcn, EqualKey, Alloc>&,
00118 const hash_map<Key, T, HashFcn, EqualKey, Alloc>&);
00119 template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
00120 bool operator==(const hash_multimap<Key, T, HashFcn, EqualKey, Alloc>&,
00121 const hash_multimap<Key, T, HashFcn, EqualKey, Alloc>&);
00122
00126 template <class Key, class T,
00127 VCL_DFL_TMPL_PARAM_STLDECL(HashFcn,hash<Key>),
00128 VCL_DFL_TMPL_PARAM_STLDECL(EqualKey,std::equal_to<Key>),
00129 VCL_DFL_TYPE_PARAM_STLDECL(Alloc,std::allocator<char> ) >
00130 class hash_map
00131 {
00132 private:
00133 typedef std::select1st<std::pair<const Key, T> > sel1st;
00134 typedef hashtable<std::pair<const Key, T>, Key, HashFcn, sel1st, EqualKey, Alloc> ht;
00135 typedef hash_map<Key, T, HashFcn, EqualKey, Alloc> self;
00136 public:
00137 VCL_IMPORT_CONTAINER_TYPEDEFS(ht)
00138 VCL_IMPORT_ITERATORS(ht)
00139 typedef typename ht::key_type key_type;
00140 typedef typename ht::hasher hasher;
00141 typedef typename ht::key_equal key_equal;
00142 typedef T data_type;
00143 typedef typename ht::pointer pointer;
00144 typedef typename ht::const_pointer const_pointer;
00145 private:
00146 ht rep;
00147
00148 public:
00149 hasher hash_funct() const { return rep.hash_funct(); }
00150 key_equal key_eq() const { return rep.key_eq(); }
00151
00152 public:
00153 hash_map() : rep(100, hasher(), key_equal()) {}
00154 hash_map(size_type n) : rep(n, hasher(), key_equal()) {}
00155 hash_map(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
00156 hash_map(size_type n, const hasher& hf, const key_equal& eql)
00157 : rep(n, hf, eql) {}
00158
00159 hash_map(const value_type* f, const value_type* l)
00160 : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
00161 hash_map(const value_type* f, const value_type* l, size_type n)
00162 : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
00163 hash_map(const value_type* f, const value_type* l, size_type n,
00164 const hasher& hf)
00165 : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
00166 hash_map(const value_type* f, const value_type* l, size_type n,
00167 const hasher& hf, const key_equal& eql)
00168 : rep(n, hf, eql) { rep.insert_unique(f, l); }
00169
00170 hash_map(const_iterator f, const_iterator l)
00171 : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
00172 hash_map(const_iterator f, const_iterator l, size_type n)
00173 : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
00174 hash_map(const_iterator f, const_iterator l, size_type n,
00175 const hasher& hf)
00176 : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
00177 hash_map(const_iterator f, const_iterator l, size_type n,
00178 const hasher& hf, const key_equal& eql)
00179 : rep(n, hf, eql) { rep.insert_unique(f, l); }
00180
00181 public:
00182 size_type size() const { return rep.size(); }
00183 size_type max_size() const { return rep.max_size(); }
00184 bool empty() const { return rep.empty(); }
00185 void swap(self& hs) { rep.swap(hs.rep); }
00186
00187 friend bool operator==ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(self)(const self &, const self &);
00188
00189 iterator begin() { return rep.begin(); }
00190 iterator end() { return rep.end(); }
00191 const_iterator begin() const { return rep.begin(); }
00192 const_iterator end() const { return rep.end(); }
00193
00194 public:
00195 std::pair<iterator, bool> insert(const value_type& obj)
00196 { return rep.insert_unique(obj); }
00197 void insert(const value_type* f, const value_type* l) { rep.insert_unique(f,l); }
00198 void insert(const_iterator f, const_iterator l) { rep.insert_unique(f, l); }
00199 std::pair<iterator, bool> insert_noresize(const value_type& obj)
00200 { return rep.insert_unique_noresize(obj); }
00201
00202 iterator find(const key_type& key) { return rep.find(key); }
00203 const_iterator find(const key_type& key) const { return rep.find(key); }
00204
00205 T& operator[](const key_type& key)
00206 {
00207 value_type val(key, T());
00208 return rep.find_or_insert(val).second;
00209 }
00210
00211 size_type count(const key_type& key) const { return rep.count(key); }
00212
00213 std::pair<iterator, iterator> equal_range(const key_type& key)
00214 { return rep.equal_range(key); }
00215 std::pair<const_iterator, const_iterator> equal_range(const key_type& key) const
00216 { return rep.equal_range(key); }
00217
00218 size_type erase(const key_type& key) {return rep.erase(key); }
00219 void erase(iterator it) { rep.erase(it); }
00220 void erase(iterator f, iterator l) { rep.erase(f, l); }
00221 void clear() { rep.clear(); }
00222
00223 public:
00224 void resize(size_type hint) { rep.resize(hint); }
00225 size_type bucket_count() const { return rep.bucket_count(); }
00226 size_type max_bucket_count() const { return rep.max_bucket_count(); }
00227 size_type elems_in_bucket(size_type n) const
00228 { return rep.elems_in_bucket(n); }
00229 };
00230
00231
00232 template <class Key, class T, VCL_DFL_TMPL_PARAM_STLDECL(HashFcn,hash<Key>),
00233 VCL_DFL_TMPL_PARAM_STLDECL(EqualKey,std::equal_to<Key>),
00234 VCL_DFL_TYPE_PARAM_STLDECL(Alloc,std::allocator<char> ) >
00235 class hash_multimap
00236 {
00237 private:
00238 typedef hashtable<std::pair<const Key, T>, Key, HashFcn,
00239 std::select1st<std::pair<const Key, T> >, EqualKey, Alloc> ht;
00240 typedef hash_multimap<Key, T, HashFcn, EqualKey, Alloc> self;
00241 public:
00242 VCL_IMPORT_CONTAINER_TYPEDEFS(ht)
00243 VCL_IMPORT_ITERATORS(ht)
00244 typedef typename ht::key_type key_type;
00245 typedef typename ht::hasher hasher;
00246 typedef typename ht::key_equal key_equal;
00247 typedef T data_type;
00248 typedef typename ht::pointer pointer;
00249 typedef typename ht::const_pointer const_pointer;
00250
00251 hasher hash_funct() const { return rep.hash_funct(); }
00252 key_equal key_eq() const { return rep.key_eq(); }
00253 private:
00254 ht rep;
00255
00256 public:
00257 hash_multimap() : rep(100, hasher(), key_equal()) {}
00258 hash_multimap(size_type n) : rep(n, hasher(), key_equal()) {}
00259 hash_multimap(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
00260 hash_multimap(size_type n, const hasher& hf, const key_equal& eql)
00261 : rep(n, hf, eql) {}
00262
00263 hash_multimap(const value_type* f, const value_type* l)
00264 : rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
00265 hash_multimap(const value_type* f, const value_type* l, size_type n)
00266 : rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
00267 hash_multimap(const value_type* f, const value_type* l, size_type n,
00268 const hasher& hf)
00269 : rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
00270 hash_multimap(const value_type* f, const value_type* l, size_type n,
00271 const hasher& hf, const key_equal& eql)
00272 : rep(n, hf, eql) { rep.insert_equal(f, l); }
00273
00274 hash_multimap(const_iterator f, const_iterator l)
00275 : rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
00276 hash_multimap(const_iterator f, const_iterator l, size_type n)
00277 : rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
00278 hash_multimap(const_iterator f, const_iterator l, size_type n,
00279 const hasher& hf)
00280 : rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
00281 hash_multimap(const_iterator f, const_iterator l, size_type n,
00282 const hasher& hf, const key_equal& eql)
00283 : rep(n, hf, eql) { rep.insert_equal(f, l); }
00284
00285 public:
00286 size_type size() const { return rep.size(); }
00287 size_type max_size() const { return rep.max_size(); }
00288 bool empty() const { return rep.empty(); }
00289 void swap(self& hs) { rep.swap(hs.rep); }
00290
00291 friend bool operator==ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(self)(const self &, const self &);
00292
00293 iterator begin() { return rep.begin(); }
00294 iterator end() { return rep.end(); }
00295 const_iterator begin() const { return rep.begin(); }
00296 const_iterator end() const { return rep.end(); }
00297
00298 public:
00299 iterator insert(const value_type& obj) { return rep.insert_equal(obj); }
00300 void insert(const value_type* f, const value_type* l) { rep.insert_equal(f,l); }
00301 void insert(const_iterator f, const_iterator l) { rep.insert_equal(f, l); }
00302 iterator insert_noresize(const value_type& obj)
00303 { return rep.insert_equal_noresize(obj); }
00304
00305 iterator find(const key_type& key) { return rep.find(key); }
00306 const_iterator find(const key_type& key) const { return rep.find(key); }
00307
00308 size_type count(const key_type& key) const { return rep.count(key); }
00309
00310 std::pair<iterator, iterator> equal_range(const key_type& key)
00311 { return rep.equal_range(key); }
00312 std::pair<const_iterator, const_iterator> equal_range(const key_type& key) const
00313 { return rep.equal_range(key); }
00314
00315 size_type erase(const key_type& key) {return rep.erase(key); }
00316 void erase(iterator it) { rep.erase(it); }
00317 void erase(iterator f, iterator l) { rep.erase(f, l); }
00318 void clear() { rep.clear(); }
00319
00320 public:
00321 void resize(size_type hint) { rep.resize(hint); }
00322 size_type bucket_count() const { return rep.bucket_count(); }
00323 size_type max_bucket_count() const { return rep.max_bucket_count(); }
00324 size_type elems_in_bucket(size_type n) const
00325 { return rep.elems_in_bucket(n); }
00326 };
00327
00330 template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
00331 bool operator==(const hash_map<Key, T, HashFcn, EqualKey, Alloc>& hm1,
00332 const hash_map<Key, T, HashFcn, EqualKey, Alloc>& hm2)
00333 {
00334 return hm1.rep == hm2.rep;
00335 }
00336
00339 template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
00340 bool operator==(const hash_multimap<Key, T, HashFcn, EqualKey, Alloc>& hm1,
00341 const hash_multimap<Key, T, HashFcn, EqualKey, Alloc>& hm2)
00342 {
00343 return hm1.rep == hm2.rep;
00344 }
00345
00346
00347 #define HASH_MAP_INSTANTIATE \
00348 extern "please include emulation/hash_map.txx instead"
00349
00350 }
00351
00352 #endif
00353
00354 #endif // itk_emulation_hash_map_h
00355