codekingpro/portable-devtools
114k
1// -*- C++ -*-2//===-------------------------- hash_map ----------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX_HASH_MAP11#define _LIBCUDACXX_HASH_MAP12 13/*14 15 hash_map synopsis16 17namespace __gnu_cxx18{19 20template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,21 class Alloc = allocator<pair<const Key, T>>>22class hash_map23{24public:25 // types26 typedef Key key_type;27 typedef T mapped_type;28 typedef Hash hasher;29 typedef Pred key_equal;30 typedef Alloc allocator_type;31 typedef pair<const key_type, mapped_type> value_type;32 typedef value_type& reference;33 typedef const value_type& const_reference;34 typedef typename allocator_traits<allocator_type>::pointer pointer;35 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;36 typedef typename allocator_traits<allocator_type>::size_type size_type;37 typedef typename allocator_traits<allocator_type>::difference_type difference_type;38 39 typedef /unspecified/ iterator;40 typedef /unspecified/ const_iterator;41 42 hash_map();43 explicit hash_map(size_type n, const hasher& hf = hasher(),44 const key_equal& eql = key_equal(),45 const allocator_type& a = allocator_type());46 template <class InputIterator>47 hash_map(InputIterator f, InputIterator l);48 template <class InputIterator>49 hash_map(InputIterator f, InputIterator l,50 size_type n, const hasher& hf = hasher(),51 const key_equal& eql = key_equal(),52 const allocator_type& a = allocator_type());53 hash_map(const hash_map&);54 ~hash_map();55 hash_map& operator=(const hash_map&);56 57 allocator_type get_allocator() const;58 59 bool empty() const;60 size_type size() const;61 size_type max_size() const;62 63 iterator begin();64 iterator end();65 const_iterator begin() const;66 const_iterator end() const;67 68 pair<iterator, bool> insert(const value_type& obj);69 template <class InputIterator>70 void insert(InputIterator first, InputIterator last);71 72 void erase(const_iterator position);73 size_type erase(const key_type& k);74 void erase(const_iterator first, const_iterator last);75 void clear();76 77 void swap(hash_map&);78 79 hasher hash_funct() const;80 key_equal key_eq() const;81 82 iterator find(const key_type& k);83 const_iterator find(const key_type& k) const;84 size_type count(const key_type& k) const;85 pair<iterator, iterator> equal_range(const key_type& k);86 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;87 88 mapped_type& operator[](const key_type& k);89 90 size_type bucket_count() const;91 size_type max_bucket_count() const;92 93 size_type elems_in_bucket(size_type n) const;94 95 void resize(size_type n);96};97 98template <class Key, class T, class Hash, class Pred, class Alloc>99 void swap(hash_map<Key, T, Hash, Pred, Alloc>& x,100 hash_map<Key, T, Hash, Pred, Alloc>& y);101 102template <class Key, class T, class Hash, class Pred, class Alloc>103 bool104 operator==(const hash_map<Key, T, Hash, Pred, Alloc>& x,105 const hash_map<Key, T, Hash, Pred, Alloc>& y);106 107template <class Key, class T, class Hash, class Pred, class Alloc>108 bool109 operator!=(const hash_map<Key, T, Hash, Pred, Alloc>& x,110 const hash_map<Key, T, Hash, Pred, Alloc>& y);111 112template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,113 class Alloc = allocator<pair<const Key, T>>>114class hash_multimap115{116public:117 // types118 typedef Key key_type;119 typedef T mapped_type;120 typedef Hash hasher;121 typedef Pred key_equal;122 typedef Alloc allocator_type;123 typedef pair<const key_type, mapped_type> value_type;124 typedef value_type& reference;125 typedef const value_type& const_reference;126 typedef typename allocator_traits<allocator_type>::pointer pointer;127 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;128 typedef typename allocator_traits<allocator_type>::size_type size_type;129 typedef typename allocator_traits<allocator_type>::difference_type difference_type;130 131 typedef /unspecified/ iterator;132 typedef /unspecified/ const_iterator;133 134 explicit hash_multimap(size_type n = 193, const hasher& hf = hasher(),135 const key_equal& eql = key_equal(),136 const allocator_type& a = allocator_type());137 template <class InputIterator>138 hash_multimap(InputIterator f, InputIterator l,139 size_type n = 193, const hasher& hf = hasher(),140 const key_equal& eql = key_equal(),141 const allocator_type& a = allocator_type());142 explicit hash_multimap(const allocator_type&);143 hash_multimap(const hash_multimap&);144 ~hash_multimap();145 hash_multimap& operator=(const hash_multimap&);146 147 allocator_type get_allocator() const;148 149 bool empty() const;150 size_type size() const;151 size_type max_size() const;152 153 iterator begin();154 iterator end();155 const_iterator begin() const;156 const_iterator end() const;157 158 iterator insert(const value_type& obj);159 template <class InputIterator>160 void insert(InputIterator first, InputIterator last);161 162 void erase(const_iterator position);163 size_type erase(const key_type& k);164 void erase(const_iterator first, const_iterator last);165 void clear();166 167 void swap(hash_multimap&);168 169 hasher hash_funct() const;170 key_equal key_eq() const;171 172 iterator find(const key_type& k);173 const_iterator find(const key_type& k) const;174 size_type count(const key_type& k) const;175 pair<iterator, iterator> equal_range(const key_type& k);176 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;177 178 size_type bucket_count() const;179 size_type max_bucket_count() const;180 181 size_type elems_in_bucket(size_type n) const;182 183 void resize(size_type n);184};185 186template <class Key, class T, class Hash, class Pred, class Alloc>187 void swap(hash_multimap<Key, T, Hash, Pred, Alloc>& x,188 hash_multimap<Key, T, Hash, Pred, Alloc>& y);189 190template <class Key, class T, class Hash, class Pred, class Alloc>191 bool192 operator==(const hash_multimap<Key, T, Hash, Pred, Alloc>& x,193 const hash_multimap<Key, T, Hash, Pred, Alloc>& y);194 195template <class Key, class T, class Hash, class Pred, class Alloc>196 bool197 operator!=(const hash_multimap<Key, T, Hash, Pred, Alloc>& x,198 const hash_multimap<Key, T, Hash, Pred, Alloc>& y);199 200} // __gnu_cxx201 202*/203 204#include <__config>205#include <__hash_table>206#include <functional>207#include <stdexcept>208#include <type_traits>209#include <ext/__hash>210 211#if __DEPRECATED212#if defined(_LIBCUDACXX_WARNING)213 _LIBCUDACXX_WARNING("Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>")214#else215# warning Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>216#endif217#endif218 219#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)220# pragma GCC system_header221#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)222# pragma clang system_header223#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)224# pragma system_header225#endif // no system header226 227namespace __gnu_cxx {228 229template <class _Tp, class _Hash,230 bool = std::is_empty<_Hash>::value && !std::__libcpp_is_final<_Hash>::value231 >232class __hash_map_hasher233 : private _Hash234{235public:236 _LIBCUDACXX_INLINE_VISIBILITY __hash_map_hasher() : _Hash() {}237 _LIBCUDACXX_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : _Hash(__h) {}238 _LIBCUDACXX_INLINE_VISIBILITY const _Hash& hash_function() const {return *this;}239 _LIBCUDACXX_INLINE_VISIBILITY240 size_t operator()(const _Tp& __x) const241 {return static_cast<const _Hash&>(*this)(__x.first);}242 _LIBCUDACXX_INLINE_VISIBILITY243 size_t operator()(const typename _Tp::first_type& __x) const244 {return static_cast<const _Hash&>(*this)(__x);}245};246 247template <class _Tp, class _Hash>248class __hash_map_hasher<_Tp, _Hash, false>249{250 _Hash __hash_;251public:252 _LIBCUDACXX_INLINE_VISIBILITY __hash_map_hasher() : __hash_() {}253 _LIBCUDACXX_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : __hash_(__h) {}254 _LIBCUDACXX_INLINE_VISIBILITY const _Hash& hash_function() const {return __hash_;}255 _LIBCUDACXX_INLINE_VISIBILITY256 size_t operator()(const _Tp& __x) const257 {return __hash_(__x.first);}258 _LIBCUDACXX_INLINE_VISIBILITY259 size_t operator()(const typename _Tp::first_type& __x) const260 {return __hash_(__x);}261};262 263template <class _Tp, class _Pred,264 bool = std::is_empty<_Pred>::value && !std::__libcpp_is_final<_Pred>::value265 >266class __hash_map_equal267 : private _Pred268{269public:270 _LIBCUDACXX_INLINE_VISIBILITY __hash_map_equal() : _Pred() {}271 _LIBCUDACXX_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : _Pred(__p) {}272 _LIBCUDACXX_INLINE_VISIBILITY const _Pred& key_eq() const {return *this;}273 _LIBCUDACXX_INLINE_VISIBILITY274 bool operator()(const _Tp& __x, const _Tp& __y) const275 {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}276 _LIBCUDACXX_INLINE_VISIBILITY277 bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const278 {return static_cast<const _Pred&>(*this)(__x, __y.first);}279 _LIBCUDACXX_INLINE_VISIBILITY280 bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const281 {return static_cast<const _Pred&>(*this)(__x.first, __y);}282 _LIBCUDACXX_INLINE_VISIBILITY283 bool operator()(const typename _Tp::first_type& __x,284 const typename _Tp::first_type& __y) const285 {return static_cast<const _Pred&>(*this)(__x, __y);}286};287 288template <class _Tp, class _Pred>289class __hash_map_equal<_Tp, _Pred, false>290{291 _Pred __pred_;292public:293 _LIBCUDACXX_INLINE_VISIBILITY __hash_map_equal() : __pred_() {}294 _LIBCUDACXX_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : __pred_(__p) {}295 _LIBCUDACXX_INLINE_VISIBILITY const _Pred& key_eq() const {return __pred_;}296 _LIBCUDACXX_INLINE_VISIBILITY297 bool operator()(const _Tp& __x, const _Tp& __y) const298 {return __pred_(__x.first, __y.first);}299 _LIBCUDACXX_INLINE_VISIBILITY300 bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const301 {return __pred_(__x, __y.first);}302 _LIBCUDACXX_INLINE_VISIBILITY303 bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const304 {return __pred_(__x.first, __y);}305 _LIBCUDACXX_INLINE_VISIBILITY306 bool operator()(const typename _Tp::first_type& __x,307 const typename _Tp::first_type& __y) const308 {return __pred_(__x, __y);}309};310 311template <class _Alloc>312class __hash_map_node_destructor313{314 typedef _Alloc allocator_type;315 typedef std::allocator_traits<allocator_type> __alloc_traits;316 typedef typename __alloc_traits::value_type::__node_value_type value_type;317public:318 typedef typename __alloc_traits::pointer pointer;319private:320 typedef typename value_type::first_type first_type;321 typedef typename value_type::second_type second_type;322 323 allocator_type& __na_;324 325public:326 bool __first_constructed;327 bool __second_constructed;328 329 __hash_map_node_destructor(__hash_map_node_destructor const&) = default;330 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&) = delete;331 332 _LIBCUDACXX_INLINE_VISIBILITY333 explicit __hash_map_node_destructor(allocator_type& __na)334 : __na_(__na),335 __first_constructed(false),336 __second_constructed(false)337 {}338 339 _LIBCUDACXX_INLINE_VISIBILITY340 __hash_map_node_destructor(std::__hash_node_destructor<allocator_type>&& __x)341 : __na_(__x.__na_),342 __first_constructed(__x.__value_constructed),343 __second_constructed(__x.__value_constructed)344 {345 __x.__value_constructed = false;346 }347 348 _LIBCUDACXX_INLINE_VISIBILITY349 void operator()(pointer __p)350 {351 if (__second_constructed)352 __alloc_traits::destroy(__na_, _CUDA_VSTD::addressof(__p->__value_.second));353 if (__first_constructed)354 __alloc_traits::destroy(__na_, _CUDA_VSTD::addressof(__p->__value_.first));355 if (__p)356 __alloc_traits::deallocate(__na_, __p, 1);357 }358};359 360template <class _HashIterator>361class _LIBCUDACXX_TEMPLATE_VIS __hash_map_iterator362{363 _HashIterator __i_;364 365 typedef const typename _HashIterator::value_type::first_type key_type;366 typedef typename _HashIterator::value_type::second_type mapped_type;367public:368 typedef std::forward_iterator_tag iterator_category;369 typedef std::pair<key_type, mapped_type> value_type;370 typedef typename _HashIterator::difference_type difference_type;371 typedef value_type& reference;372 typedef typename std::__rebind_pointer<typename _HashIterator::pointer, value_type>::type373 pointer;374 375 _LIBCUDACXX_INLINE_VISIBILITY __hash_map_iterator() {}376 377 _LIBCUDACXX_INLINE_VISIBILITY __hash_map_iterator(_HashIterator __i) : __i_(__i) {}378 379 _LIBCUDACXX_INLINE_VISIBILITY reference operator*() const {return *operator->();}380 _LIBCUDACXX_INLINE_VISIBILITY pointer operator->() const {return (pointer)__i_.operator->();}381 382 _LIBCUDACXX_INLINE_VISIBILITY __hash_map_iterator& operator++() {++__i_; return *this;}383 _LIBCUDACXX_INLINE_VISIBILITY384 __hash_map_iterator operator++(int)385 {386 __hash_map_iterator __t(*this);387 ++(*this);388 return __t;389 }390 391 friend _LIBCUDACXX_INLINE_VISIBILITY392 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)393 {return __x.__i_ == __y.__i_;}394 friend _LIBCUDACXX_INLINE_VISIBILITY395 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)396 {return __x.__i_ != __y.__i_;}397 398 template <class, class, class, class, class> friend class _LIBCUDACXX_TEMPLATE_VIS hash_map;399 template <class, class, class, class, class> friend class _LIBCUDACXX_TEMPLATE_VIS hash_multimap;400 template <class> friend class _LIBCUDACXX_TEMPLATE_VIS __hash_const_iterator;401 template <class> friend class _LIBCUDACXX_TEMPLATE_VIS __hash_const_local_iterator;402 template <class> friend class _LIBCUDACXX_TEMPLATE_VIS __hash_map_const_iterator;403};404 405template <class _HashIterator>406class _LIBCUDACXX_TEMPLATE_VIS __hash_map_const_iterator407{408 _HashIterator __i_;409 410 typedef const typename _HashIterator::value_type::first_type key_type;411 typedef typename _HashIterator::value_type::second_type mapped_type;412public:413 typedef std::forward_iterator_tag iterator_category;414 typedef std::pair<key_type, mapped_type> value_type;415 typedef typename _HashIterator::difference_type difference_type;416 typedef const value_type& reference;417 typedef typename std::__rebind_pointer<typename _HashIterator::pointer, const value_type>::type418 pointer;419 420 _LIBCUDACXX_INLINE_VISIBILITY __hash_map_const_iterator() {}421 422 _LIBCUDACXX_INLINE_VISIBILITY423 __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {}424 _LIBCUDACXX_INLINE_VISIBILITY425 __hash_map_const_iterator(426 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)427 : __i_(__i.__i_) {}428 429 _LIBCUDACXX_INLINE_VISIBILITY430 reference operator*() const {return *operator->();}431 _LIBCUDACXX_INLINE_VISIBILITY432 pointer operator->() const {return (pointer)__i_.operator->();}433 434 _LIBCUDACXX_INLINE_VISIBILITY435 __hash_map_const_iterator& operator++() {++__i_; return *this;}436 _LIBCUDACXX_INLINE_VISIBILITY437 __hash_map_const_iterator operator++(int)438 {439 __hash_map_const_iterator __t(*this);440 ++(*this);441 return __t;442 }443 444 friend _LIBCUDACXX_INLINE_VISIBILITY445 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)446 {return __x.__i_ == __y.__i_;}447 friend _LIBCUDACXX_INLINE_VISIBILITY448 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)449 {return __x.__i_ != __y.__i_;}450 451 template <class, class, class, class, class> friend class _LIBCUDACXX_TEMPLATE_VIS hash_map;452 template <class, class, class, class, class> friend class _LIBCUDACXX_TEMPLATE_VIS hash_multimap;453 template <class> friend class _LIBCUDACXX_TEMPLATE_VIS __hash_const_iterator;454 template <class> friend class _LIBCUDACXX_TEMPLATE_VIS __hash_const_local_iterator;455};456 457template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = std::equal_to<_Key>,458 class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >459class _LIBCUDACXX_TEMPLATE_VIS hash_map460{461public:462 // types463 typedef _Key key_type;464 typedef _Tp mapped_type;465 typedef _Tp data_type;466 typedef _Hash hasher;467 typedef _Pred key_equal;468 typedef _Alloc allocator_type;469 typedef std::pair<const key_type, mapped_type> value_type;470 typedef value_type& reference;471 typedef const value_type& const_reference;472 473private:474 typedef std::pair<key_type, mapped_type> __value_type;475 typedef __hash_map_hasher<__value_type, hasher> __hasher;476 typedef __hash_map_equal<__value_type, key_equal> __key_equal;477 typedef typename std::__rebind_alloc_helper<478 std::allocator_traits<allocator_type>, __value_type>::type __allocator_type;479 480 typedef std::__hash_table<__value_type, __hasher,481 __key_equal, __allocator_type> __table;482 483 __table __table_;484 485 typedef typename __table::__node_pointer __node_pointer;486 typedef typename __table::__node_const_pointer __node_const_pointer;487 typedef typename __table::__node_traits __node_traits;488 typedef typename __table::__node_allocator __node_allocator;489 typedef typename __table::__node __node;490 typedef __hash_map_node_destructor<__node_allocator> _Dp;491 typedef std::unique_ptr<__node, _Dp> __node_holder;492 typedef std::allocator_traits<allocator_type> __alloc_traits;493public:494 typedef typename __alloc_traits::pointer pointer;495 typedef typename __alloc_traits::const_pointer const_pointer;496 typedef typename __alloc_traits::size_type size_type;497 typedef typename __alloc_traits::difference_type difference_type;498 499 typedef __hash_map_iterator<typename __table::iterator> iterator;500 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;501 502 _LIBCUDACXX_INLINE_VISIBILITY hash_map() { }503 explicit hash_map(size_type __n, const hasher& __hf = hasher(),504 const key_equal& __eql = key_equal());505 hash_map(size_type __n, const hasher& __hf,506 const key_equal& __eql,507 const allocator_type& __a);508 template <class _InputIterator>509 hash_map(_InputIterator __first, _InputIterator __last);510 template <class _InputIterator>511 hash_map(_InputIterator __first, _InputIterator __last,512 size_type __n, const hasher& __hf = hasher(),513 const key_equal& __eql = key_equal());514 template <class _InputIterator>515 hash_map(_InputIterator __first, _InputIterator __last,516 size_type __n, const hasher& __hf,517 const key_equal& __eql,518 const allocator_type& __a);519 hash_map(const hash_map& __u);520 521 _LIBCUDACXX_INLINE_VISIBILITY522 allocator_type get_allocator() const523 {return allocator_type(__table_.__node_alloc());}524 525 _LIBCUDACXX_INLINE_VISIBILITY526 bool empty() const {return __table_.size() == 0;}527 _LIBCUDACXX_INLINE_VISIBILITY528 size_type size() const {return __table_.size();}529 _LIBCUDACXX_INLINE_VISIBILITY530 size_type max_size() const {return __table_.max_size();}531 532 _LIBCUDACXX_INLINE_VISIBILITY533 iterator begin() {return __table_.begin();}534 _LIBCUDACXX_INLINE_VISIBILITY535 iterator end() {return __table_.end();}536 _LIBCUDACXX_INLINE_VISIBILITY537 const_iterator begin() const {return __table_.begin();}538 _LIBCUDACXX_INLINE_VISIBILITY539 const_iterator end() const {return __table_.end();}540 541 _LIBCUDACXX_INLINE_VISIBILITY542 std::pair<iterator, bool> insert(const value_type& __x)543 {return __table_.__insert_unique(__x);}544 _LIBCUDACXX_INLINE_VISIBILITY545 iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;}546 template <class _InputIterator>547 _LIBCUDACXX_INLINE_VISIBILITY548 void insert(_InputIterator __first, _InputIterator __last);549 550 _LIBCUDACXX_INLINE_VISIBILITY551 void erase(const_iterator __p) {__table_.erase(__p.__i_);}552 _LIBCUDACXX_INLINE_VISIBILITY553 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}554 _LIBCUDACXX_INLINE_VISIBILITY555 void erase(const_iterator __first, const_iterator __last)556 {__table_.erase(__first.__i_, __last.__i_);}557 _LIBCUDACXX_INLINE_VISIBILITY558 void clear() {__table_.clear();}559 560 _LIBCUDACXX_INLINE_VISIBILITY561 void swap(hash_map& __u) {__table_.swap(__u.__table_);}562 563 _LIBCUDACXX_INLINE_VISIBILITY564 hasher hash_funct() const565 {return __table_.hash_function().hash_function();}566 _LIBCUDACXX_INLINE_VISIBILITY567 key_equal key_eq() const568 {return __table_.key_eq().key_eq();}569 570 _LIBCUDACXX_INLINE_VISIBILITY571 iterator find(const key_type& __k) {return __table_.find(__k);}572 _LIBCUDACXX_INLINE_VISIBILITY573 const_iterator find(const key_type& __k) const {return __table_.find(__k);}574 _LIBCUDACXX_INLINE_VISIBILITY575 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}576 _LIBCUDACXX_INLINE_VISIBILITY577 std::pair<iterator, iterator> equal_range(const key_type& __k)578 {return __table_.__equal_range_unique(__k);}579 _LIBCUDACXX_INLINE_VISIBILITY580 std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const581 {return __table_.__equal_range_unique(__k);}582 583 mapped_type& operator[](const key_type& __k);584 585 _LIBCUDACXX_INLINE_VISIBILITY586 size_type bucket_count() const {return __table_.bucket_count();}587 _LIBCUDACXX_INLINE_VISIBILITY588 size_type max_bucket_count() const {return __table_.max_bucket_count();}589 590 _LIBCUDACXX_INLINE_VISIBILITY591 size_type elems_in_bucket(size_type __n) const592 {return __table_.bucket_size(__n);}593 594 _LIBCUDACXX_INLINE_VISIBILITY595 void resize(size_type __n) {__table_.rehash(__n);}596 597private:598 __node_holder __construct_node(const key_type& __k);599};600 601template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>602hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(603 size_type __n, const hasher& __hf, const key_equal& __eql)604 : __table_(__hf, __eql)605{606 __table_.rehash(__n);607}608 609template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>610hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(611 size_type __n, const hasher& __hf, const key_equal& __eql,612 const allocator_type& __a)613 : __table_(__hf, __eql, __a)614{615 __table_.rehash(__n);616}617 618template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>619template <class _InputIterator>620hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(621 _InputIterator __first, _InputIterator __last)622{623 insert(__first, __last);624}625 626template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>627template <class _InputIterator>628hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(629 _InputIterator __first, _InputIterator __last, size_type __n,630 const hasher& __hf, const key_equal& __eql)631 : __table_(__hf, __eql)632{633 __table_.rehash(__n);634 insert(__first, __last);635}636 637template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>638template <class _InputIterator>639hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(640 _InputIterator __first, _InputIterator __last, size_type __n,641 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)642 : __table_(__hf, __eql, __a)643{644 __table_.rehash(__n);645 insert(__first, __last);646}647 648template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>649hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(650 const hash_map& __u)651 : __table_(__u.__table_)652{653 __table_.rehash(__u.bucket_count());654 insert(__u.begin(), __u.end());655}656 657template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>658typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder659hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k)660{661 __node_allocator& __na = __table_.__node_alloc();662 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));663 __node_traits::construct(__na, _CUDA_VSTD::addressof(__h->__value_.first), __k);664 __h.get_deleter().__first_constructed = true;665 __node_traits::construct(__na, _CUDA_VSTD::addressof(__h->__value_.second));666 __h.get_deleter().__second_constructed = true;667 return _LIBCUDACXX_EXPLICIT_MOVE(__h); // explicitly moved for C++03668}669 670template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>671template <class _InputIterator>672inline673void674hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,675 _InputIterator __last)676{677 for (; __first != __last; ++__first)678 __table_.__insert_unique(*__first);679}680 681template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>682_Tp&683hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)684{685 iterator __i = find(__k);686 if (__i != end())687 return __i->second;688 __node_holder __h = __construct_node(__k);689 std::pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());690 __h.release();691 return __r.first->second;692}693 694template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>695inline _LIBCUDACXX_INLINE_VISIBILITY696void697swap(hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,698 hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)699{700 __x.swap(__y);701}702 703template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>704bool705operator==(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,706 const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)707{708 if (__x.size() != __y.size())709 return false;710 typedef typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator711 const_iterator;712 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();713 __i != __ex; ++__i)714 {715 const_iterator __j = __y.find(__i->first);716 if (__j == __ey || !(*__i == *__j))717 return false;718 }719 return true;720}721 722template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>723inline _LIBCUDACXX_INLINE_VISIBILITY724bool725operator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,726 const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)727{728 return !(__x == __y);729}730 731template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = std::equal_to<_Key>,732 class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >733class _LIBCUDACXX_TEMPLATE_VIS hash_multimap734{735public:736 // types737 typedef _Key key_type;738 typedef _Tp mapped_type;739 typedef _Tp data_type;740 typedef _Hash hasher;741 typedef _Pred key_equal;742 typedef _Alloc allocator_type;743 typedef std::pair<const key_type, mapped_type> value_type;744 typedef value_type& reference;745 typedef const value_type& const_reference;746 747private:748 typedef std::pair<key_type, mapped_type> __value_type;749 typedef __hash_map_hasher<__value_type, hasher> __hasher;750 typedef __hash_map_equal<__value_type, key_equal> __key_equal;751 typedef typename std::__rebind_alloc_helper<std::allocator_traits<allocator_type>, __value_type>::type __allocator_type;752 753 typedef std::__hash_table<__value_type, __hasher,754 __key_equal, __allocator_type> __table;755 756 __table __table_;757 758 typedef typename __table::__node_traits __node_traits;759 typedef typename __table::__node_allocator __node_allocator;760 typedef typename __table::__node __node;761 typedef __hash_map_node_destructor<__node_allocator> _Dp;762 typedef std::unique_ptr<__node, _Dp> __node_holder;763 typedef std::allocator_traits<allocator_type> __alloc_traits;764public:765 typedef typename __alloc_traits::pointer pointer;766 typedef typename __alloc_traits::const_pointer const_pointer;767 typedef typename __alloc_traits::size_type size_type;768 typedef typename __alloc_traits::difference_type difference_type;769 770 typedef __hash_map_iterator<typename __table::iterator> iterator;771 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;772 773 _LIBCUDACXX_INLINE_VISIBILITY774 hash_multimap() { }775 explicit hash_multimap(size_type __n, const hasher& __hf = hasher(),776 const key_equal& __eql = key_equal());777 hash_multimap(size_type __n, const hasher& __hf,778 const key_equal& __eql,779 const allocator_type& __a);780 template <class _InputIterator>781 hash_multimap(_InputIterator __first, _InputIterator __last);782 template <class _InputIterator>783 hash_multimap(_InputIterator __first, _InputIterator __last,784 size_type __n, const hasher& __hf = hasher(),785 const key_equal& __eql = key_equal());786 template <class _InputIterator>787 hash_multimap(_InputIterator __first, _InputIterator __last,788 size_type __n, const hasher& __hf,789 const key_equal& __eql,790 const allocator_type& __a);791 hash_multimap(const hash_multimap& __u);792 793 _LIBCUDACXX_INLINE_VISIBILITY794 allocator_type get_allocator() const795 {return allocator_type(__table_.__node_alloc());}796 797 _LIBCUDACXX_INLINE_VISIBILITY798 bool empty() const {return __table_.size() == 0;}799 _LIBCUDACXX_INLINE_VISIBILITY800 size_type size() const {return __table_.size();}801 _LIBCUDACXX_INLINE_VISIBILITY802 size_type max_size() const {return __table_.max_size();}803 804 _LIBCUDACXX_INLINE_VISIBILITY805 iterator begin() {return __table_.begin();}806 _LIBCUDACXX_INLINE_VISIBILITY807 iterator end() {return __table_.end();}808 _LIBCUDACXX_INLINE_VISIBILITY809 const_iterator begin() const {return __table_.begin();}810 _LIBCUDACXX_INLINE_VISIBILITY811 const_iterator end() const {return __table_.end();}812 813 _LIBCUDACXX_INLINE_VISIBILITY814 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}815 _LIBCUDACXX_INLINE_VISIBILITY816 iterator insert(const_iterator, const value_type& __x) {return insert(__x);}817 template <class _InputIterator>818 _LIBCUDACXX_INLINE_VISIBILITY819 void insert(_InputIterator __first, _InputIterator __last);820 821 _LIBCUDACXX_INLINE_VISIBILITY822 void erase(const_iterator __p) {__table_.erase(__p.__i_);}823 _LIBCUDACXX_INLINE_VISIBILITY824 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}825 _LIBCUDACXX_INLINE_VISIBILITY826 void erase(const_iterator __first, const_iterator __last)827 {__table_.erase(__first.__i_, __last.__i_);}828 _LIBCUDACXX_INLINE_VISIBILITY829 void clear() {__table_.clear();}830 831 _LIBCUDACXX_INLINE_VISIBILITY832 void swap(hash_multimap& __u) {__table_.swap(__u.__table_);}833 834 _LIBCUDACXX_INLINE_VISIBILITY835 hasher hash_funct() const836 {return __table_.hash_function().hash_function();}837 _LIBCUDACXX_INLINE_VISIBILITY838 key_equal key_eq() const839 {return __table_.key_eq().key_eq();}840 841 _LIBCUDACXX_INLINE_VISIBILITY842 iterator find(const key_type& __k) {return __table_.find(__k);}843 _LIBCUDACXX_INLINE_VISIBILITY844 const_iterator find(const key_type& __k) const {return __table_.find(__k);}845 _LIBCUDACXX_INLINE_VISIBILITY846 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}847 _LIBCUDACXX_INLINE_VISIBILITY848 std::pair<iterator, iterator> equal_range(const key_type& __k)849 {return __table_.__equal_range_multi(__k);}850 _LIBCUDACXX_INLINE_VISIBILITY851 std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const852 {return __table_.__equal_range_multi(__k);}853 854 _LIBCUDACXX_INLINE_VISIBILITY855 size_type bucket_count() const {return __table_.bucket_count();}856 _LIBCUDACXX_INLINE_VISIBILITY857 size_type max_bucket_count() const {return __table_.max_bucket_count();}858 859 _LIBCUDACXX_INLINE_VISIBILITY860 size_type elems_in_bucket(size_type __n) const861 {return __table_.bucket_size(__n);}862 863 _LIBCUDACXX_INLINE_VISIBILITY864 void resize(size_type __n) {__table_.rehash(__n);}865};866 867template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>868hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(869 size_type __n, const hasher& __hf, const key_equal& __eql)870 : __table_(__hf, __eql)871{872 __table_.rehash(__n);873}874 875template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>876hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(877 size_type __n, const hasher& __hf, const key_equal& __eql,878 const allocator_type& __a)879 : __table_(__hf, __eql, __a)880{881 __table_.rehash(__n);882}883 884template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>885template <class _InputIterator>886hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(887 _InputIterator __first, _InputIterator __last)888{889 insert(__first, __last);890}891 892template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>893template <class _InputIterator>894hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(895 _InputIterator __first, _InputIterator __last, size_type __n,896 const hasher& __hf, const key_equal& __eql)897 : __table_(__hf, __eql)898{899 __table_.rehash(__n);900 insert(__first, __last);901}902 903template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>904template <class _InputIterator>905hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(906 _InputIterator __first, _InputIterator __last, size_type __n,907 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)908 : __table_(__hf, __eql, __a)909{910 __table_.rehash(__n);911 insert(__first, __last);912}913 914template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>915hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(916 const hash_multimap& __u)917 : __table_(__u.__table_)918{919 __table_.rehash(__u.bucket_count());920 insert(__u.begin(), __u.end());921}922 923template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>924template <class _InputIterator>925inline926void927hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,928 _InputIterator __last)929{930 for (; __first != __last; ++__first)931 __table_.__insert_multi(*__first);932}933 934template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>935inline _LIBCUDACXX_INLINE_VISIBILITY936void937swap(hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,938 hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)939{940 __x.swap(__y);941}942 943template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>944bool945operator==(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,946 const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)947{948 if (__x.size() != __y.size())949 return false;950 typedef typename hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator951 const_iterator;952 typedef std::pair<const_iterator, const_iterator> _EqRng;953 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)954 {955 _EqRng __xeq = __x.equal_range(__i->first);956 _EqRng __yeq = __y.equal_range(__i->first);957 if (_CUDA_VSTD::distance(__xeq.first, __xeq.second) !=958 _CUDA_VSTD::distance(__yeq.first, __yeq.second) ||959 !_CUDA_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))960 return false;961 __i = __xeq.second;962 }963 return true;964}965 966template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>967inline _LIBCUDACXX_INLINE_VISIBILITY968bool969operator!=(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,970 const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)971{972 return !(__x == __y);973}974 975} // __gnu_cxx976 977#endif // _LIBCUDACXX_HASH_MAP978 