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_set_h
00055 #define itk_emulation_hash_set_h
00056
00057 #if (defined(__GNUC__) && (((__GNUC__==3) && (__GNUC_MINOR__>=1) || (__GNUC__>3) ) || ( (__GNUC__==4) && defined(__INTEL_COMPILER) ) )) || (defined(__IBMCPP__) && __IBMCPP__ >= 600)
00058
00059 #include <ext/hash_set>
00060
00061 namespace itk
00062 {
00063 using __gnu_cxx::hash;
00064 using __gnu_cxx::hash_set;
00065 using __gnu_cxx::hash_multiset;
00066 }
00067
00068 #else
00069
00070 #include "itk_hashtable.h"
00071 #include <functional>
00072
00073
00074
00075 namespace itk
00076 {
00077
00081 template <class Value, VCL_DFL_TMPL_PARAM_STLDECL(HashFcn,hash<Value>),
00082 VCL_DFL_TMPL_PARAM_STLDECL(EqualKey,std::equal_to<Value>),
00083 VCL_DFL_TYPE_PARAM_STLDECL(Alloc,std::allocator<char> ) >
00084 class hash_set
00085 {
00086 private:
00087 typedef hashtable<Value, Value, HashFcn, std::identity<Value>,
00088 EqualKey, Alloc> ht;
00089 typedef hash_set<Value, HashFcn, EqualKey, Alloc> self;
00090 public:
00091 typedef typename ht::key_type key_type;
00092 typedef typename ht::value_type value_type;
00093 typedef typename ht::hasher hasher;
00094 typedef typename ht::key_equal key_equal;
00095
00096 typedef typename ht::size_type size_type;
00097 typedef typename ht::difference_type difference_type;
00098 typedef typename ht::const_pointer pointer;
00099 typedef typename ht::const_pointer const_pointer;
00100 typedef typename ht::const_reference reference;
00101 typedef typename ht::const_reference const_reference;
00102
00103 typedef typename ht::const_iterator const_iterator;
00104 typedef const_iterator iterator;
00105
00106
00107 typedef typename ht::iterator ht_iterator;
00108
00109 hasher hash_funct() const { return rep.hash_funct(); }
00110 key_equal key_eq() const { return rep.key_eq(); }
00111
00112 private:
00113 ht rep;
00114
00115 public:
00116 hash_set() : rep(100, hasher(), key_equal()) {}
00117 hash_set(size_type n) : rep(n, hasher(), key_equal()) {}
00118 hash_set(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
00119 hash_set(size_type n, const hasher& hf, const key_equal& eql)
00120 : rep(n, hf, eql) {}
00121
00122 hash_set(const value_type* f, const value_type* l)
00123 : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
00124 hash_set(const value_type* f, const value_type* l, size_type n)
00125 : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
00126 hash_set(const value_type* f, const value_type* l, size_type n,
00127 const hasher& hf)
00128 : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
00129 hash_set(const value_type* f, const value_type* l, size_type n,
00130 const hasher& hf, const key_equal& eql)
00131 : rep(n, hf, eql) { rep.insert_unique(f, l); }
00132
00133 hash_set(const_iterator f, const_iterator l)
00134 : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
00135 hash_set(const_iterator f, const_iterator l, size_type n)
00136 : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
00137 hash_set(const_iterator f, const_iterator l, size_type n,
00138 const hasher& hf)
00139 : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
00140 hash_set(const_iterator f, const_iterator l, size_type n,
00141 const hasher& hf, const key_equal& eql)
00142 : rep(n, hf, eql) { rep.insert_unique(f, l); }
00143
00144 public:
00145 size_type size() const { return rep.size(); }
00146 size_type max_size() const { return rep.max_size(); }
00147 bool empty() const { return rep.empty(); }
00148 void swap(self& hs) { rep.swap(hs.rep); }
00149
00150 friend bool operator==ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(self)(const self &, const self &);
00151
00152 iterator begin() const { return rep.begin(); }
00153 iterator end() const { return rep.end(); }
00154
00155 public:
00156 std::pair<iterator, bool> insert(const value_type& obj)
00157 {
00158 #ifdef _MSC_VER
00159 std::pair< ht::iterator, bool> p = rep.insert_unique(obj);
00160 #else
00161 std::pair<typename ht::iterator, bool> p = rep.insert_unique(obj);
00162 #endif
00163 return std::pair<iterator, bool>(p.first, p.second);
00164 }
00165 void insert(const value_type* f, const value_type* l) { rep.insert_unique(f,l); }
00166 void insert(const_iterator f, const_iterator l) { rep.insert_unique(f, l); }
00167 std::pair<iterator, bool> insert_noresize(const value_type& obj)
00168 {
00169 #ifdef _MSC_VER
00170 std::pair<ht::iterator, bool> p = rep.insert_unique_noresize(obj);
00171 #else
00172 std::pair<typename ht::iterator, bool> p = rep.insert_unique_noresize(obj);
00173 #endif
00174 return std::pair<iterator, bool>(p.first, p.second);
00175 }
00176
00177 iterator find(const key_type& key) const { return rep.find(key); }
00178
00179 size_type count(const key_type& key) const { return rep.count(key); }
00180
00181 std::pair<iterator, iterator> equal_range(const key_type& key) const
00182 { return rep.equal_range(key); }
00183
00184 size_type erase(const key_type& key) {return rep.erase(key); }
00185 void erase(iterator it) { rep.erase(it); }
00186 void erase(iterator f, iterator l) { rep.erase(f, l); }
00187 void clear() { rep.clear(); }
00188
00189 public:
00190 void resize(size_type hint) { rep.resize(hint); }
00191 size_type bucket_count() const { return rep.bucket_count(); }
00192 size_type max_bucket_count() const { return rep.max_bucket_count(); }
00193 size_type elems_in_bucket(size_type n) const
00194 { return rep.elems_in_bucket(n); }
00195 };
00196
00197
00198 template <class Value, VCL_DFL_TMPL_PARAM_STLDECL(HashFcn,hash<Value>),
00199 VCL_DFL_TMPL_PARAM_STLDECL(EqualKey,std::equal_to<Value>),
00200 VCL_DFL_TYPE_PARAM_STLDECL(Alloc,std::allocator<char> ) >
00201 class hash_multiset
00202 {
00203 private:
00204 typedef hashtable<Value, Value, HashFcn, std::identity<Value>,
00205 EqualKey, Alloc> ht;
00206 typedef hash_multiset<Value, HashFcn, EqualKey, Alloc> self;
00207 public:
00208 typedef typename ht::key_type key_type;
00209 typedef typename ht::value_type value_type;
00210 typedef typename ht::hasher hasher;
00211 typedef typename ht::key_equal key_equal;
00212
00213 typedef typename ht::size_type size_type;
00214 typedef typename ht::difference_type difference_type;
00215 typedef typename ht::const_pointer pointer;
00216 typedef typename ht::const_pointer const_pointer;
00217 typedef typename ht::const_reference reference;
00218 typedef typename ht::const_reference const_reference;
00219
00220 typedef typename ht::const_iterator const_iterator;
00221
00222 typedef const_iterator iterator;
00223
00224 hasher hash_funct() const { return rep.hash_funct(); }
00225 key_equal key_eq() const { return rep.key_eq(); }
00226 private:
00227 ht rep;
00228
00229 public:
00230 hash_multiset() : rep(100, hasher(), key_equal()) {}
00231 hash_multiset(size_type n) : rep(n, hasher(), key_equal()) {}
00232 hash_multiset(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
00233 hash_multiset(size_type n, const hasher& hf, const key_equal& eql)
00234 : rep(n, hf, eql) {}
00235
00236 hash_multiset(const value_type* f, const value_type* l)
00237 : rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
00238 hash_multiset(const value_type* f, const value_type* l, size_type n)
00239 : rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
00240 hash_multiset(const value_type* f, const value_type* l, size_type n,
00241 const hasher& hf)
00242 : rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
00243 hash_multiset(const value_type* f, const value_type* l, size_type n,
00244 const hasher& hf, const key_equal& eql)
00245 : rep(n, hf, eql) { rep.insert_equal(f, l); }
00246
00247 hash_multiset(const_iterator f, const_iterator l)
00248 : rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
00249 hash_multiset(const_iterator f, const_iterator l, size_type n)
00250 : rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
00251 hash_multiset(const_iterator f, const_iterator l, size_type n,
00252 const hasher& hf)
00253 : rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
00254 hash_multiset(const_iterator f, const_iterator l, size_type n,
00255 const hasher& hf, const key_equal& eql)
00256 : rep(n, hf, eql) { rep.insert_equal(f, l); }
00257
00258 public:
00259 size_type size() const { return rep.size(); }
00260 size_type max_size() const { return rep.max_size(); }
00261 bool empty() const { return rep.empty(); }
00262 void swap(self& hs) { rep.swap(hs.rep); }
00263
00264 friend bool operator==ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(self)(const self &, const self &);
00265
00266 iterator begin() const { return rep.begin(); }
00267 iterator end() const { return rep.end(); }
00268
00269 public:
00270 iterator insert(const value_type& obj) { return rep.insert_equal(obj); }
00271 void insert(const value_type* f, const value_type* l) { rep.insert_equal(f,l); }
00272 void insert(const_iterator f, const_iterator l) { rep.insert_equal(f, l); }
00273 iterator insert_noresize(const value_type& obj)
00274 { return rep.insert_equal_noresize(obj); }
00275
00276 iterator find(const key_type& key) const { return rep.find(key); }
00277
00278 size_type count(const key_type& key) const { return rep.count(key); }
00279
00280 std::pair<iterator, iterator> equal_range(const key_type& key) const
00281 { return rep.equal_range(key); }
00282
00283 size_type erase(const key_type& key) {return rep.erase(key); }
00284 void erase(iterator it) { rep.erase(it); }
00285 void erase(iterator f, iterator l) { rep.erase(f, l); }
00286 void clear() { rep.clear(); }
00287
00288 public:
00289 void resize(size_type hint) { rep.resize(hint); }
00290 size_type bucket_count() const { return rep.bucket_count(); }
00291 size_type max_bucket_count() const { return rep.max_bucket_count(); }
00292 size_type elems_in_bucket(size_type n) const
00293 { return rep.elems_in_bucket(n); }
00294 };
00295
00296
00299 template <class Value, class HashFcn, class EqualKey, class Alloc>
00300 bool operator==(const hash_set<Value, HashFcn, EqualKey, Alloc>& hs1,
00301 const hash_set<Value, HashFcn, EqualKey, Alloc>& hs2)
00302 {
00303 return hs1.rep == hs2.rep;
00304 }
00305
00308 template <class Value, class HashFcn, class EqualKey, class Alloc>
00309 bool operator==(const hash_multiset<Value, HashFcn, EqualKey, Alloc>& hs1,
00310 const hash_multiset<Value, HashFcn, EqualKey, Alloc>& hs2)
00311 {
00312 return hs1.rep == hs2.rep;
00313 }
00314
00315 # if defined (__STL_CLASS_PARTIAL_SPECIALIZATION )
00316 template <class Value, class HashFcn, class EqualKey, class Alloc>
00317 inline void swap(hash_multiset<Value, HashFcn, EqualKey, Alloc>& a,
00318 hash_multiset<Value, HashFcn, EqualKey, Alloc>& b) { a.swap(b); }
00319 template <class Value, class HashFcn, class EqualKey, class Alloc>
00320 inline void swap(hash_set<Value, HashFcn, EqualKey, Alloc>& a,
00321 hash_set<Value, HashFcn, EqualKey, Alloc>& b) { a.swap(b); }
00322 # endif
00323
00324 }
00325
00326 #endif
00327 #endif // itk_emulation_hash_set_h
00328