KWStyle - itk_hash_set.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itk_hash_set.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:46 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 /*
18 IND ** Copyright (c) 1996
19 IND ** Silicon Graphics Computer Systems, Inc.
20 IND **
21 IND ** Permission to use, copy, modify, distribute and sell this software
22 IND ** and its documentation for any purpose is hereby granted without fee,
23 IND ** provided that the above copyright notice appear in all copies and
24 IND ** that both that copyright notice and this permission notice appear
25 IND ** in supporting documentation.  Silicon Graphics makes no
26 IND ** representations about the suitability of this software for any
27 IND ** purpose.  It is provided "as is" without express or implied warranty.
28 IND **
29 IND **
30 IND ** Copyright (c) 1994
31 IND ** Hewlett-Packard Company
32 IND **
33 IND ** Permission to use, copy, modify, distribute and sell this software
34 IND ** and its documentation for any purpose is hereby granted without fee,
35 IND ** provided that the above copyright notice appear in all copies and
36 IND ** that both that copyright notice and this permission notice appear
37 IND ** in supporting documentation.  Hewlett-Packard Company makes no
38 IND ** representations about the suitability of this software for any
39 IND ** purpose.  It is provided "as is" without express or implied warranty.
40 IND **
41 IND ** Copyright (c) 1997
42 IND ** Moscow Center for SPARC Technology
43 IND **
44 IND ** Permission to use, copy, modify, distribute and sell this software
45 IND ** and its documentation for any purpose is hereby granted without fee,
46 IND ** provided that the above copyright notice appear in all copies and
47 IND ** that both that copyright notice and this permission notice appear
48 IND ** in supporting documentation.  Moscow Center for SPARC Technology makes no
49 IND ** representations about the suitability of this software for any
50 IND ** purpose.  It is provided "as is" without express or implied warranty.
51 IND **
52 IND **/
53
54 DEF #ifndef itk_emulation_hash_set_h
55 DEF #define itk_emulation_hash_set_h
56
57 LEN #if (defined(__GNUC__) && ((__GNUC__==3) && (__GNUC_MINOR__>=1) || (__GNUC__>3)) && !defined(__INTEL_COMPILER)) || (defined(__IBMCPP__) && __IBMCPP__ >= 600)
58 #include <ext/hash_set>
59
60 namespace itk
61 {
62 IND **using __gnu_cxx::hash;
63 IND **using __gnu_cxx::hash_set;
64 IND **using __gnu_cxx::hash_multiset;
65 }
66
67 #else
68
69 #include "itk_hashtable.h"
70 #include <functional>
71
72 // ---
73
74 namespace itk
75 {
76   
77 /** \brief Replacement for STL hash set because some systems do not support it,
78  * or support it incorrectly.
79  */
80 template <class Value, VCL_DFL_TMPL_PARAM_STLDECL(HashFcn,hash<Value>),
81 IND **********VCL_DFL_TMPL_PARAM_STLDECL(EqualKey,std::equal_to<Value>),
82 IND **********VCL_DFL_TYPE_PARAM_STLDECL(Alloc,std::allocator<char> ) >
83 class hash_set
84 MCM {
85 private:
86   typedef hashtable<Value, Value, HashFcn, std::identity<Value>, 
87 TDR,IND ******EqualKey, Alloc> ht;
88 TDA,TDR   typedef hash_set<Value, HashFcn, EqualKey, Alloc> self;
89 public:
90 TDR   typedef typename ht::key_type key_type;
91 TDA,TDR   typedef typename ht::value_type value_type;
92 TDA,TDR   typedef typename ht::hasher hasher;
93 TDA,TDR   typedef typename ht::key_equal key_equal;
94
95 TDR   typedef typename ht::size_type size_type;
96 TDA,TDR   typedef typename ht::difference_type difference_type;
97 TDA,TDR   typedef typename ht::const_pointer pointer;
98 TDA,TDR   typedef typename ht::const_pointer const_pointer;
99 TDA,TDR   typedef typename ht::const_reference reference;
100 TDA,TDR   typedef typename ht::const_reference const_reference;
101   // SunPro bug
102 TDR   typedef typename ht::const_iterator const_iterator;
103 TDA,TDR   typedef const_iterator iterator;
104
105   // vc6 addition
106 TDR   typedef typename ht::iterator ht_iterator;
107
108   hasher hash_funct() const { return rep.hash_funct(); }
109   key_equal key_eq() const { return rep.key_eq(); }
110
111 private:
112   ht rep;
113
114 public:
115   hash_set() : rep(100, hasher(), key_equal()) {}
116   hash_set(size_type n) : rep(n, hasher(), key_equal()) {}
117   hash_set(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
118   hash_set(size_type n, const hasher& hf, const key_equal& eql)
119 IND ****: rep(n, hf, eql) {}
120
121   hash_set(const value_type* f, const value_type* l)
122 IND ****: rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
123   hash_set(const value_type* f, const value_type* l, size_type n)
124 IND ****: rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
125   hash_set(const value_type* f, const value_type* l, size_type n,
126            const hasher& hf)
127 IND ****: rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
128   hash_set(const value_type* f, const value_type* l, size_type n,
129            const hasher& hf, const key_equal& eql)
130 IND ****: rep(n, hf, eql) { rep.insert_unique(f, l); }
131
132   hash_set(const_iterator f, const_iterator l)
133 IND ****: rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
134   hash_set(const_iterator f, const_iterator l, size_type n)
135 IND ****: rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
136   hash_set(const_iterator f, const_iterator l, size_type n,
137            const hasher& hf)
138 IND ****: rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
139   hash_set(const_iterator f, const_iterator l, size_type n,
140            const hasher& hf, const key_equal& eql)
141 IND ****: rep(n, hf, eql) { rep.insert_unique(f, l); }
142
143 public:
144   size_type size() const { return rep.size(); }
145   size_type max_size() const { return rep.max_size(); }
146   bool empty() const { return rep.empty(); }
147   void swap(self& hs) { rep.swap(hs.rep); }
148 LEN   friend bool operator==VCL_NULL_TMPL_ARGS(const hash_set<Value,HashFcn,EqualKey,Alloc>&,
149                            const hash_set<Value,HashFcn,EqualKey,Alloc>&);
150
151   iterator begin() const { return rep.begin(); }
152   iterator end() const { return rep.end(); }
153
154 public:
155   std::pair<iterator, bool> insert(const value_type& obj)
156     {
157 #ifdef _MSC_VER
158 IND ******std::pair< ht::iterator, bool> p = rep.insert_unique(obj);
159 IND #else
160 IND ******std::pair<typename ht::iterator, bool> p = rep.insert_unique(obj);
161 #endif
162 IND ******return std::pair<iterator, bool>(p.first, p.second);
163     }
164 LEN   void insert(const value_type* f, const value_type* l) { rep.insert_unique(f,l); }
165   void insert(const_iterator f, const_iterator l) { rep.insert_unique(f, l); }
166   std::pair<iterator, bool> insert_noresize(const value_type& obj)
167     {
168 #ifdef _MSC_VER
169     std::pair<ht::iterator, bool> p = rep.insert_unique_noresize(obj);
170 IND #else
171 LEN,IND ******std::pair<typename ht::iterator, bool> p = rep.insert_unique_noresize(obj);
172 #endif
173 IND ******return std::pair<iterator, bool>(p.first, p.second);
174     }
175
176   iterator find(const key_type& key) const { return rep.find(key); }
177
178   size_type count(const key_type& key) const { return rep.count(key); }
179   
180   std::pair<iterator, iterator> equal_range(const key_type& key) const
181     { return rep.equal_range(key); }
182
183   size_type erase(const key_type& key) {return rep.erase(key); }
184   void erase(iterator it) { rep.erase(it); }
185   void erase(iterator f, iterator l) { rep.erase(f, l); }
186   void clear() { rep.clear(); }
187
188 public:
189   void resize(size_type hint) { rep.resize(hint); }
190   size_type bucket_count() const { return rep.bucket_count(); }
191   size_type max_bucket_count() const { return rep.max_bucket_count(); }
192   size_type elems_in_bucket(size_type n) const
193     { return rep.elems_in_bucket(n); }
194 };
195
196
197 template <class Value, VCL_DFL_TMPL_PARAM_STLDECL(HashFcn,hash<Value>),
198 IND **********VCL_DFL_TMPL_PARAM_STLDECL(EqualKey,std::equal_to<Value>),
199 IND **********VCL_DFL_TYPE_PARAM_STLDECL(Alloc,std::allocator<char> ) >
200 class hash_multiset
201 {
202 private:
203   typedef hashtable<Value, Value, HashFcn, std::identity<Value>, 
204 TDR,IND ******EqualKey, Alloc> ht;
205 TDA,TDR   typedef hash_multiset<Value, HashFcn, EqualKey, Alloc> self;
206 public:
207 TDR   typedef typename ht::key_type key_type;
208 TDA,TDR   typedef typename ht::value_type value_type;
209 TDA,TDR   typedef typename ht::hasher hasher;
210 TDA,TDR   typedef typename ht::key_equal key_equal;
211
212 TDR   typedef typename ht::size_type size_type;
213 TDA,TDR   typedef typename ht::difference_type difference_type;
214 TDA,TDR   typedef typename ht::const_pointer pointer;
215 TDA,TDR   typedef typename ht::const_pointer const_pointer;
216 TDA,TDR   typedef typename ht::const_reference reference;
217 TDA,TDR   typedef typename ht::const_reference const_reference;
218
219 TDR   typedef typename ht::const_iterator const_iterator;
220   // SunPro bug
221 TDR   typedef const_iterator iterator;
222
223   hasher hash_funct() const { return rep.hash_funct(); }
224   key_equal key_eq() const { return rep.key_eq(); }
225 private:
226   ht rep;
227
228 public:
229   hash_multiset() : rep(100, hasher(), key_equal()) {}
230   hash_multiset(size_type n) : rep(n, hasher(), key_equal()) {}
231   hash_multiset(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
232   hash_multiset(size_type n, const hasher& hf, const key_equal& eql)
233 IND ****: rep(n, hf, eql) {}
234
235   hash_multiset(const value_type* f, const value_type* l)
236 IND ****: rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
237   hash_multiset(const value_type* f, const value_type* l, size_type n)
238 IND ****: rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
239   hash_multiset(const value_type* f, const value_type* l, size_type n,
240            const hasher& hf)
241 IND ****: rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
242   hash_multiset(const value_type* f, const value_type* l, size_type n,
243            const hasher& hf, const key_equal& eql)
244 IND ****: rep(n, hf, eql) { rep.insert_equal(f, l); }
245
246   hash_multiset(const_iterator f, const_iterator l)
247 IND ****: rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
248   hash_multiset(const_iterator f, const_iterator l, size_type n)
249 IND ****: rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
250   hash_multiset(const_iterator f, const_iterator l, size_type n,
251            const hasher& hf)
252 IND ****: rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
253   hash_multiset(const_iterator f, const_iterator l, size_type n,
254            const hasher& hf, const key_equal& eql)
255 IND ****: rep(n, hf, eql) { rep.insert_equal(f, l); }
256
257 public:
258   size_type size() const { return rep.size(); }
259   size_type max_size() const { return rep.max_size(); }
260   bool empty() const { return rep.empty(); }
261   void swap(self& hs) { rep.swap(hs.rep); }
262 LEN   friend bool operator==VCL_NULL_TMPL_ARGS(const hash_multiset<Value,HashFcn,EqualKey,Alloc>&,
263                          const hash_multiset<Value,HashFcn,EqualKey,Alloc>&);
264
265   iterator begin() const { return rep.begin(); }
266   iterator end() const { return rep.end(); }
267
268 public:
269   iterator insert(const value_type& obj) { return rep.insert_equal(obj); }
270 LEN   void insert(const value_type* f, const value_type* l) { rep.insert_equal(f,l); }
271   void insert(const_iterator f, const_iterator l) { rep.insert_equal(f, l); }
272   iterator insert_noresize(const value_type& obj)
273     { return rep.insert_equal_noresize(obj); }    
274
275   iterator find(const key_type& key) const { return rep.find(key); }
276
277   size_type count(const key_type& key) const { return rep.count(key); }
278   
279   std::pair<iterator, iterator> equal_range(const key_type& key) const
280     { return rep.equal_range(key); }
281
282   size_type erase(const key_type& key) {return rep.erase(key); }
283   void erase(iterator it) { rep.erase(it); }
284   void erase(iterator f, iterator l) { rep.erase(f, l); }
285   void clear() { rep.clear(); }
286
287 public:
288   void resize(size_type hint) { rep.resize(hint); }
289   size_type bucket_count() const { return rep.bucket_count(); }
290   size_type max_bucket_count() const { return rep.max_bucket_count(); }
291   size_type elems_in_bucket(size_type n) const
292     { return rep.elems_in_bucket(n); }
293 };
294
295
296 template <class Value, class HashFcn, class EqualKey, class Alloc>
297 inline bool operator==(const hash_set<Value, HashFcn, EqualKey, Alloc>& hs1,
298                        const hash_set<Value, HashFcn, EqualKey, Alloc>& hs2)
299 {
300   return hs1.rep == hs2.rep;
301 }
302
303 template <class Value, class HashFcn, class EqualKey, class Alloc>
304 LEN inline bool operator==(const hash_multiset<Value, HashFcn, EqualKey, Alloc>& hs1,
305 LEN                        const hash_multiset<Value, HashFcn, EqualKey, Alloc>& hs2)
306 {
307   return hs1.rep == hs2.rep;
308 }
309
310 # if defined (__STL_CLASS_PARTIAL_SPECIALIZATION )
311 template <class Value, class HashFcn, class EqualKey, class Alloc>
312 inline void swap(hash_multiset<Value, HashFcn, EqualKey, Alloc>& a,
313 LEN,IND,IND *****************hash_multiset<Value, HashFcn, EqualKey, Alloc>& b) { a.swap(b); }
314 template <class Value, class HashFcn, class EqualKey, class Alloc>
315 inline void swap(hash_set<Value, HashFcn, EqualKey, Alloc>& a,
316 IND,IND *****************hash_set<Value, HashFcn, EqualKey, Alloc>& b) { a.swap(b); }
317 # endif
318
319 // end namespace itk
320
321 #endif
322 #endif // itk_emulation_hash_set_h
323

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:55PM
© Kitware Inc.