32 #ifndef PXR_BASE_TF_HASHSET_H 33 #define PXR_BASE_TF_HASHSET_H 36 #include "pxr/base/arch/defines.h" 38 #if defined(ARCH_HAS_GNU_STL_EXTENSIONS) 39 #include <ext/hash_set> 41 #include <unordered_set> 42 #endif // ARCH_HAS_GNU_STL_EXTENSIONS 44 PXR_NAMESPACE_OPEN_SCOPE
46 #if defined(ARCH_HAS_GNU_STL_EXTENSIONS) 48 template<
class Key,
class HashFn = __gnu_cxx::hash<Key>,
49 class EqualKey = __gnu_cxx::equal_to<Key>,
50 class Alloc = __gnu_cxx::allocator<Key> >
52 private __gnu_cxx::hash_set<Key, HashFn, EqualKey, Alloc> {
53 typedef __gnu_cxx::hash_set<Key, HashFn, EqualKey, Alloc> _Base;
55 typedef typename _Base::key_type key_type;
56 typedef typename _Base::value_type value_type;
57 typedef typename _Base::hasher hasher;
58 typedef typename _Base::key_equal key_equal;
59 typedef typename _Base::size_type size_type;
60 typedef typename _Base::difference_type difference_type;
61 typedef typename _Base::pointer pointer;
62 typedef typename _Base::const_pointer const_pointer;
63 typedef typename _Base::reference reference;
64 typedef typename _Base::const_reference const_reference;
65 typedef typename _Base::iterator iterator;
66 typedef typename _Base::const_iterator const_iterator;
67 typedef typename _Base::allocator_type allocator_type;
70 TfHashSet() : _Base() { }
72 TfHashSet(size_type n,
const hasher& hf = hasher(),
73 const key_equal& eql = key_equal(),
74 const allocator_type& alloc = allocator_type()) :
75 _Base(n, hf, eql, alloc) { }
77 TfHashSet(
const allocator_type& alloc) :
78 _Base(0, hasher(), key_equal(), alloc) { }
79 template<
class InputIterator>
80 TfHashSet(InputIterator first, InputIterator last,
81 size_type n = 0,
const hasher& hf = hasher(),
82 const key_equal& eql = key_equal(),
83 const allocator_type& alloc = allocator_type()) :
84 _Base(first, last, n, hf, eql, alloc) { }
85 TfHashSet(
const TfHashSet& other) : _Base(other) { }
87 TfHashSet& operator=(
const TfHashSet& rhs) {
88 _Base::operator=(rhs);
92 iterator begin() {
return _Base::begin(); }
93 const_iterator begin()
const {
return const_iterator(_Base::begin()); }
95 using _Base::bucket_count;
96 size_type bucket_size(size_type n)
const {
return _Base::elems_in_bucket(n); }
97 const_iterator cbegin()
const {
return const_iterator(_Base::begin()); }
98 const_iterator cend()
const {
return const_iterator(_Base::end()); }
102 iterator end() {
return _Base::end(); }
103 const_iterator end()
const {
return const_iterator(_Base::end()); }
104 std::pair<iterator,iterator> equal_range(
const key_type& key) {
105 return _Base::equal_range(key);
107 std::pair<const_iterator,const_iterator> equal_range(
const key_type& key)
const {
108 return _Base::equal_range(key);
110 size_type erase(
const key_type& key) {
return _Base::erase(key); }
111 void erase(const_iterator position) {
112 _Base::erase(_MakeIterator(position));
114 void erase(const_iterator first, const_iterator last) {
115 _Base::erase(_MakeIterator(first), _MakeIterator(last));
117 iterator find(
const key_type& key) {
return _Base::find(key); }
118 const_iterator find(
const key_type& key)
const {
119 return const_iterator(_Base::find(key));
121 using _Base::get_allocator;
122 hasher hash_function()
const {
return _Base::hash_funct(); }
124 iterator insert(const_iterator,
const value_type& v) {
125 return insert(v).first;
128 float load_factor()
const {
129 return static_cast<float>(static_cast<double>(size()) / bucket_count());
131 using _Base::max_bucket_count;
132 float max_load_factor()
const {
return 1.0; }
134 using _Base::max_size;
135 void rehash(size_type n) { _Base::resize(__gnu_cxx::__stl_next_prime(n)); }
136 void reserve(size_type n) { _Base::resize(n); }
140 template<
class Key2,
class HashFn2,
class EqualKey2,
class Alloc2>
142 operator==(
const TfHashSet<Key2, HashFn2, EqualKey2, Alloc2>&,
143 const TfHashSet<Key2, HashFn2, EqualKey2, Alloc2>&);
148 static const iterator& _MakeIterator(
const const_iterator& i) {
149 return reinterpret_cast<const iterator&>(i);
153 template<
class Key,
class HashFn = __gnu_cxx::hash<Key>,
154 class EqualKey = __gnu_cxx::equal_to<Key>,
155 class Alloc = __gnu_cxx::allocator<Key> >
156 class TfHashMultiSet :
157 private __gnu_cxx::hash_multiset<Key, HashFn, EqualKey, Alloc> {
158 typedef __gnu_cxx::hash_multiset<Key, HashFn, EqualKey, Alloc> _Base;
160 typedef typename _Base::key_type key_type;
161 typedef typename _Base::value_type value_type;
162 typedef typename _Base::hasher hasher;
163 typedef typename _Base::key_equal key_equal;
164 typedef typename _Base::size_type size_type;
165 typedef typename _Base::difference_type difference_type;
166 typedef typename _Base::pointer pointer;
167 typedef typename _Base::const_pointer const_pointer;
168 typedef typename _Base::reference reference;
169 typedef typename _Base::const_reference const_reference;
170 typedef typename _Base::iterator iterator;
171 typedef typename _Base::const_iterator const_iterator;
172 typedef typename _Base::allocator_type allocator_type;
175 TfHashMultiSet() : _Base() { }
177 TfHashMultiSet(size_type n,
const hasher& hf = hasher(),
178 const key_equal& eql = key_equal(),
179 const allocator_type& alloc = allocator_type()) :
180 _Base(n, hf, eql, alloc) { }
182 TfHashMultiSet(
const allocator_type& alloc) :
183 _Base(0, hasher(), key_equal(), alloc) { }
184 template<
class InputIterator>
185 TfHashMultiSet(InputIterator first, InputIterator last,
186 size_type n = 0,
const hasher& hf = hasher(),
187 const key_equal& eql = key_equal(),
188 const allocator_type& alloc = allocator_type()) :
189 _Base(first, last, n, hf, eql, alloc) { }
190 TfHashMultiSet(
const TfHashMultiSet& other) : _Base(other) { }
192 TfHashMultiSet& operator=(
const TfHashMultiSet& rhs) {
193 _Base::operator=(rhs);
197 iterator begin() {
return _Base::begin(); }
198 const_iterator begin()
const {
return const_iterator(_Base::begin()); }
200 using _Base::bucket_count;
201 size_type bucket_size(size_type n)
const {
return _Base::elems_in_bucket(n); }
202 const_iterator cbegin()
const {
return const_iterator(_Base::begin()); }
203 const_iterator cend()
const {
return const_iterator(_Base::end()); }
207 iterator end() {
return _Base::end(); }
208 const_iterator end()
const {
return const_iterator(_Base::end()); }
209 std::pair<iterator,iterator> equal_range(
const key_type& key) {
210 return _Base::equal_range(key);
212 std::pair<const_iterator,const_iterator> equal_range(
const key_type& key)
const {
213 return _Base::equal_range(key);
215 size_type erase(
const key_type& key) {
return _Base::erase(key); }
216 void erase(const_iterator position) {
217 _Base::erase(_MakeIterator(position));
219 void erase(const_iterator first, const_iterator last) {
220 _Base::erase(_MakeIterator(first), _MakeIterator(last));
222 iterator find(
const key_type& key) {
return _Base::find(key); }
223 const_iterator find(
const key_type& key)
const {
224 return const_iterator(_Base::find(key));
226 using _Base::get_allocator;
227 hasher hash_function()
const {
return _Base::hash_funct(); }
229 iterator insert(const_iterator,
const value_type& v) {
230 return insert(v).first;
233 float load_factor()
const {
234 return static_cast<float>(static_cast<double>(size()) / bucket_count());
236 using _Base::max_bucket_count;
237 float max_load_factor()
const {
return 1.0; }
239 using _Base::max_size;
240 void rehash(size_type n) { _Base::resize(__gnu_cxx::__stl_next_prime(n)); }
241 void reserve(size_type n) { _Base::resize(n); }
245 template<
class Key2,
class HashFn2,
class EqualKey2,
class Alloc2>
247 operator==(
const TfHashMultiSet<Key2, HashFn2, EqualKey2, Alloc2>&,
248 const TfHashMultiSet<Key2, HashFn2, EqualKey2, Alloc2>&);
253 static const iterator& _MakeIterator(
const const_iterator& i) {
254 return reinterpret_cast<const iterator&>(i);
260 template<
class Key,
class HashFn = std::hash<Key>,
261 class EqualKey = std::equal_to<Key>,
262 class Alloc = std::allocator<Key> >
264 private std::unordered_set<Key, HashFn, EqualKey, Alloc> {
265 typedef std::unordered_set<Key, HashFn, EqualKey, Alloc> _Base;
267 typedef typename _Base::key_type key_type;
268 typedef typename _Base::value_type value_type;
269 typedef typename _Base::hasher hasher;
270 typedef typename _Base::key_equal key_equal;
271 typedef typename _Base::size_type size_type;
272 typedef typename _Base::difference_type difference_type;
273 typedef typename _Base::pointer pointer;
274 typedef typename _Base::const_pointer const_pointer;
275 typedef typename _Base::reference reference;
276 typedef typename _Base::const_reference const_reference;
277 typedef typename _Base::iterator iterator;
278 typedef typename _Base::const_iterator const_iterator;
279 typedef typename _Base::allocator_type allocator_type;
282 TfHashSet() : _Base() { }
284 TfHashSet(size_type n,
const hasher& hf = hasher(),
285 const key_equal& eql = key_equal(),
286 const allocator_type& alloc = allocator_type()) :
287 _Base(n, hf, eql, alloc) { }
289 TfHashSet(
const allocator_type& alloc) : _Base(alloc) { }
290 template<
class InputIterator>
291 TfHashSet(InputIterator first, InputIterator last,
292 size_type n = 0,
const hasher& hf = hasher(),
293 const key_equal& eql = key_equal(),
294 const allocator_type& alloc = allocator_type()) :
295 _Base(first, last, n, hf, eql, alloc) { }
296 TfHashSet(
const TfHashSet& other) : _Base(other) { }
298 TfHashSet& operator=(
const TfHashSet& rhs) {
299 _Base::operator=(rhs);
303 iterator begin() {
return _Base::begin(); }
304 const_iterator begin()
const {
return _Base::begin(); }
306 using _Base::bucket_count;
307 using _Base::bucket_size;
308 const_iterator cbegin()
const {
return _Base::cbegin(); }
309 const_iterator cend()
const {
return _Base::cend(); }
313 iterator end() {
return _Base::end(); }
314 const_iterator end()
const {
return _Base::end(); }
315 using _Base::equal_range;
316 size_type erase(
const key_type& key) {
return _Base::erase(key); }
317 void erase(const_iterator position) { _Base::erase(position); }
318 void erase(const_iterator first, const_iterator last) {
319 _Base::erase(first, last);
322 using _Base::get_allocator;
323 using _Base::hash_function;
324 std::pair<iterator, bool> insert(
const value_type& v) {
325 return _Base::insert(v);
327 iterator insert(const_iterator hint,
const value_type& v) {
328 return _Base::insert(hint, v);
330 template<
class InputIterator>
331 void insert(InputIterator first, InputIterator last) {
332 _Base::insert(first, last);
335 using _Base::load_factor;
336 using _Base::max_bucket_count;
337 using _Base::max_load_factor;
339 using _Base::max_size;
341 using _Base::reserve;
345 template<
class Key2,
class HashFn2,
class EqualKey2,
class Alloc2>
347 operator==(
const TfHashSet<Key2, HashFn2, EqualKey2, Alloc2>&,
348 const TfHashSet<Key2, HashFn2, EqualKey2, Alloc2>&);
351 template<
class Key,
class HashFn = std::hash<Key>,
352 class EqualKey = std::equal_to<Key>,
353 class Alloc = std::allocator<Key> >
354 class TfHashMultiSet :
355 private std::unordered_multiset<Key, HashFn, EqualKey, Alloc> {
356 typedef std::unordered_multiset<Key, HashFn, EqualKey, Alloc> _Base;
358 typedef typename _Base::key_type key_type;
359 typedef typename _Base::value_type value_type;
360 typedef typename _Base::hasher hasher;
361 typedef typename _Base::key_equal key_equal;
362 typedef typename _Base::size_type size_type;
363 typedef typename _Base::difference_type difference_type;
364 typedef typename _Base::pointer pointer;
365 typedef typename _Base::const_pointer const_pointer;
366 typedef typename _Base::reference reference;
367 typedef typename _Base::const_reference const_reference;
368 typedef typename _Base::iterator iterator;
369 typedef typename _Base::const_iterator const_iterator;
370 typedef typename _Base::allocator_type allocator_type;
373 TfHashMultiSet() : _Base() { }
375 TfHashMultiSet(size_type n,
const hasher& hf = hasher(),
376 const key_equal& eql = key_equal(),
377 const allocator_type& alloc = allocator_type()) :
378 _Base(n, hf, eql, alloc) { }
380 TfHashMultiSet(
const allocator_type& alloc) : _Base(alloc) { }
381 template<
class InputIterator>
382 TfHashMultiSet(InputIterator first, InputIterator last,
383 size_type n = 0,
const hasher& hf = hasher(),
384 const key_equal& eql = key_equal(),
385 const allocator_type& alloc = allocator_type()) :
386 _Base(first, last, n, hf, eql, alloc) { }
387 TfHashMultiSet(
const TfHashMultiSet& other) : _Base(other) { }
389 TfHashMultiSet& operator=(
const TfHashMultiSet& rhs) {
390 _Base::operator=(rhs);
394 iterator begin() {
return _Base::begin(); }
395 const_iterator begin()
const {
return _Base::begin(); }
397 using _Base::bucket_count;
398 using _Base::bucket_size;
399 const_iterator cbegin()
const {
return _Base::cbegin(); }
400 const_iterator cend()
const {
return _Base::cend(); }
404 iterator end() {
return _Base::end(); }
405 const_iterator end()
const {
return _Base::end(); }
406 using _Base::equal_range;
407 size_type erase(
const key_type& key) {
return _Base::erase(key); }
408 void erase(const_iterator position) { _Base::erase(position); }
409 void erase(const_iterator first, const_iterator last) {
410 _Base::erase(first, last);
413 using _Base::get_allocator;
414 using _Base::hash_function;
415 iterator insert(
const value_type& v) {
416 return _Base::insert(v);
418 iterator insert(const_iterator hint,
const value_type& v) {
419 return _Base::insert(hint, v);
421 template<
class InputIterator>
422 void insert(InputIterator first, InputIterator last) {
423 _Base::insert(first, last);
426 using _Base::load_factor;
427 using _Base::max_bucket_count;
428 using _Base::max_load_factor;
430 using _Base::max_size;
432 using _Base::reserve;
436 template<
class Key2,
class HashFn2,
class EqualKey2,
class Alloc2>
438 operator==(
const TfHashMultiSet<Key2, HashFn2, EqualKey2, Alloc2>&,
439 const TfHashMultiSet<Key2, HashFn2, EqualKey2, Alloc2>&);
442 #endif // ARCH_HAS_GNU_STL_EXTENSIONS 444 template<
class Key,
class HashFn,
class EqualKey,
class Alloc>
446 swap(TfHashSet<Key, HashFn, EqualKey, Alloc>& lhs,
447 TfHashSet<Key, HashFn, EqualKey, Alloc>& rhs)
452 template<
class Key,
class HashFn,
class EqualKey,
class Alloc>
454 operator==(
const TfHashSet<Key, HashFn, EqualKey, Alloc>& lhs,
455 const TfHashSet<Key, HashFn, EqualKey, Alloc>& rhs)
457 typedef typename TfHashSet<Key, HashFn, EqualKey, Alloc>::_Base _Base;
458 return static_cast<const _Base&>(lhs) == static_cast<const _Base&>(rhs);
461 template<
class Key,
class HashFn,
class EqualKey,
class Alloc>
463 operator!=(
const TfHashSet<Key, HashFn, EqualKey, Alloc>& lhs,
464 const TfHashSet<Key, HashFn, EqualKey, Alloc>& rhs)
466 return !(lhs == rhs);
469 template<
class Key,
class HashFn,
class EqualKey,
class Alloc>
471 swap(TfHashMultiSet<Key, HashFn, EqualKey, Alloc>& lhs,
472 TfHashMultiSet<Key, HashFn, EqualKey, Alloc>& rhs)
477 template<
class Key,
class HashFn,
class EqualKey,
class Alloc>
479 operator==(
const TfHashMultiSet<Key, HashFn, EqualKey, Alloc>& lhs,
480 const TfHashMultiSet<Key, HashFn, EqualKey, Alloc>& rhs)
482 typedef typename TfHashMultiSet<Key, HashFn, EqualKey, Alloc>::_Base _Base;
483 return static_cast<const _Base&>(lhs) == static_cast<const _Base&>(rhs);
486 template<
class Key,
class HashFn,
class EqualKey,
class Alloc>
488 operator!=(
const TfHashMultiSet<Key, HashFn, EqualKey, Alloc>& lhs,
489 const TfHashMultiSet<Key, HashFn, EqualKey, Alloc>& rhs)
491 return !(lhs == rhs);
494 PXR_NAMESPACE_CLOSE_SCOPE
496 #endif // PXR_BASE_TF_HASHSET_H void swap(ArAssetInfo &lhs, ArAssetInfo &rhs)
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
void swap(UsdStageLoadRules &l, UsdStageLoadRules &r)
Swap the contents of rules l and r.
VT_API bool operator==(VtDictionary const &, VtDictionary const &)
Equality comparison.