32 #ifndef PXR_BASE_TF_HASHMAP_H 33 #define PXR_BASE_TF_HASHMAP_H 36 #include "pxr/base/arch/defines.h" 38 #if defined(ARCH_HAS_GNU_STL_EXTENSIONS) 39 #include <ext/hash_map> 41 #include <unordered_map> 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 Mapped,
class HashFn = __gnu_cxx::hash<Key>,
49 class EqualKey = __gnu_cxx::equal_to<Key>,
50 class Alloc = __gnu_cxx::allocator<Mapped> >
52 private __gnu_cxx::hash_map<Key, Mapped, HashFn, EqualKey, Alloc> {
53 typedef __gnu_cxx::hash_map<Key, Mapped, HashFn, EqualKey, Alloc> _Base;
55 typedef typename _Base::key_type key_type;
56 typedef typename _Base::mapped_type mapped_type;
57 typedef typename _Base::value_type value_type;
58 typedef typename _Base::hasher hasher;
59 typedef typename _Base::key_equal key_equal;
60 typedef typename _Base::size_type size_type;
61 typedef typename _Base::difference_type difference_type;
62 typedef typename _Base::pointer pointer;
63 typedef typename _Base::const_pointer const_pointer;
64 typedef typename _Base::reference reference;
65 typedef typename _Base::const_reference const_reference;
66 typedef typename _Base::iterator iterator;
67 typedef typename _Base::const_iterator const_iterator;
68 typedef typename _Base::allocator_type allocator_type;
71 TfHashMap() : _Base() { }
73 TfHashMap(size_type n,
const hasher& hf = hasher(),
74 const key_equal& eql = key_equal(),
75 const allocator_type& alloc = allocator_type()) :
76 _Base(n, hf, eql, alloc) { }
78 TfHashMap(
const allocator_type& alloc) :
79 _Base(0, hasher(), key_equal(), alloc) { }
80 template<
class InputIterator>
81 TfHashMap(InputIterator first, InputIterator last,
82 size_type n = 0,
const hasher& hf = hasher(),
83 const key_equal& eql = key_equal(),
84 const allocator_type& alloc = allocator_type()) :
85 _Base(first, last, n, hf, eql, alloc) { }
86 TfHashMap(
const TfHashMap& other) : _Base(other) { }
88 TfHashMap& operator=(
const TfHashMap& rhs) {
89 _Base::operator=(rhs);
93 iterator begin() {
return _Base::begin(); }
94 const_iterator begin()
const {
return const_iterator(_Base::begin()); }
96 using _Base::bucket_count;
97 size_type bucket_size(size_type n)
const {
return _Base::elems_in_bucket(n); }
98 const_iterator cbegin()
const {
return const_iterator(_Base::begin()); }
99 const_iterator cend()
const {
return const_iterator(_Base::end()); }
103 iterator end() {
return _Base::end(); }
104 const_iterator end()
const {
return const_iterator(_Base::end()); }
105 std::pair<iterator,iterator> equal_range(
const key_type& key) {
106 return _Base::equal_range(key);
108 std::pair<const_iterator,const_iterator> equal_range(
const key_type& key)
const {
109 return _Base::equal_range(key);
111 size_type erase(
const key_type& key) {
return _Base::erase(key); }
112 void erase(const_iterator position) {
113 _Base::erase(_MakeIterator(position));
115 void erase(const_iterator first, const_iterator last) {
116 _Base::erase(_MakeIterator(first), _MakeIterator(last));
118 iterator find(
const key_type& key) {
return _Base::find(key); }
119 const_iterator find(
const key_type& key)
const {
120 return const_iterator(_Base::find(key));
122 using _Base::get_allocator;
123 hasher hash_function()
const {
return _Base::hash_funct(); }
125 iterator insert(const_iterator,
const value_type& v) {
126 return insert(v).first;
129 float load_factor()
const {
130 return static_cast<float>(static_cast<double>(size()) / bucket_count());
132 using _Base::max_bucket_count;
133 float max_load_factor()
const {
return 1.0; }
135 using _Base::max_size;
136 void rehash(size_type n) { _Base::resize(__gnu_cxx::__stl_next_prime(n)); }
137 void reserve(size_type n) { _Base::resize(n); }
140 mapped_type& operator[](
const key_type& k) {
return _Base::operator[](k); }
142 template<
class Key2,
class Mapped2,
class HashFn2,
class EqualKey2,
class Alloc2>
144 operator==(
const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&,
145 const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&);
150 static const iterator& _MakeIterator(
const const_iterator& i) {
151 return reinterpret_cast<const iterator&>(i);
155 template<
class Key,
class Mapped,
class HashFn = __gnu_cxx::hash<Key>,
156 class EqualKey = __gnu_cxx::equal_to<Key>,
157 class Alloc = __gnu_cxx::allocator<Mapped> >
158 class TfHashMultiMap :
159 private __gnu_cxx::hash_multimap<Key, Mapped, HashFn, EqualKey, Alloc> {
160 typedef __gnu_cxx::hash_multimap<Key, Mapped, HashFn, EqualKey, Alloc> _Base;
162 typedef typename _Base::key_type key_type;
163 typedef typename _Base::mapped_type mapped_type;
164 typedef typename _Base::value_type value_type;
165 typedef typename _Base::hasher hasher;
166 typedef typename _Base::key_equal key_equal;
167 typedef typename _Base::size_type size_type;
168 typedef typename _Base::difference_type difference_type;
169 typedef typename _Base::pointer pointer;
170 typedef typename _Base::const_pointer const_pointer;
171 typedef typename _Base::reference reference;
172 typedef typename _Base::const_reference const_reference;
173 typedef typename _Base::iterator iterator;
174 typedef typename _Base::const_iterator const_iterator;
175 typedef typename _Base::allocator_type allocator_type;
178 TfHashMultiMap() : _Base() { }
180 TfHashMultiMap(size_type n,
const hasher& hf = hasher(),
181 const key_equal& eql = key_equal(),
182 const allocator_type& alloc = allocator_type()) :
183 _Base(n, hf, eql, alloc) { }
185 TfHashMultiMap(
const allocator_type& alloc) :
186 _Base(0, hasher(), key_equal(), alloc) { }
187 template<
class InputIterator>
188 TfHashMultiMap(InputIterator first, InputIterator last,
189 size_type n = 0,
const hasher& hf = hasher(),
190 const key_equal& eql = key_equal(),
191 const allocator_type& alloc = allocator_type()) :
192 _Base(first, last, n, hf, eql, alloc) { }
193 TfHashMultiMap(
const TfHashMultiMap& other) : _Base(other) { }
195 TfHashMultiMap& operator=(
const TfHashMultiMap& rhs) {
196 _Base::operator=(rhs);
200 iterator begin() {
return _Base::begin(); }
201 const_iterator begin()
const {
return const_iterator(_Base::begin()); }
203 using _Base::bucket_count;
204 size_type bucket_size(size_type n)
const {
return _Base::elems_in_bucket(n); }
205 const_iterator cbegin()
const {
return const_iterator(_Base::begin()); }
206 const_iterator cend()
const {
return const_iterator(_Base::end()); }
210 iterator end() {
return _Base::end(); }
211 const_iterator end()
const {
return const_iterator(_Base::end()); }
212 std::pair<iterator,iterator> equal_range(
const key_type& key) {
213 return _Base::equal_range(key);
215 std::pair<const_iterator,const_iterator> equal_range(
const key_type& key)
const {
216 return _Base::equal_range(key);
218 size_type erase(
const key_type& key) {
return _Base::erase(key); }
219 void erase(const_iterator position) {
220 _Base::erase(_MakeIterator(position));
222 void erase(const_iterator first, const_iterator last) {
223 _Base::erase(_MakeIterator(first), _MakeIterator(last));
225 iterator find(
const key_type& key) {
return _Base::find(key); }
226 const_iterator find(
const key_type& key)
const {
227 return const_iterator(_Base::find(key));
229 using _Base::get_allocator;
230 hasher hash_function()
const {
return _Base::hash_funct(); }
232 iterator insert(const_iterator,
const value_type& v) {
233 return insert(v).first;
236 float load_factor()
const {
237 return static_cast<float>(static_cast<double>(size()) / bucket_count());
239 using _Base::max_bucket_count;
240 float max_load_factor()
const {
return 1.0; }
242 using _Base::max_size;
243 void rehash(size_type n) { _Base::resize(__gnu_cxx::__stl_next_prime(n)); }
244 void reserve(size_type n) { _Base::resize(n); }
247 mapped_type& operator[](
const key_type& k) {
return _Base::operator[](k); }
249 template<
class Key2,
class Mapped2,
class HashFn2,
class EqualKey2,
class Alloc2>
251 operator==(
const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&,
252 const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&);
257 static const iterator& _MakeIterator(
const const_iterator& i) {
258 return reinterpret_cast<const iterator&>(i);
264 template<
class Key,
class Mapped,
class HashFn = std::hash<Key>,
265 class EqualKey = std::equal_to<Key>,
266 class Alloc = std::allocator<std::pair<const Key, Mapped> > >
268 private std::unordered_map<Key, Mapped, HashFn, EqualKey, Alloc> {
269 typedef std::unordered_map<Key, Mapped, HashFn, EqualKey, Alloc> _Base;
271 typedef typename _Base::key_type key_type;
272 typedef typename _Base::mapped_type mapped_type;
273 typedef typename _Base::value_type value_type;
274 typedef typename _Base::hasher hasher;
275 typedef typename _Base::key_equal key_equal;
276 typedef typename _Base::size_type size_type;
277 typedef typename _Base::difference_type difference_type;
278 typedef typename _Base::pointer pointer;
279 typedef typename _Base::const_pointer const_pointer;
280 typedef typename _Base::reference reference;
281 typedef typename _Base::const_reference const_reference;
282 typedef typename _Base::iterator iterator;
283 typedef typename _Base::const_iterator const_iterator;
284 typedef typename _Base::allocator_type allocator_type;
287 TfHashMap() : _Base() { }
289 TfHashMap(size_type n,
const hasher& hf = hasher(),
290 const key_equal& eql = key_equal(),
291 const allocator_type& alloc = allocator_type()) :
292 _Base(n, hf, eql, alloc) { }
294 TfHashMap(
const allocator_type& alloc) : _Base(alloc) { }
295 template<
class InputIterator>
296 TfHashMap(InputIterator first, InputIterator last,
297 size_type n = 0,
const hasher& hf = hasher(),
298 const key_equal& eql = key_equal(),
299 const allocator_type& alloc = allocator_type()) :
300 _Base(first, last, n, hf, eql, alloc) { }
301 TfHashMap(
const TfHashMap& other) : _Base(other) { }
303 TfHashMap& operator=(
const TfHashMap& rhs) {
304 _Base::operator=(rhs);
308 iterator begin() {
return _Base::begin(); }
309 const_iterator begin()
const {
return _Base::begin(); }
311 using _Base::bucket_count;
312 using _Base::bucket_size;
313 const_iterator cbegin()
const {
return _Base::cbegin(); }
314 const_iterator cend()
const {
return _Base::cend(); }
318 iterator end() {
return _Base::end(); }
319 const_iterator end()
const {
return _Base::end(); }
320 using _Base::equal_range;
321 size_type erase(
const key_type& key) {
return _Base::erase(key); }
322 void erase(const_iterator position) { _Base::erase(position); }
323 void erase(const_iterator first, const_iterator last) {
324 _Base::erase(first, last);
327 using _Base::get_allocator;
328 using _Base::hash_function;
329 std::pair<iterator, bool> insert(
const value_type& v) {
330 return _Base::insert(v);
332 iterator insert(const_iterator hint,
const value_type& v) {
333 return _Base::insert(hint, v);
335 template<
class InputIterator>
336 void insert(InputIterator first, InputIterator last) {
337 _Base::insert(first, last);
340 using _Base::load_factor;
341 using _Base::max_bucket_count;
342 using _Base::max_load_factor;
344 using _Base::max_size;
346 using _Base::reserve;
349 mapped_type& operator[](
const key_type& k) {
return _Base::operator[](k); }
351 template<
class Key2,
class Mapped2,
class HashFn2,
class EqualKey2,
class Alloc2>
353 operator==(
const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&,
354 const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&);
357 template<
class Key,
class Mapped,
class HashFn = std::hash<Key>,
358 class EqualKey = std::equal_to<Key>,
359 class Alloc = std::allocator<std::pair<const Key, Mapped> > >
360 class TfHashMultiMap :
361 private std::unordered_multimap<Key, Mapped, HashFn, EqualKey, Alloc> {
362 typedef std::unordered_multimap<Key, Mapped, HashFn, EqualKey, Alloc> _Base;
364 typedef typename _Base::key_type key_type;
365 typedef typename _Base::mapped_type mapped_type;
366 typedef typename _Base::value_type value_type;
367 typedef typename _Base::hasher hasher;
368 typedef typename _Base::key_equal key_equal;
369 typedef typename _Base::size_type size_type;
370 typedef typename _Base::difference_type difference_type;
371 typedef typename _Base::pointer pointer;
372 typedef typename _Base::const_pointer const_pointer;
373 typedef typename _Base::reference reference;
374 typedef typename _Base::const_reference const_reference;
375 typedef typename _Base::iterator iterator;
376 typedef typename _Base::const_iterator const_iterator;
377 typedef typename _Base::allocator_type allocator_type;
380 TfHashMultiMap() : _Base() { }
382 TfHashMultiMap(size_type n,
const hasher& hf = hasher(),
383 const key_equal& eql = key_equal(),
384 const allocator_type& alloc = allocator_type()) :
385 _Base(n, hf, eql, alloc) { }
387 TfHashMultiMap(
const allocator_type& alloc) : _Base(alloc) { }
388 template<
class InputIterator>
389 TfHashMultiMap(InputIterator first, InputIterator last,
390 size_type n = 0,
const hasher& hf = hasher(),
391 const key_equal& eql = key_equal(),
392 const allocator_type& alloc = allocator_type()) :
393 _Base(first, last, n, hf, eql, alloc) { }
394 TfHashMultiMap(
const TfHashMultiMap& other) : _Base(other) { }
396 TfHashMultiMap& operator=(
const TfHashMultiMap& rhs) {
397 _Base::operator=(rhs);
401 iterator begin() {
return _Base::begin(); }
402 const_iterator begin()
const {
return _Base::begin(); }
404 using _Base::bucket_count;
405 using _Base::bucket_size;
406 const_iterator cbegin()
const {
return _Base::cbegin(); }
407 const_iterator cend()
const {
return _Base::cend(); }
411 iterator end() {
return _Base::end(); }
412 const_iterator end()
const {
return _Base::end(); }
413 using _Base::equal_range;
414 size_type erase(
const key_type& key) {
return _Base::erase(key); }
415 void erase(const_iterator position) { _Base::erase(position); }
416 void erase(const_iterator first, const_iterator last) {
417 _Base::erase(first, last);
420 using _Base::get_allocator;
421 using _Base::hash_function;
422 iterator insert(
const value_type& v) {
423 return _Base::insert(v);
425 iterator insert(const_iterator hint,
const value_type& v) {
426 return _Base::insert(hint, v);
428 template<
class InputIterator>
429 void insert(InputIterator first, InputIterator last) {
430 _Base::insert(first, last);
433 using _Base::load_factor;
434 using _Base::max_bucket_count;
435 using _Base::max_load_factor;
437 using _Base::max_size;
439 using _Base::reserve;
442 mapped_type& operator[](
const key_type& k) {
return _Base::operator[](k); }
444 template<
class Key2,
class Mapped2,
class HashFn2,
class EqualKey2,
class Alloc2>
446 operator==(
const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&,
447 const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&);
450 #endif // ARCH_HAS_GNU_STL_EXTENSIONS 452 template<
class Key,
class Mapped,
class HashFn,
class EqualKey,
class Alloc>
454 swap(TfHashMap<Key, Mapped, HashFn, EqualKey, Alloc>& lhs,
455 TfHashMap<Key, Mapped, HashFn, EqualKey, Alloc>& rhs)
460 template<
class Key,
class Mapped,
class HashFn,
class EqualKey,
class Alloc>
462 operator==(
const TfHashMap<Key, Mapped, HashFn, EqualKey, Alloc>& lhs,
463 const TfHashMap<Key, Mapped, HashFn, EqualKey, Alloc>& rhs)
465 typedef typename TfHashMap<Key, Mapped, HashFn, EqualKey, Alloc>::_Base _Base;
466 return static_cast<const _Base&>(lhs) == static_cast<const _Base&>(rhs);
469 template<
class Key,
class Mapped,
class HashFn,
class EqualKey,
class Alloc>
471 operator!=(
const TfHashMap<Key, Mapped, HashFn, EqualKey, Alloc>& lhs,
472 const TfHashMap<Key, Mapped, HashFn, EqualKey, Alloc>& rhs)
474 return !(lhs == rhs);
477 template<
class Key,
class Mapped,
class HashFn,
class EqualKey,
class Alloc>
479 swap(TfHashMultiMap<Key, Mapped, HashFn, EqualKey, Alloc>& lhs,
480 TfHashMultiMap<Key, Mapped, HashFn, EqualKey, Alloc>& rhs)
485 template<
class Key,
class Mapped,
class HashFn,
class EqualKey,
class Alloc>
487 operator==(
const TfHashMultiMap<Key, Mapped, HashFn, EqualKey, Alloc>& lhs,
488 const TfHashMultiMap<Key, Mapped, HashFn, EqualKey, Alloc>& rhs)
490 typedef typename TfHashMultiMap<Key, Mapped, HashFn, EqualKey, Alloc>::_Base _Base;
491 return static_cast<const _Base&>(lhs) == static_cast<const _Base&>(rhs);
494 template<
class Key,
class Mapped,
class HashFn,
class EqualKey,
class Alloc>
496 operator!=(
const TfHashMultiMap<Key, Mapped, HashFn, EqualKey, Alloc>& lhs,
497 const TfHashMultiMap<Key, Mapped, HashFn, EqualKey, Alloc>& rhs)
499 return !(lhs == rhs);
502 PXR_NAMESPACE_CLOSE_SCOPE
504 #endif // PXR_BASE_TF_HASHMAP_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.