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