__hash_table 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP__HASH_TABLE
  11. #define _LIBCPP__HASH_TABLE
  12. #include <__config>
  13. #include <initializer_list>
  14. #include <memory>
  15. #include <iterator>
  16. #include <algorithm>
  17. #include <cmath>
  18. #include <utility>
  19. #include <__undef_min_max>
  20. #include <__undef___deallocate>
  21. #include <__debug>
  22. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  23. #pragma GCC system_header
  24. #endif
  25. _LIBCPP_BEGIN_NAMESPACE_STD
  26. #ifndef _LIBCPP_CXX03_LANG
  27. template <class _Key, class _Tp>
  28. union __hash_value_type;
  29. #else
  30. template <class _Key, class _Tp>
  31. struct __hash_value_type;
  32. #endif
  33. #ifndef _LIBCPP_CXX03_LANG
  34. template <class _Tp>
  35. struct __is_hash_value_type_imp : false_type {};
  36. template <class _Key, class _Value>
  37. struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {};
  38. template <class ..._Args>
  39. struct __is_hash_value_type : false_type {};
  40. template <class _One>
  41. struct __is_hash_value_type<_One> : __is_hash_value_type_imp<typename __uncvref<_One>::type> {};
  42. #endif
  43. _LIBCPP_FUNC_VIS
  44. size_t __next_prime(size_t __n);
  45. template <class _NodePtr>
  46. struct __hash_node_base
  47. {
  48. typedef __hash_node_base __first_node;
  49. _NodePtr __next_;
  50. _LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {}
  51. };
  52. template <class _Tp, class _VoidPtr>
  53. struct __hash_node
  54. : public __hash_node_base
  55. <
  56. typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type
  57. >
  58. {
  59. typedef _Tp __node_value_type;
  60. size_t __hash_;
  61. __node_value_type __value_;
  62. };
  63. inline _LIBCPP_INLINE_VISIBILITY
  64. bool
  65. __is_hash_power2(size_t __bc)
  66. {
  67. return __bc > 2 && !(__bc & (__bc - 1));
  68. }
  69. inline _LIBCPP_INLINE_VISIBILITY
  70. size_t
  71. __constrain_hash(size_t __h, size_t __bc)
  72. {
  73. return !(__bc & (__bc - 1)) ? __h & (__bc - 1) :
  74. (__h < __bc ? __h : __h % __bc);
  75. }
  76. inline _LIBCPP_INLINE_VISIBILITY
  77. size_t
  78. __next_hash_pow2(size_t __n)
  79. {
  80. return size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1));
  81. }
  82. template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table;
  83. template <class _NodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_iterator;
  84. template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
  85. template <class _NodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_local_iterator;
  86. template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
  87. template <class _HashIterator> class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator;
  88. template <class _HashIterator> class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
  89. template <class _Tp>
  90. struct __hash_key_value_types {
  91. static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, "");
  92. typedef _Tp key_type;
  93. typedef _Tp __node_value_type;
  94. typedef _Tp __container_value_type;
  95. static const bool __is_map = false;
  96. _LIBCPP_INLINE_VISIBILITY
  97. static key_type const& __get_key(_Tp const& __v) {
  98. return __v;
  99. }
  100. _LIBCPP_INLINE_VISIBILITY
  101. static __container_value_type const& __get_value(__node_value_type const& __v) {
  102. return __v;
  103. }
  104. _LIBCPP_INLINE_VISIBILITY
  105. static __container_value_type* __get_ptr(__node_value_type& __n) {
  106. return _VSTD::addressof(__n);
  107. }
  108. #ifndef _LIBCPP_CXX03_LANG
  109. _LIBCPP_INLINE_VISIBILITY
  110. static __container_value_type&& __move(__node_value_type& __v) {
  111. return _VSTD::move(__v);
  112. }
  113. #endif
  114. };
  115. template <class _Key, class _Tp>
  116. struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > {
  117. typedef _Key key_type;
  118. typedef _Tp mapped_type;
  119. typedef __hash_value_type<_Key, _Tp> __node_value_type;
  120. typedef pair<const _Key, _Tp> __container_value_type;
  121. typedef pair<_Key, _Tp> __nc_value_type;
  122. typedef __container_value_type __map_value_type;
  123. static const bool __is_map = true;
  124. _LIBCPP_INLINE_VISIBILITY
  125. static key_type const& __get_key(__container_value_type const& __v) {
  126. return __v.first;
  127. }
  128. template <class _Up>
  129. _LIBCPP_INLINE_VISIBILITY
  130. static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value,
  131. __container_value_type const&>::type
  132. __get_value(_Up& __t) {
  133. return __t.__cc;
  134. }
  135. template <class _Up>
  136. _LIBCPP_INLINE_VISIBILITY
  137. static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value,
  138. __container_value_type const&>::type
  139. __get_value(_Up& __t) {
  140. return __t;
  141. }
  142. _LIBCPP_INLINE_VISIBILITY
  143. static __container_value_type* __get_ptr(__node_value_type& __n) {
  144. return _VSTD::addressof(__n.__cc);
  145. }
  146. #ifndef _LIBCPP_CXX03_LANG
  147. _LIBCPP_INLINE_VISIBILITY
  148. static __nc_value_type&& __move(__node_value_type& __v) {
  149. return _VSTD::move(__v.__nc);
  150. }
  151. #endif
  152. };
  153. template <class _Tp, class _AllocPtr, class _KVTypes = __hash_key_value_types<_Tp>,
  154. bool = _KVTypes::__is_map>
  155. struct __hash_map_pointer_types {};
  156. template <class _Tp, class _AllocPtr, class _KVTypes>
  157. struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> {
  158. typedef typename _KVTypes::__map_value_type _Mv;
  159. typedef typename __rebind_pointer<_AllocPtr, _Mv>::type
  160. __map_value_type_pointer;
  161. typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type
  162. __const_map_value_type_pointer;
  163. };
  164. template <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type>
  165. struct __hash_node_types;
  166. template <class _NodePtr, class _Tp, class _VoidPtr>
  167. struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> >
  168. : public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr>
  169. {
  170. typedef __hash_key_value_types<_Tp> __base;
  171. public:
  172. typedef ptrdiff_t difference_type;
  173. typedef size_t size_type;
  174. typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer;
  175. typedef typename pointer_traits<_NodePtr>::element_type __node_type;
  176. typedef _NodePtr __node_pointer;
  177. typedef __hash_node_base<__node_pointer> __node_base_type;
  178. typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type
  179. __node_base_pointer;
  180. typedef _Tp __node_value_type;
  181. typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type
  182. __node_value_type_pointer;
  183. typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type
  184. __const_node_value_type_pointer;
  185. private:
  186. static_assert(!is_const<__node_type>::value,
  187. "_NodePtr should never be a pointer to const");
  188. static_assert((is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value),
  189. "_VoidPtr does not point to unqualified void type");
  190. static_assert((is_same<typename __rebind_pointer<_VoidPtr, __node_type>::type,
  191. _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr.");
  192. };
  193. template <class _HashIterator>
  194. struct __hash_node_types_from_iterator;
  195. template <class _NodePtr>
  196. struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
  197. template <class _NodePtr>
  198. struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
  199. template <class _NodePtr>
  200. struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
  201. template <class _NodePtr>
  202. struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
  203. template <class _NodeValueTp, class _VoidPtr>
  204. struct __make_hash_node_types {
  205. typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp;
  206. typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr;
  207. typedef __hash_node_types<_NodePtr> type;
  208. };
  209. template <class _NodePtr>
  210. class _LIBCPP_TYPE_VIS_ONLY __hash_iterator
  211. {
  212. typedef __hash_node_types<_NodePtr> _NodeTypes;
  213. typedef _NodePtr __node_pointer;
  214. __node_pointer __node_;
  215. public:
  216. typedef forward_iterator_tag iterator_category;
  217. typedef typename _NodeTypes::__node_value_type value_type;
  218. typedef typename _NodeTypes::difference_type difference_type;
  219. typedef value_type& reference;
  220. typedef typename _NodeTypes::__node_value_type_pointer pointer;
  221. _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT
  222. #if _LIBCPP_STD_VER > 11
  223. : __node_(nullptr)
  224. #endif
  225. {
  226. #if _LIBCPP_DEBUG_LEVEL >= 2
  227. __get_db()->__insert_i(this);
  228. #endif
  229. }
  230. #if _LIBCPP_DEBUG_LEVEL >= 2
  231. _LIBCPP_INLINE_VISIBILITY
  232. __hash_iterator(const __hash_iterator& __i)
  233. : __node_(__i.__node_)
  234. {
  235. __get_db()->__iterator_copy(this, &__i);
  236. }
  237. _LIBCPP_INLINE_VISIBILITY
  238. ~__hash_iterator()
  239. {
  240. __get_db()->__erase_i(this);
  241. }
  242. _LIBCPP_INLINE_VISIBILITY
  243. __hash_iterator& operator=(const __hash_iterator& __i)
  244. {
  245. if (this != &__i)
  246. {
  247. __get_db()->__iterator_copy(this, &__i);
  248. __node_ = __i.__node_;
  249. }
  250. return *this;
  251. }
  252. #endif // _LIBCPP_DEBUG_LEVEL >= 2
  253. _LIBCPP_INLINE_VISIBILITY
  254. reference operator*() const
  255. {
  256. #if _LIBCPP_DEBUG_LEVEL >= 2
  257. _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
  258. "Attempted to dereference a non-dereferenceable unordered container iterator");
  259. #endif
  260. return __node_->__value_;
  261. }
  262. _LIBCPP_INLINE_VISIBILITY
  263. pointer operator->() const
  264. {
  265. #if _LIBCPP_DEBUG_LEVEL >= 2
  266. _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
  267. "Attempted to dereference a non-dereferenceable unordered container iterator");
  268. #endif
  269. return pointer_traits<pointer>::pointer_to(__node_->__value_);
  270. }
  271. _LIBCPP_INLINE_VISIBILITY
  272. __hash_iterator& operator++()
  273. {
  274. #if _LIBCPP_DEBUG_LEVEL >= 2
  275. _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
  276. "Attempted to increment non-incrementable unordered container iterator");
  277. #endif
  278. __node_ = __node_->__next_;
  279. return *this;
  280. }
  281. _LIBCPP_INLINE_VISIBILITY
  282. __hash_iterator operator++(int)
  283. {
  284. __hash_iterator __t(*this);
  285. ++(*this);
  286. return __t;
  287. }
  288. friend _LIBCPP_INLINE_VISIBILITY
  289. bool operator==(const __hash_iterator& __x, const __hash_iterator& __y)
  290. {
  291. return __x.__node_ == __y.__node_;
  292. }
  293. friend _LIBCPP_INLINE_VISIBILITY
  294. bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y)
  295. {return !(__x == __y);}
  296. private:
  297. #if _LIBCPP_DEBUG_LEVEL >= 2
  298. _LIBCPP_INLINE_VISIBILITY
  299. __hash_iterator(__node_pointer __node, const void* __c) _NOEXCEPT
  300. : __node_(__node)
  301. {
  302. __get_db()->__insert_ic(this, __c);
  303. }
  304. #else
  305. _LIBCPP_INLINE_VISIBILITY
  306. __hash_iterator(__node_pointer __node) _NOEXCEPT
  307. : __node_(__node)
  308. {}
  309. #endif
  310. template <class, class, class, class> friend class __hash_table;
  311. template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
  312. template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator;
  313. template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
  314. template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
  315. };
  316. template <class _NodePtr>
  317. class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator
  318. {
  319. static_assert(!is_const<typename pointer_traits<_NodePtr>::element_type>::value, "");
  320. typedef __hash_node_types<_NodePtr> _NodeTypes;
  321. typedef _NodePtr __node_pointer;
  322. __node_pointer __node_;
  323. public:
  324. typedef __hash_iterator<_NodePtr> __non_const_iterator;
  325. typedef forward_iterator_tag iterator_category;
  326. typedef typename _NodeTypes::__node_value_type value_type;
  327. typedef typename _NodeTypes::difference_type difference_type;
  328. typedef const value_type& reference;
  329. typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
  330. _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT
  331. #if _LIBCPP_STD_VER > 11
  332. : __node_(nullptr)
  333. #endif
  334. {
  335. #if _LIBCPP_DEBUG_LEVEL >= 2
  336. __get_db()->__insert_i(this);
  337. #endif
  338. }
  339. _LIBCPP_INLINE_VISIBILITY
  340. __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT
  341. : __node_(__x.__node_)
  342. {
  343. #if _LIBCPP_DEBUG_LEVEL >= 2
  344. __get_db()->__iterator_copy(this, &__x);
  345. #endif
  346. }
  347. #if _LIBCPP_DEBUG_LEVEL >= 2
  348. _LIBCPP_INLINE_VISIBILITY
  349. __hash_const_iterator(const __hash_const_iterator& __i)
  350. : __node_(__i.__node_)
  351. {
  352. __get_db()->__iterator_copy(this, &__i);
  353. }
  354. _LIBCPP_INLINE_VISIBILITY
  355. ~__hash_const_iterator()
  356. {
  357. __get_db()->__erase_i(this);
  358. }
  359. _LIBCPP_INLINE_VISIBILITY
  360. __hash_const_iterator& operator=(const __hash_const_iterator& __i)
  361. {
  362. if (this != &__i)
  363. {
  364. __get_db()->__iterator_copy(this, &__i);
  365. __node_ = __i.__node_;
  366. }
  367. return *this;
  368. }
  369. #endif // _LIBCPP_DEBUG_LEVEL >= 2
  370. _LIBCPP_INLINE_VISIBILITY
  371. reference operator*() const
  372. {
  373. #if _LIBCPP_DEBUG_LEVEL >= 2
  374. _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
  375. "Attempted to dereference a non-dereferenceable unordered container const_iterator");
  376. #endif
  377. return __node_->__value_;
  378. }
  379. _LIBCPP_INLINE_VISIBILITY
  380. pointer operator->() const
  381. {
  382. #if _LIBCPP_DEBUG_LEVEL >= 2
  383. _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
  384. "Attempted to dereference a non-dereferenceable unordered container const_iterator");
  385. #endif
  386. return pointer_traits<pointer>::pointer_to(__node_->__value_);
  387. }
  388. _LIBCPP_INLINE_VISIBILITY
  389. __hash_const_iterator& operator++()
  390. {
  391. #if _LIBCPP_DEBUG_LEVEL >= 2
  392. _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
  393. "Attempted to increment non-incrementable unordered container const_iterator");
  394. #endif
  395. __node_ = __node_->__next_;
  396. return *this;
  397. }
  398. _LIBCPP_INLINE_VISIBILITY
  399. __hash_const_iterator operator++(int)
  400. {
  401. __hash_const_iterator __t(*this);
  402. ++(*this);
  403. return __t;
  404. }
  405. friend _LIBCPP_INLINE_VISIBILITY
  406. bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
  407. {
  408. return __x.__node_ == __y.__node_;
  409. }
  410. friend _LIBCPP_INLINE_VISIBILITY
  411. bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
  412. {return !(__x == __y);}
  413. private:
  414. #if _LIBCPP_DEBUG_LEVEL >= 2
  415. _LIBCPP_INLINE_VISIBILITY
  416. __hash_const_iterator(__node_pointer __node, const void* __c) _NOEXCEPT
  417. : __node_(__node)
  418. {
  419. __get_db()->__insert_ic(this, __c);
  420. }
  421. #else
  422. _LIBCPP_INLINE_VISIBILITY
  423. __hash_const_iterator(__node_pointer __node) _NOEXCEPT
  424. : __node_(__node)
  425. {}
  426. #endif
  427. template <class, class, class, class> friend class __hash_table;
  428. template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
  429. template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
  430. template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
  431. };
  432. template <class _NodePtr>
  433. class _LIBCPP_TYPE_VIS_ONLY __hash_local_iterator
  434. {
  435. typedef __hash_node_types<_NodePtr> _NodeTypes;
  436. typedef _NodePtr __node_pointer;
  437. __node_pointer __node_;
  438. size_t __bucket_;
  439. size_t __bucket_count_;
  440. public:
  441. typedef forward_iterator_tag iterator_category;
  442. typedef typename _NodeTypes::__node_value_type value_type;
  443. typedef typename _NodeTypes::difference_type difference_type;
  444. typedef value_type& reference;
  445. typedef typename _NodeTypes::__node_value_type_pointer pointer;
  446. _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT
  447. {
  448. #if _LIBCPP_DEBUG_LEVEL >= 2
  449. __get_db()->__insert_i(this);
  450. #endif
  451. }
  452. #if _LIBCPP_DEBUG_LEVEL >= 2
  453. _LIBCPP_INLINE_VISIBILITY
  454. __hash_local_iterator(const __hash_local_iterator& __i)
  455. : __node_(__i.__node_),
  456. __bucket_(__i.__bucket_),
  457. __bucket_count_(__i.__bucket_count_)
  458. {
  459. __get_db()->__iterator_copy(this, &__i);
  460. }
  461. _LIBCPP_INLINE_VISIBILITY
  462. ~__hash_local_iterator()
  463. {
  464. __get_db()->__erase_i(this);
  465. }
  466. _LIBCPP_INLINE_VISIBILITY
  467. __hash_local_iterator& operator=(const __hash_local_iterator& __i)
  468. {
  469. if (this != &__i)
  470. {
  471. __get_db()->__iterator_copy(this, &__i);
  472. __node_ = __i.__node_;
  473. __bucket_ = __i.__bucket_;
  474. __bucket_count_ = __i.__bucket_count_;
  475. }
  476. return *this;
  477. }
  478. #endif // _LIBCPP_DEBUG_LEVEL >= 2
  479. _LIBCPP_INLINE_VISIBILITY
  480. reference operator*() const
  481. {
  482. #if _LIBCPP_DEBUG_LEVEL >= 2
  483. _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
  484. "Attempted to dereference a non-dereferenceable unordered container local_iterator");
  485. #endif
  486. return __node_->__value_;
  487. }
  488. _LIBCPP_INLINE_VISIBILITY
  489. pointer operator->() const
  490. {
  491. #if _LIBCPP_DEBUG_LEVEL >= 2
  492. _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
  493. "Attempted to dereference a non-dereferenceable unordered container local_iterator");
  494. #endif
  495. return pointer_traits<pointer>::pointer_to(__node_->__value_);
  496. }
  497. _LIBCPP_INLINE_VISIBILITY
  498. __hash_local_iterator& operator++()
  499. {
  500. #if _LIBCPP_DEBUG_LEVEL >= 2
  501. _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
  502. "Attempted to increment non-incrementable unordered container local_iterator");
  503. #endif
  504. __node_ = __node_->__next_;
  505. if (__node_ != nullptr && __constrain_hash(__node_->__hash_, __bucket_count_) != __bucket_)
  506. __node_ = nullptr;
  507. return *this;
  508. }
  509. _LIBCPP_INLINE_VISIBILITY
  510. __hash_local_iterator operator++(int)
  511. {
  512. __hash_local_iterator __t(*this);
  513. ++(*this);
  514. return __t;
  515. }
  516. friend _LIBCPP_INLINE_VISIBILITY
  517. bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
  518. {
  519. return __x.__node_ == __y.__node_;
  520. }
  521. friend _LIBCPP_INLINE_VISIBILITY
  522. bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
  523. {return !(__x == __y);}
  524. private:
  525. #if _LIBCPP_DEBUG_LEVEL >= 2
  526. _LIBCPP_INLINE_VISIBILITY
  527. __hash_local_iterator(__node_pointer __node, size_t __bucket,
  528. size_t __bucket_count, const void* __c) _NOEXCEPT
  529. : __node_(__node),
  530. __bucket_(__bucket),
  531. __bucket_count_(__bucket_count)
  532. {
  533. __get_db()->__insert_ic(this, __c);
  534. if (__node_ != nullptr)
  535. __node_ = __node_->__next_;
  536. }
  537. #else
  538. _LIBCPP_INLINE_VISIBILITY
  539. __hash_local_iterator(__node_pointer __node, size_t __bucket,
  540. size_t __bucket_count) _NOEXCEPT
  541. : __node_(__node),
  542. __bucket_(__bucket),
  543. __bucket_count_(__bucket_count)
  544. {
  545. if (__node_ != nullptr)
  546. __node_ = __node_->__next_;
  547. }
  548. #endif
  549. template <class, class, class, class> friend class __hash_table;
  550. template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
  551. template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator;
  552. };
  553. template <class _ConstNodePtr>
  554. class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator
  555. {
  556. typedef __hash_node_types<_ConstNodePtr> _NodeTypes;
  557. typedef _ConstNodePtr __node_pointer;
  558. __node_pointer __node_;
  559. size_t __bucket_;
  560. size_t __bucket_count_;
  561. typedef pointer_traits<__node_pointer> __pointer_traits;
  562. typedef typename __pointer_traits::element_type __node;
  563. typedef typename remove_const<__node>::type __non_const_node;
  564. typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type
  565. __non_const_node_pointer;
  566. public:
  567. typedef __hash_local_iterator<__non_const_node_pointer>
  568. __non_const_iterator;
  569. typedef forward_iterator_tag iterator_category;
  570. typedef typename _NodeTypes::__node_value_type value_type;
  571. typedef typename _NodeTypes::difference_type difference_type;
  572. typedef const value_type& reference;
  573. typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
  574. _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT
  575. {
  576. #if _LIBCPP_DEBUG_LEVEL >= 2
  577. __get_db()->__insert_i(this);
  578. #endif
  579. }
  580. _LIBCPP_INLINE_VISIBILITY
  581. __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT
  582. : __node_(__x.__node_),
  583. __bucket_(__x.__bucket_),
  584. __bucket_count_(__x.__bucket_count_)
  585. {
  586. #if _LIBCPP_DEBUG_LEVEL >= 2
  587. __get_db()->__iterator_copy(this, &__x);
  588. #endif
  589. }
  590. #if _LIBCPP_DEBUG_LEVEL >= 2
  591. _LIBCPP_INLINE_VISIBILITY
  592. __hash_const_local_iterator(const __hash_const_local_iterator& __i)
  593. : __node_(__i.__node_),
  594. __bucket_(__i.__bucket_),
  595. __bucket_count_(__i.__bucket_count_)
  596. {
  597. __get_db()->__iterator_copy(this, &__i);
  598. }
  599. _LIBCPP_INLINE_VISIBILITY
  600. ~__hash_const_local_iterator()
  601. {
  602. __get_db()->__erase_i(this);
  603. }
  604. _LIBCPP_INLINE_VISIBILITY
  605. __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i)
  606. {
  607. if (this != &__i)
  608. {
  609. __get_db()->__iterator_copy(this, &__i);
  610. __node_ = __i.__node_;
  611. __bucket_ = __i.__bucket_;
  612. __bucket_count_ = __i.__bucket_count_;
  613. }
  614. return *this;
  615. }
  616. #endif // _LIBCPP_DEBUG_LEVEL >= 2
  617. _LIBCPP_INLINE_VISIBILITY
  618. reference operator*() const
  619. {
  620. #if _LIBCPP_DEBUG_LEVEL >= 2
  621. _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
  622. "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
  623. #endif
  624. return __node_->__value_;
  625. }
  626. _LIBCPP_INLINE_VISIBILITY
  627. pointer operator->() const
  628. {
  629. #if _LIBCPP_DEBUG_LEVEL >= 2
  630. _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
  631. "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
  632. #endif
  633. return pointer_traits<pointer>::pointer_to(__node_->__value_);
  634. }
  635. _LIBCPP_INLINE_VISIBILITY
  636. __hash_const_local_iterator& operator++()
  637. {
  638. #if _LIBCPP_DEBUG_LEVEL >= 2
  639. _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
  640. "Attempted to increment non-incrementable unordered container const_local_iterator");
  641. #endif
  642. __node_ = __node_->__next_;
  643. if (__node_ != nullptr && __constrain_hash(__node_->__hash_, __bucket_count_) != __bucket_)
  644. __node_ = nullptr;
  645. return *this;
  646. }
  647. _LIBCPP_INLINE_VISIBILITY
  648. __hash_const_local_iterator operator++(int)
  649. {
  650. __hash_const_local_iterator __t(*this);
  651. ++(*this);
  652. return __t;
  653. }
  654. friend _LIBCPP_INLINE_VISIBILITY
  655. bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
  656. {
  657. return __x.__node_ == __y.__node_;
  658. }
  659. friend _LIBCPP_INLINE_VISIBILITY
  660. bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
  661. {return !(__x == __y);}
  662. private:
  663. #if _LIBCPP_DEBUG_LEVEL >= 2
  664. _LIBCPP_INLINE_VISIBILITY
  665. __hash_const_local_iterator(__node_pointer __node, size_t __bucket,
  666. size_t __bucket_count, const void* __c) _NOEXCEPT
  667. : __node_(__node),
  668. __bucket_(__bucket),
  669. __bucket_count_(__bucket_count)
  670. {
  671. __get_db()->__insert_ic(this, __c);
  672. if (__node_ != nullptr)
  673. __node_ = __node_->__next_;
  674. }
  675. #else
  676. _LIBCPP_INLINE_VISIBILITY
  677. __hash_const_local_iterator(__node_pointer __node, size_t __bucket,
  678. size_t __bucket_count) _NOEXCEPT
  679. : __node_(__node),
  680. __bucket_(__bucket),
  681. __bucket_count_(__bucket_count)
  682. {
  683. if (__node_ != nullptr)
  684. __node_ = __node_->__next_;
  685. }
  686. #endif
  687. template <class, class, class, class> friend class __hash_table;
  688. template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
  689. };
  690. template <class _Alloc>
  691. class __bucket_list_deallocator
  692. {
  693. typedef _Alloc allocator_type;
  694. typedef allocator_traits<allocator_type> __alloc_traits;
  695. typedef typename __alloc_traits::size_type size_type;
  696. __compressed_pair<size_type, allocator_type> __data_;
  697. public:
  698. typedef typename __alloc_traits::pointer pointer;
  699. _LIBCPP_INLINE_VISIBILITY
  700. __bucket_list_deallocator()
  701. _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
  702. : __data_(0) {}
  703. _LIBCPP_INLINE_VISIBILITY
  704. __bucket_list_deallocator(const allocator_type& __a, size_type __size)
  705. _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
  706. : __data_(__size, __a) {}
  707. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  708. _LIBCPP_INLINE_VISIBILITY
  709. __bucket_list_deallocator(__bucket_list_deallocator&& __x)
  710. _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
  711. : __data_(_VSTD::move(__x.__data_))
  712. {
  713. __x.size() = 0;
  714. }
  715. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  716. _LIBCPP_INLINE_VISIBILITY
  717. size_type& size() _NOEXCEPT {return __data_.first();}
  718. _LIBCPP_INLINE_VISIBILITY
  719. size_type size() const _NOEXCEPT {return __data_.first();}
  720. _LIBCPP_INLINE_VISIBILITY
  721. allocator_type& __alloc() _NOEXCEPT {return __data_.second();}
  722. _LIBCPP_INLINE_VISIBILITY
  723. const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();}
  724. _LIBCPP_INLINE_VISIBILITY
  725. void operator()(pointer __p) _NOEXCEPT
  726. {
  727. __alloc_traits::deallocate(__alloc(), __p, size());
  728. }
  729. };
  730. template <class _Alloc> class __hash_map_node_destructor;
  731. template <class _Alloc>
  732. class __hash_node_destructor
  733. {
  734. typedef _Alloc allocator_type;
  735. typedef allocator_traits<allocator_type> __alloc_traits;
  736. public:
  737. typedef typename __alloc_traits::pointer pointer;
  738. private:
  739. typedef __hash_node_types<pointer> _NodeTypes;
  740. allocator_type& __na_;
  741. __hash_node_destructor& operator=(const __hash_node_destructor&);
  742. public:
  743. bool __value_constructed;
  744. _LIBCPP_INLINE_VISIBILITY
  745. explicit __hash_node_destructor(allocator_type& __na,
  746. bool __constructed = false) _NOEXCEPT
  747. : __na_(__na),
  748. __value_constructed(__constructed)
  749. {}
  750. _LIBCPP_INLINE_VISIBILITY
  751. void operator()(pointer __p) _NOEXCEPT
  752. {
  753. if (__value_constructed)
  754. __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_));
  755. if (__p)
  756. __alloc_traits::deallocate(__na_, __p, 1);
  757. }
  758. template <class> friend class __hash_map_node_destructor;
  759. };
  760. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  761. class __hash_table
  762. {
  763. public:
  764. typedef _Tp value_type;
  765. typedef _Hash hasher;
  766. typedef _Equal key_equal;
  767. typedef _Alloc allocator_type;
  768. private:
  769. typedef allocator_traits<allocator_type> __alloc_traits;
  770. typedef typename
  771. __make_hash_node_types<value_type, typename __alloc_traits::void_pointer>::type
  772. _NodeTypes;
  773. public:
  774. typedef typename _NodeTypes::__node_value_type __node_value_type;
  775. typedef typename _NodeTypes::__container_value_type __container_value_type;
  776. typedef typename _NodeTypes::key_type key_type;
  777. typedef value_type& reference;
  778. typedef const value_type& const_reference;
  779. typedef typename __alloc_traits::pointer pointer;
  780. typedef typename __alloc_traits::const_pointer const_pointer;
  781. #ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
  782. typedef typename __alloc_traits::size_type size_type;
  783. #else
  784. typedef typename _NodeTypes::size_type size_type;
  785. #endif
  786. typedef typename _NodeTypes::difference_type difference_type;
  787. public:
  788. // Create __node
  789. typedef typename _NodeTypes::__node_type __node;
  790. typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
  791. typedef allocator_traits<__node_allocator> __node_traits;
  792. typedef typename _NodeTypes::__void_pointer __void_pointer;
  793. typedef typename _NodeTypes::__node_pointer __node_pointer;
  794. typedef typename _NodeTypes::__node_pointer __node_const_pointer;
  795. typedef typename _NodeTypes::__node_base_type __first_node;
  796. typedef typename _NodeTypes::__node_base_pointer __node_base_pointer;
  797. private:
  798. // check for sane allocator pointer rebinding semantics. Rebinding the
  799. // allocator for a new pointer type should be exactly the same as rebinding
  800. // the pointer using 'pointer_traits'.
  801. static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value),
  802. "Allocator does not rebind pointers in a sane manner.");
  803. typedef typename __rebind_alloc_helper<__node_traits, __first_node>::type
  804. __node_base_allocator;
  805. typedef allocator_traits<__node_base_allocator> __node_base_traits;
  806. static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value),
  807. "Allocator does not rebind pointers in a sane manner.");
  808. private:
  809. typedef typename __rebind_alloc_helper<__node_traits, __node_pointer>::type __pointer_allocator;
  810. typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter;
  811. typedef unique_ptr<__node_pointer[], __bucket_list_deleter> __bucket_list;
  812. typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits;
  813. typedef typename __bucket_list_deleter::pointer __node_pointer_pointer;
  814. // --- Member data begin ---
  815. __bucket_list __bucket_list_;
  816. __compressed_pair<__first_node, __node_allocator> __p1_;
  817. __compressed_pair<size_type, hasher> __p2_;
  818. __compressed_pair<float, key_equal> __p3_;
  819. // --- Member data end ---
  820. _LIBCPP_INLINE_VISIBILITY
  821. size_type& size() _NOEXCEPT {return __p2_.first();}
  822. public:
  823. _LIBCPP_INLINE_VISIBILITY
  824. size_type size() const _NOEXCEPT {return __p2_.first();}
  825. _LIBCPP_INLINE_VISIBILITY
  826. hasher& hash_function() _NOEXCEPT {return __p2_.second();}
  827. _LIBCPP_INLINE_VISIBILITY
  828. const hasher& hash_function() const _NOEXCEPT {return __p2_.second();}
  829. _LIBCPP_INLINE_VISIBILITY
  830. float& max_load_factor() _NOEXCEPT {return __p3_.first();}
  831. _LIBCPP_INLINE_VISIBILITY
  832. float max_load_factor() const _NOEXCEPT {return __p3_.first();}
  833. _LIBCPP_INLINE_VISIBILITY
  834. key_equal& key_eq() _NOEXCEPT {return __p3_.second();}
  835. _LIBCPP_INLINE_VISIBILITY
  836. const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();}
  837. _LIBCPP_INLINE_VISIBILITY
  838. __node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();}
  839. _LIBCPP_INLINE_VISIBILITY
  840. const __node_allocator& __node_alloc() const _NOEXCEPT
  841. {return __p1_.second();}
  842. public:
  843. typedef __hash_iterator<__node_pointer> iterator;
  844. typedef __hash_const_iterator<__node_pointer> const_iterator;
  845. typedef __hash_local_iterator<__node_pointer> local_iterator;
  846. typedef __hash_const_local_iterator<__node_pointer> const_local_iterator;
  847. _LIBCPP_INLINE_VISIBILITY
  848. __hash_table()
  849. _NOEXCEPT_(
  850. is_nothrow_default_constructible<__bucket_list>::value &&
  851. is_nothrow_default_constructible<__first_node>::value &&
  852. is_nothrow_default_constructible<__node_allocator>::value &&
  853. is_nothrow_default_constructible<hasher>::value &&
  854. is_nothrow_default_constructible<key_equal>::value);
  855. _LIBCPP_INLINE_VISIBILITY
  856. __hash_table(const hasher& __hf, const key_equal& __eql);
  857. __hash_table(const hasher& __hf, const key_equal& __eql,
  858. const allocator_type& __a);
  859. explicit __hash_table(const allocator_type& __a);
  860. __hash_table(const __hash_table& __u);
  861. __hash_table(const __hash_table& __u, const allocator_type& __a);
  862. #ifndef _LIBCPP_CXX03_LANG
  863. __hash_table(__hash_table&& __u)
  864. _NOEXCEPT_(
  865. is_nothrow_move_constructible<__bucket_list>::value &&
  866. is_nothrow_move_constructible<__first_node>::value &&
  867. is_nothrow_move_constructible<__node_allocator>::value &&
  868. is_nothrow_move_constructible<hasher>::value &&
  869. is_nothrow_move_constructible<key_equal>::value);
  870. __hash_table(__hash_table&& __u, const allocator_type& __a);
  871. #endif // _LIBCPP_CXX03_LANG
  872. ~__hash_table();
  873. __hash_table& operator=(const __hash_table& __u);
  874. #ifndef _LIBCPP_CXX03_LANG
  875. _LIBCPP_INLINE_VISIBILITY
  876. __hash_table& operator=(__hash_table&& __u)
  877. _NOEXCEPT_(
  878. __node_traits::propagate_on_container_move_assignment::value &&
  879. is_nothrow_move_assignable<__node_allocator>::value &&
  880. is_nothrow_move_assignable<hasher>::value &&
  881. is_nothrow_move_assignable<key_equal>::value);
  882. #endif
  883. template <class _InputIterator>
  884. void __assign_unique(_InputIterator __first, _InputIterator __last);
  885. template <class _InputIterator>
  886. void __assign_multi(_InputIterator __first, _InputIterator __last);
  887. _LIBCPP_INLINE_VISIBILITY
  888. size_type max_size() const _NOEXCEPT
  889. {
  890. return allocator_traits<__pointer_allocator>::max_size(
  891. __bucket_list_.get_deleter().__alloc());
  892. }
  893. pair<iterator, bool> __node_insert_unique(__node_pointer __nd);
  894. iterator __node_insert_multi(__node_pointer __nd);
  895. iterator __node_insert_multi(const_iterator __p,
  896. __node_pointer __nd);
  897. #ifndef _LIBCPP_CXX03_LANG
  898. template <class _Key, class ..._Args>
  899. _LIBCPP_INLINE_VISIBILITY
  900. pair<iterator, bool> __emplace_unique_key_args(_Key const& __k, _Args&&... __args);
  901. template <class... _Args>
  902. _LIBCPP_INLINE_VISIBILITY
  903. pair<iterator, bool> __emplace_unique_impl(_Args&&... __args);
  904. template <class _Pp>
  905. _LIBCPP_INLINE_VISIBILITY
  906. pair<iterator, bool> __emplace_unique(_Pp&& __x) {
  907. return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x),
  908. __can_extract_key<_Pp, key_type>());
  909. }
  910. template <class _First, class _Second>
  911. _LIBCPP_INLINE_VISIBILITY
  912. typename enable_if<
  913. __can_extract_map_key<_First, key_type, __container_value_type>::value,
  914. pair<iterator, bool>
  915. >::type __emplace_unique(_First&& __f, _Second&& __s) {
  916. return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f),
  917. _VSTD::forward<_Second>(__s));
  918. }
  919. template <class... _Args>
  920. _LIBCPP_INLINE_VISIBILITY
  921. pair<iterator, bool> __emplace_unique(_Args&&... __args) {
  922. return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...);
  923. }
  924. template <class _Pp>
  925. _LIBCPP_INLINE_VISIBILITY
  926. pair<iterator, bool>
  927. __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) {
  928. return __emplace_unique_impl(_VSTD::forward<_Pp>(__x));
  929. }
  930. template <class _Pp>
  931. _LIBCPP_INLINE_VISIBILITY
  932. pair<iterator, bool>
  933. __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) {
  934. return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x));
  935. }
  936. template <class _Pp>
  937. _LIBCPP_INLINE_VISIBILITY
  938. pair<iterator, bool>
  939. __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) {
  940. return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x));
  941. }
  942. template <class... _Args>
  943. _LIBCPP_INLINE_VISIBILITY
  944. iterator __emplace_multi(_Args&&... __args);
  945. template <class... _Args>
  946. _LIBCPP_INLINE_VISIBILITY
  947. iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
  948. _LIBCPP_INLINE_VISIBILITY
  949. pair<iterator, bool>
  950. __insert_unique(__container_value_type&& __x) {
  951. return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _VSTD::move(__x));
  952. }
  953. template <class _Pp, class = typename enable_if<
  954. !__is_same_uncvref<_Pp, __container_value_type>::value
  955. >::type>
  956. _LIBCPP_INLINE_VISIBILITY
  957. pair<iterator, bool> __insert_unique(_Pp&& __x) {
  958. return __emplace_unique(_VSTD::forward<_Pp>(__x));
  959. }
  960. template <class _Pp>
  961. _LIBCPP_INLINE_VISIBILITY
  962. iterator __insert_multi(_Pp&& __x) {
  963. return __emplace_multi(_VSTD::forward<_Pp>(__x));
  964. }
  965. template <class _Pp>
  966. _LIBCPP_INLINE_VISIBILITY
  967. iterator __insert_multi(const_iterator __p, _Pp&& __x) {
  968. return __emplace_hint_multi(__p, _VSTD::forward<_Pp>(__x));
  969. }
  970. #else // !defined(_LIBCPP_CXX03_LANG)
  971. template <class _Key, class _Args>
  972. pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args);
  973. iterator __insert_multi(const __container_value_type& __x);
  974. iterator __insert_multi(const_iterator __p, const __container_value_type& __x);
  975. #endif
  976. _LIBCPP_INLINE_VISIBILITY
  977. pair<iterator, bool> __insert_unique(const __container_value_type& __x) {
  978. return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x);
  979. }
  980. void clear() _NOEXCEPT;
  981. void rehash(size_type __n);
  982. _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n)
  983. {rehash(static_cast<size_type>(ceil(__n / max_load_factor())));}
  984. _LIBCPP_INLINE_VISIBILITY
  985. size_type bucket_count() const _NOEXCEPT
  986. {
  987. return __bucket_list_.get_deleter().size();
  988. }
  989. _LIBCPP_INLINE_VISIBILITY
  990. iterator begin() _NOEXCEPT;
  991. _LIBCPP_INLINE_VISIBILITY
  992. iterator end() _NOEXCEPT;
  993. _LIBCPP_INLINE_VISIBILITY
  994. const_iterator begin() const _NOEXCEPT;
  995. _LIBCPP_INLINE_VISIBILITY
  996. const_iterator end() const _NOEXCEPT;
  997. template <class _Key>
  998. _LIBCPP_INLINE_VISIBILITY
  999. size_type bucket(const _Key& __k) const
  1000. {
  1001. _LIBCPP_ASSERT(bucket_count() > 0,
  1002. "unordered container::bucket(key) called when bucket_count() == 0");
  1003. return __constrain_hash(hash_function()(__k), bucket_count());
  1004. }
  1005. template <class _Key>
  1006. iterator find(const _Key& __x);
  1007. template <class _Key>
  1008. const_iterator find(const _Key& __x) const;
  1009. typedef __hash_node_destructor<__node_allocator> _Dp;
  1010. typedef unique_ptr<__node, _Dp> __node_holder;
  1011. iterator erase(const_iterator __p);
  1012. iterator erase(const_iterator __first, const_iterator __last);
  1013. template <class _Key>
  1014. size_type __erase_unique(const _Key& __k);
  1015. template <class _Key>
  1016. size_type __erase_multi(const _Key& __k);
  1017. __node_holder remove(const_iterator __p) _NOEXCEPT;
  1018. template <class _Key>
  1019. _LIBCPP_INLINE_VISIBILITY
  1020. size_type __count_unique(const _Key& __k) const;
  1021. template <class _Key>
  1022. size_type __count_multi(const _Key& __k) const;
  1023. template <class _Key>
  1024. pair<iterator, iterator>
  1025. __equal_range_unique(const _Key& __k);
  1026. template <class _Key>
  1027. pair<const_iterator, const_iterator>
  1028. __equal_range_unique(const _Key& __k) const;
  1029. template <class _Key>
  1030. pair<iterator, iterator>
  1031. __equal_range_multi(const _Key& __k);
  1032. template <class _Key>
  1033. pair<const_iterator, const_iterator>
  1034. __equal_range_multi(const _Key& __k) const;
  1035. void swap(__hash_table& __u)
  1036. #if _LIBCPP_STD_VER <= 11
  1037. _NOEXCEPT_(
  1038. __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
  1039. && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
  1040. || __is_nothrow_swappable<__pointer_allocator>::value)
  1041. && (!__node_traits::propagate_on_container_swap::value
  1042. || __is_nothrow_swappable<__node_allocator>::value)
  1043. );
  1044. #else
  1045. _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value);
  1046. #endif
  1047. _LIBCPP_INLINE_VISIBILITY
  1048. size_type max_bucket_count() const _NOEXCEPT
  1049. {return __pointer_alloc_traits::max_size(__bucket_list_.get_deleter().__alloc());}
  1050. size_type bucket_size(size_type __n) const;
  1051. _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT
  1052. {
  1053. size_type __bc = bucket_count();
  1054. return __bc != 0 ? (float)size() / __bc : 0.f;
  1055. }
  1056. _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT
  1057. {
  1058. _LIBCPP_ASSERT(__mlf > 0,
  1059. "unordered container::max_load_factor(lf) called with lf <= 0");
  1060. max_load_factor() = _VSTD::max(__mlf, load_factor());
  1061. }
  1062. _LIBCPP_INLINE_VISIBILITY
  1063. local_iterator
  1064. begin(size_type __n)
  1065. {
  1066. _LIBCPP_ASSERT(__n < bucket_count(),
  1067. "unordered container::begin(n) called with n >= bucket_count()");
  1068. #if _LIBCPP_DEBUG_LEVEL >= 2
  1069. return local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
  1070. #else
  1071. return local_iterator(__bucket_list_[__n], __n, bucket_count());
  1072. #endif
  1073. }
  1074. _LIBCPP_INLINE_VISIBILITY
  1075. local_iterator
  1076. end(size_type __n)
  1077. {
  1078. _LIBCPP_ASSERT(__n < bucket_count(),
  1079. "unordered container::end(n) called with n >= bucket_count()");
  1080. #if _LIBCPP_DEBUG_LEVEL >= 2
  1081. return local_iterator(nullptr, __n, bucket_count(), this);
  1082. #else
  1083. return local_iterator(nullptr, __n, bucket_count());
  1084. #endif
  1085. }
  1086. _LIBCPP_INLINE_VISIBILITY
  1087. const_local_iterator
  1088. cbegin(size_type __n) const
  1089. {
  1090. _LIBCPP_ASSERT(__n < bucket_count(),
  1091. "unordered container::cbegin(n) called with n >= bucket_count()");
  1092. #if _LIBCPP_DEBUG_LEVEL >= 2
  1093. return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
  1094. #else
  1095. return const_local_iterator(__bucket_list_[__n], __n, bucket_count());
  1096. #endif
  1097. }
  1098. _LIBCPP_INLINE_VISIBILITY
  1099. const_local_iterator
  1100. cend(size_type __n) const
  1101. {
  1102. _LIBCPP_ASSERT(__n < bucket_count(),
  1103. "unordered container::cend(n) called with n >= bucket_count()");
  1104. #if _LIBCPP_DEBUG_LEVEL >= 2
  1105. return const_local_iterator(nullptr, __n, bucket_count(), this);
  1106. #else
  1107. return const_local_iterator(nullptr, __n, bucket_count());
  1108. #endif
  1109. }
  1110. #if _LIBCPP_DEBUG_LEVEL >= 2
  1111. bool __dereferenceable(const const_iterator* __i) const;
  1112. bool __decrementable(const const_iterator* __i) const;
  1113. bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
  1114. bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
  1115. #endif // _LIBCPP_DEBUG_LEVEL >= 2
  1116. private:
  1117. void __rehash(size_type __n);
  1118. #ifndef _LIBCPP_CXX03_LANG
  1119. template <class ..._Args>
  1120. __node_holder __construct_node(_Args&& ...__args);
  1121. template <class _First, class ..._Rest>
  1122. __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest);
  1123. #else // _LIBCPP_CXX03_LANG
  1124. __node_holder __construct_node(const __container_value_type& __v);
  1125. __node_holder __construct_node_hash(size_t __hash, const __container_value_type& __v);
  1126. #endif
  1127. _LIBCPP_INLINE_VISIBILITY
  1128. void __copy_assign_alloc(const __hash_table& __u)
  1129. {__copy_assign_alloc(__u, integral_constant<bool,
  1130. __node_traits::propagate_on_container_copy_assignment::value>());}
  1131. void __copy_assign_alloc(const __hash_table& __u, true_type);
  1132. _LIBCPP_INLINE_VISIBILITY
  1133. void __copy_assign_alloc(const __hash_table&, false_type) {}
  1134. #ifndef _LIBCPP_CXX03_LANG
  1135. void __move_assign(__hash_table& __u, false_type);
  1136. void __move_assign(__hash_table& __u, true_type)
  1137. _NOEXCEPT_(
  1138. is_nothrow_move_assignable<__node_allocator>::value &&
  1139. is_nothrow_move_assignable<hasher>::value &&
  1140. is_nothrow_move_assignable<key_equal>::value);
  1141. _LIBCPP_INLINE_VISIBILITY
  1142. void __move_assign_alloc(__hash_table& __u)
  1143. _NOEXCEPT_(
  1144. !__node_traits::propagate_on_container_move_assignment::value ||
  1145. (is_nothrow_move_assignable<__pointer_allocator>::value &&
  1146. is_nothrow_move_assignable<__node_allocator>::value))
  1147. {__move_assign_alloc(__u, integral_constant<bool,
  1148. __node_traits::propagate_on_container_move_assignment::value>());}
  1149. _LIBCPP_INLINE_VISIBILITY
  1150. void __move_assign_alloc(__hash_table& __u, true_type)
  1151. _NOEXCEPT_(
  1152. is_nothrow_move_assignable<__pointer_allocator>::value &&
  1153. is_nothrow_move_assignable<__node_allocator>::value)
  1154. {
  1155. __bucket_list_.get_deleter().__alloc() =
  1156. _VSTD::move(__u.__bucket_list_.get_deleter().__alloc());
  1157. __node_alloc() = _VSTD::move(__u.__node_alloc());
  1158. }
  1159. _LIBCPP_INLINE_VISIBILITY
  1160. void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {}
  1161. #endif // _LIBCPP_CXX03_LANG
  1162. void __deallocate(__node_pointer __np) _NOEXCEPT;
  1163. __node_pointer __detach() _NOEXCEPT;
  1164. template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
  1165. template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
  1166. };
  1167. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1168. inline
  1169. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table()
  1170. _NOEXCEPT_(
  1171. is_nothrow_default_constructible<__bucket_list>::value &&
  1172. is_nothrow_default_constructible<__first_node>::value &&
  1173. is_nothrow_default_constructible<__node_allocator>::value &&
  1174. is_nothrow_default_constructible<hasher>::value &&
  1175. is_nothrow_default_constructible<key_equal>::value)
  1176. : __p2_(0),
  1177. __p3_(1.0f)
  1178. {
  1179. }
  1180. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1181. inline
  1182. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
  1183. const key_equal& __eql)
  1184. : __bucket_list_(nullptr, __bucket_list_deleter()),
  1185. __p1_(),
  1186. __p2_(0, __hf),
  1187. __p3_(1.0f, __eql)
  1188. {
  1189. }
  1190. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1191. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
  1192. const key_equal& __eql,
  1193. const allocator_type& __a)
  1194. : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
  1195. __p1_(__node_allocator(__a)),
  1196. __p2_(0, __hf),
  1197. __p3_(1.0f, __eql)
  1198. {
  1199. }
  1200. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1201. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a)
  1202. : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
  1203. __p1_(__node_allocator(__a)),
  1204. __p2_(0),
  1205. __p3_(1.0f)
  1206. {
  1207. }
  1208. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1209. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u)
  1210. : __bucket_list_(nullptr,
  1211. __bucket_list_deleter(allocator_traits<__pointer_allocator>::
  1212. select_on_container_copy_construction(
  1213. __u.__bucket_list_.get_deleter().__alloc()), 0)),
  1214. __p1_(allocator_traits<__node_allocator>::
  1215. select_on_container_copy_construction(__u.__node_alloc())),
  1216. __p2_(0, __u.hash_function()),
  1217. __p3_(__u.__p3_)
  1218. {
  1219. }
  1220. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1221. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u,
  1222. const allocator_type& __a)
  1223. : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
  1224. __p1_(__node_allocator(__a)),
  1225. __p2_(0, __u.hash_function()),
  1226. __p3_(__u.__p3_)
  1227. {
  1228. }
  1229. #ifndef _LIBCPP_CXX03_LANG
  1230. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1231. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u)
  1232. _NOEXCEPT_(
  1233. is_nothrow_move_constructible<__bucket_list>::value &&
  1234. is_nothrow_move_constructible<__first_node>::value &&
  1235. is_nothrow_move_constructible<__node_allocator>::value &&
  1236. is_nothrow_move_constructible<hasher>::value &&
  1237. is_nothrow_move_constructible<key_equal>::value)
  1238. : __bucket_list_(_VSTD::move(__u.__bucket_list_)),
  1239. __p1_(_VSTD::move(__u.__p1_)),
  1240. __p2_(_VSTD::move(__u.__p2_)),
  1241. __p3_(_VSTD::move(__u.__p3_))
  1242. {
  1243. if (size() > 0)
  1244. {
  1245. __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
  1246. static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
  1247. __u.__p1_.first().__next_ = nullptr;
  1248. __u.size() = 0;
  1249. }
  1250. }
  1251. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1252. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u,
  1253. const allocator_type& __a)
  1254. : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
  1255. __p1_(__node_allocator(__a)),
  1256. __p2_(0, _VSTD::move(__u.hash_function())),
  1257. __p3_(_VSTD::move(__u.__p3_))
  1258. {
  1259. if (__a == allocator_type(__u.__node_alloc()))
  1260. {
  1261. __bucket_list_.reset(__u.__bucket_list_.release());
  1262. __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
  1263. __u.__bucket_list_.get_deleter().size() = 0;
  1264. if (__u.size() > 0)
  1265. {
  1266. __p1_.first().__next_ = __u.__p1_.first().__next_;
  1267. __u.__p1_.first().__next_ = nullptr;
  1268. __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
  1269. static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
  1270. size() = __u.size();
  1271. __u.size() = 0;
  1272. }
  1273. }
  1274. }
  1275. #endif // _LIBCPP_CXX03_LANG
  1276. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1277. __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
  1278. {
  1279. static_assert((is_copy_constructible<key_equal>::value),
  1280. "Predicate must be copy-constructible.");
  1281. static_assert((is_copy_constructible<hasher>::value),
  1282. "Hasher must be copy-constructible.");
  1283. __deallocate(__p1_.first().__next_);
  1284. #if _LIBCPP_DEBUG_LEVEL >= 2
  1285. __get_db()->__erase_c(this);
  1286. #endif
  1287. }
  1288. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1289. void
  1290. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc(
  1291. const __hash_table& __u, true_type)
  1292. {
  1293. if (__node_alloc() != __u.__node_alloc())
  1294. {
  1295. clear();
  1296. __bucket_list_.reset();
  1297. __bucket_list_.get_deleter().size() = 0;
  1298. }
  1299. __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc();
  1300. __node_alloc() = __u.__node_alloc();
  1301. }
  1302. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1303. __hash_table<_Tp, _Hash, _Equal, _Alloc>&
  1304. __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u)
  1305. {
  1306. if (this != &__u)
  1307. {
  1308. __copy_assign_alloc(__u);
  1309. hash_function() = __u.hash_function();
  1310. key_eq() = __u.key_eq();
  1311. max_load_factor() = __u.max_load_factor();
  1312. __assign_multi(__u.begin(), __u.end());
  1313. }
  1314. return *this;
  1315. }
  1316. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1317. void
  1318. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate(__node_pointer __np)
  1319. _NOEXCEPT
  1320. {
  1321. __node_allocator& __na = __node_alloc();
  1322. while (__np != nullptr)
  1323. {
  1324. __node_pointer __next = __np->__next_;
  1325. #if _LIBCPP_DEBUG_LEVEL >= 2
  1326. __c_node* __c = __get_db()->__find_c_and_lock(this);
  1327. for (__i_node** __p = __c->end_; __p != __c->beg_; )
  1328. {
  1329. --__p;
  1330. iterator* __i = static_cast<iterator*>((*__p)->__i_);
  1331. if (__i->__node_ == __np)
  1332. {
  1333. (*__p)->__c_ = nullptr;
  1334. if (--__c->end_ != __p)
  1335. memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
  1336. }
  1337. }
  1338. __get_db()->unlock();
  1339. #endif
  1340. __node_traits::destroy(__na, _NodeTypes::__get_ptr(__np->__value_));
  1341. __node_traits::deallocate(__na, __np, 1);
  1342. __np = __next;
  1343. }
  1344. }
  1345. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1346. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_pointer
  1347. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT
  1348. {
  1349. size_type __bc = bucket_count();
  1350. for (size_type __i = 0; __i < __bc; ++__i)
  1351. __bucket_list_[__i] = nullptr;
  1352. size() = 0;
  1353. __node_pointer __cache = __p1_.first().__next_;
  1354. __p1_.first().__next_ = nullptr;
  1355. return __cache;
  1356. }
  1357. #ifndef _LIBCPP_CXX03_LANG
  1358. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1359. void
  1360. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
  1361. __hash_table& __u, true_type)
  1362. _NOEXCEPT_(
  1363. is_nothrow_move_assignable<__node_allocator>::value &&
  1364. is_nothrow_move_assignable<hasher>::value &&
  1365. is_nothrow_move_assignable<key_equal>::value)
  1366. {
  1367. clear();
  1368. __bucket_list_.reset(__u.__bucket_list_.release());
  1369. __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
  1370. __u.__bucket_list_.get_deleter().size() = 0;
  1371. __move_assign_alloc(__u);
  1372. size() = __u.size();
  1373. hash_function() = _VSTD::move(__u.hash_function());
  1374. max_load_factor() = __u.max_load_factor();
  1375. key_eq() = _VSTD::move(__u.key_eq());
  1376. __p1_.first().__next_ = __u.__p1_.first().__next_;
  1377. if (size() > 0)
  1378. {
  1379. __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
  1380. static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
  1381. __u.__p1_.first().__next_ = nullptr;
  1382. __u.size() = 0;
  1383. }
  1384. #if _LIBCPP_DEBUG_LEVEL >= 2
  1385. __get_db()->swap(this, &__u);
  1386. #endif
  1387. }
  1388. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1389. void
  1390. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
  1391. __hash_table& __u, false_type)
  1392. {
  1393. if (__node_alloc() == __u.__node_alloc())
  1394. __move_assign(__u, true_type());
  1395. else
  1396. {
  1397. hash_function() = _VSTD::move(__u.hash_function());
  1398. key_eq() = _VSTD::move(__u.key_eq());
  1399. max_load_factor() = __u.max_load_factor();
  1400. if (bucket_count() != 0)
  1401. {
  1402. __node_pointer __cache = __detach();
  1403. #ifndef _LIBCPP_NO_EXCEPTIONS
  1404. try
  1405. {
  1406. #endif // _LIBCPP_NO_EXCEPTIONS
  1407. const_iterator __i = __u.begin();
  1408. while (__cache != nullptr && __u.size() != 0)
  1409. {
  1410. __cache->__value_ = _VSTD::move(__u.remove(__i++)->__value_);
  1411. __node_pointer __next = __cache->__next_;
  1412. __node_insert_multi(__cache);
  1413. __cache = __next;
  1414. }
  1415. #ifndef _LIBCPP_NO_EXCEPTIONS
  1416. }
  1417. catch (...)
  1418. {
  1419. __deallocate(__cache);
  1420. throw;
  1421. }
  1422. #endif // _LIBCPP_NO_EXCEPTIONS
  1423. __deallocate(__cache);
  1424. }
  1425. const_iterator __i = __u.begin();
  1426. while (__u.size() != 0)
  1427. {
  1428. __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_));
  1429. __node_insert_multi(__h.get());
  1430. __h.release();
  1431. }
  1432. }
  1433. }
  1434. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1435. inline
  1436. __hash_table<_Tp, _Hash, _Equal, _Alloc>&
  1437. __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u)
  1438. _NOEXCEPT_(
  1439. __node_traits::propagate_on_container_move_assignment::value &&
  1440. is_nothrow_move_assignable<__node_allocator>::value &&
  1441. is_nothrow_move_assignable<hasher>::value &&
  1442. is_nothrow_move_assignable<key_equal>::value)
  1443. {
  1444. __move_assign(__u, integral_constant<bool,
  1445. __node_traits::propagate_on_container_move_assignment::value>());
  1446. return *this;
  1447. }
  1448. #endif // _LIBCPP_CXX03_LANG
  1449. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1450. template <class _InputIterator>
  1451. void
  1452. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first,
  1453. _InputIterator __last)
  1454. {
  1455. typedef iterator_traits<_InputIterator> _ITraits;
  1456. typedef typename _ITraits::value_type _ItValueType;
  1457. static_assert((is_same<_ItValueType, __container_value_type>::value),
  1458. "__assign_unique may only be called with the containers value type");
  1459. if (bucket_count() != 0)
  1460. {
  1461. __node_pointer __cache = __detach();
  1462. #ifndef _LIBCPP_NO_EXCEPTIONS
  1463. try
  1464. {
  1465. #endif // _LIBCPP_NO_EXCEPTIONS
  1466. for (; __cache != nullptr && __first != __last; ++__first)
  1467. {
  1468. __cache->__value_ = *__first;
  1469. __node_pointer __next = __cache->__next_;
  1470. __node_insert_unique(__cache);
  1471. __cache = __next;
  1472. }
  1473. #ifndef _LIBCPP_NO_EXCEPTIONS
  1474. }
  1475. catch (...)
  1476. {
  1477. __deallocate(__cache);
  1478. throw;
  1479. }
  1480. #endif // _LIBCPP_NO_EXCEPTIONS
  1481. __deallocate(__cache);
  1482. }
  1483. for (; __first != __last; ++__first)
  1484. __insert_unique(*__first);
  1485. }
  1486. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1487. template <class _InputIterator>
  1488. void
  1489. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first,
  1490. _InputIterator __last)
  1491. {
  1492. typedef iterator_traits<_InputIterator> _ITraits;
  1493. typedef typename _ITraits::value_type _ItValueType;
  1494. static_assert((is_same<_ItValueType, __container_value_type>::value ||
  1495. is_same<_ItValueType, __node_value_type>::value),
  1496. "__assign_multi may only be called with the containers value type"
  1497. " or the nodes value type");
  1498. if (bucket_count() != 0)
  1499. {
  1500. __node_pointer __cache = __detach();
  1501. #ifndef _LIBCPP_NO_EXCEPTIONS
  1502. try
  1503. {
  1504. #endif // _LIBCPP_NO_EXCEPTIONS
  1505. for (; __cache != nullptr && __first != __last; ++__first)
  1506. {
  1507. __cache->__value_ = *__first;
  1508. __node_pointer __next = __cache->__next_;
  1509. __node_insert_multi(__cache);
  1510. __cache = __next;
  1511. }
  1512. #ifndef _LIBCPP_NO_EXCEPTIONS
  1513. }
  1514. catch (...)
  1515. {
  1516. __deallocate(__cache);
  1517. throw;
  1518. }
  1519. #endif // _LIBCPP_NO_EXCEPTIONS
  1520. __deallocate(__cache);
  1521. }
  1522. for (; __first != __last; ++__first)
  1523. __insert_multi(_NodeTypes::__get_value(*__first));
  1524. }
  1525. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1526. inline
  1527. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
  1528. __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT
  1529. {
  1530. #if _LIBCPP_DEBUG_LEVEL >= 2
  1531. return iterator(__p1_.first().__next_, this);
  1532. #else
  1533. return iterator(__p1_.first().__next_);
  1534. #endif
  1535. }
  1536. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1537. inline
  1538. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
  1539. __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT
  1540. {
  1541. #if _LIBCPP_DEBUG_LEVEL >= 2
  1542. return iterator(nullptr, this);
  1543. #else
  1544. return iterator(nullptr);
  1545. #endif
  1546. }
  1547. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1548. inline
  1549. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
  1550. __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT
  1551. {
  1552. #if _LIBCPP_DEBUG_LEVEL >= 2
  1553. return const_iterator(__p1_.first().__next_, this);
  1554. #else
  1555. return const_iterator(__p1_.first().__next_);
  1556. #endif
  1557. }
  1558. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1559. inline
  1560. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
  1561. __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT
  1562. {
  1563. #if _LIBCPP_DEBUG_LEVEL >= 2
  1564. return const_iterator(nullptr, this);
  1565. #else
  1566. return const_iterator(nullptr);
  1567. #endif
  1568. }
  1569. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1570. void
  1571. __hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT
  1572. {
  1573. if (size() > 0)
  1574. {
  1575. __deallocate(__p1_.first().__next_);
  1576. __p1_.first().__next_ = nullptr;
  1577. size_type __bc = bucket_count();
  1578. for (size_type __i = 0; __i < __bc; ++__i)
  1579. __bucket_list_[__i] = nullptr;
  1580. size() = 0;
  1581. }
  1582. }
  1583. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1584. pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
  1585. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd)
  1586. {
  1587. __nd->__hash_ = hash_function()(__nd->__value_);
  1588. size_type __bc = bucket_count();
  1589. bool __inserted = false;
  1590. __node_pointer __ndptr;
  1591. size_t __chash;
  1592. if (__bc != 0)
  1593. {
  1594. __chash = __constrain_hash(__nd->__hash_, __bc);
  1595. __ndptr = __bucket_list_[__chash];
  1596. if (__ndptr != nullptr)
  1597. {
  1598. for (__ndptr = __ndptr->__next_; __ndptr != nullptr &&
  1599. __constrain_hash(__ndptr->__hash_, __bc) == __chash;
  1600. __ndptr = __ndptr->__next_)
  1601. {
  1602. if (key_eq()(__ndptr->__value_, __nd->__value_))
  1603. goto __done;
  1604. }
  1605. }
  1606. }
  1607. {
  1608. if (size()+1 > __bc * max_load_factor() || __bc == 0)
  1609. {
  1610. rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
  1611. size_type(ceil(float(size() + 1) / max_load_factor()))));
  1612. __bc = bucket_count();
  1613. __chash = __constrain_hash(__nd->__hash_, __bc);
  1614. }
  1615. // insert_after __bucket_list_[__chash], or __first_node if bucket is null
  1616. __node_pointer __pn = __bucket_list_[__chash];
  1617. if (__pn == nullptr)
  1618. {
  1619. __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
  1620. __nd->__next_ = __pn->__next_;
  1621. __pn->__next_ = __nd;
  1622. // fix up __bucket_list_
  1623. __bucket_list_[__chash] = __pn;
  1624. if (__nd->__next_ != nullptr)
  1625. __bucket_list_[__constrain_hash(__nd->__next_->__hash_, __bc)] = __nd;
  1626. }
  1627. else
  1628. {
  1629. __nd->__next_ = __pn->__next_;
  1630. __pn->__next_ = __nd;
  1631. }
  1632. __ndptr = __nd;
  1633. // increment size
  1634. ++size();
  1635. __inserted = true;
  1636. }
  1637. __done:
  1638. #if _LIBCPP_DEBUG_LEVEL >= 2
  1639. return pair<iterator, bool>(iterator(__ndptr, this), __inserted);
  1640. #else
  1641. return pair<iterator, bool>(iterator(__ndptr), __inserted);
  1642. #endif
  1643. }
  1644. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1645. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
  1646. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp)
  1647. {
  1648. __cp->__hash_ = hash_function()(__cp->__value_);
  1649. size_type __bc = bucket_count();
  1650. if (size()+1 > __bc * max_load_factor() || __bc == 0)
  1651. {
  1652. rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
  1653. size_type(ceil(float(size() + 1) / max_load_factor()))));
  1654. __bc = bucket_count();
  1655. }
  1656. size_t __chash = __constrain_hash(__cp->__hash_, __bc);
  1657. __node_pointer __pn = __bucket_list_[__chash];
  1658. if (__pn == nullptr)
  1659. {
  1660. __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
  1661. __cp->__next_ = __pn->__next_;
  1662. __pn->__next_ = __cp;
  1663. // fix up __bucket_list_
  1664. __bucket_list_[__chash] = __pn;
  1665. if (__cp->__next_ != nullptr)
  1666. __bucket_list_[__constrain_hash(__cp->__next_->__hash_, __bc)] = __cp;
  1667. }
  1668. else
  1669. {
  1670. for (bool __found = false; __pn->__next_ != nullptr &&
  1671. __constrain_hash(__pn->__next_->__hash_, __bc) == __chash;
  1672. __pn = __pn->__next_)
  1673. {
  1674. // __found key_eq() action
  1675. // false false loop
  1676. // true true loop
  1677. // false true set __found to true
  1678. // true false break
  1679. if (__found != (__pn->__next_->__hash_ == __cp->__hash_ &&
  1680. key_eq()(__pn->__next_->__value_, __cp->__value_)))
  1681. {
  1682. if (!__found)
  1683. __found = true;
  1684. else
  1685. break;
  1686. }
  1687. }
  1688. __cp->__next_ = __pn->__next_;
  1689. __pn->__next_ = __cp;
  1690. if (__cp->__next_ != nullptr)
  1691. {
  1692. size_t __nhash = __constrain_hash(__cp->__next_->__hash_, __bc);
  1693. if (__nhash != __chash)
  1694. __bucket_list_[__nhash] = __cp;
  1695. }
  1696. }
  1697. ++size();
  1698. #if _LIBCPP_DEBUG_LEVEL >= 2
  1699. return iterator(__cp, this);
  1700. #else
  1701. return iterator(__cp);
  1702. #endif
  1703. }
  1704. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1705. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
  1706. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
  1707. const_iterator __p, __node_pointer __cp)
  1708. {
  1709. #if _LIBCPP_DEBUG_LEVEL >= 2
  1710. _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
  1711. "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
  1712. " referring to this unordered container");
  1713. #endif
  1714. if (__p != end() && key_eq()(*__p, __cp->__value_))
  1715. {
  1716. __node_pointer __np = __p.__node_;
  1717. __cp->__hash_ = __np->__hash_;
  1718. size_type __bc = bucket_count();
  1719. if (size()+1 > __bc * max_load_factor() || __bc == 0)
  1720. {
  1721. rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
  1722. size_type(ceil(float(size() + 1) / max_load_factor()))));
  1723. __bc = bucket_count();
  1724. }
  1725. size_t __chash = __constrain_hash(__cp->__hash_, __bc);
  1726. __node_pointer __pp = __bucket_list_[__chash];
  1727. while (__pp->__next_ != __np)
  1728. __pp = __pp->__next_;
  1729. __cp->__next_ = __np;
  1730. __pp->__next_ = __cp;
  1731. ++size();
  1732. #if _LIBCPP_DEBUG_LEVEL >= 2
  1733. return iterator(__cp, this);
  1734. #else
  1735. return iterator(__cp);
  1736. #endif
  1737. }
  1738. return __node_insert_multi(__cp);
  1739. }
  1740. #ifndef _LIBCPP_CXX03_LANG
  1741. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1742. template <class _Key, class ..._Args>
  1743. _LIBCPP_INLINE_VISIBILITY
  1744. pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
  1745. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args)
  1746. #else
  1747. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1748. template <class _Key, class _Args>
  1749. _LIBCPP_INLINE_VISIBILITY
  1750. pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
  1751. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args)
  1752. #endif
  1753. {
  1754. size_t __hash = hash_function()(__k);
  1755. size_type __bc = bucket_count();
  1756. bool __inserted = false;
  1757. __node_pointer __nd;
  1758. size_t __chash;
  1759. if (__bc != 0)
  1760. {
  1761. __chash = __constrain_hash(__hash, __bc);
  1762. __nd = __bucket_list_[__chash];
  1763. if (__nd != nullptr)
  1764. {
  1765. for (__nd = __nd->__next_; __nd != nullptr &&
  1766. __constrain_hash(__nd->__hash_, __bc) == __chash;
  1767. __nd = __nd->__next_)
  1768. {
  1769. if (key_eq()(__nd->__value_, __k))
  1770. goto __done;
  1771. }
  1772. }
  1773. }
  1774. {
  1775. #ifndef _LIBCPP_CXX03_LANG
  1776. __node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...);
  1777. #else
  1778. __node_holder __h = __construct_node_hash(__hash, __args);
  1779. #endif
  1780. if (size()+1 > __bc * max_load_factor() || __bc == 0)
  1781. {
  1782. rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
  1783. size_type(ceil(float(size() + 1) / max_load_factor()))));
  1784. __bc = bucket_count();
  1785. __chash = __constrain_hash(__hash, __bc);
  1786. }
  1787. // insert_after __bucket_list_[__chash], or __first_node if bucket is null
  1788. __node_pointer __pn = __bucket_list_[__chash];
  1789. if (__pn == nullptr)
  1790. {
  1791. __pn = static_cast<__node_pointer>(static_cast<__void_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())));
  1792. __h->__next_ = __pn->__next_;
  1793. __pn->__next_ = __h.get();
  1794. // fix up __bucket_list_
  1795. __bucket_list_[__chash] = __pn;
  1796. if (__h->__next_ != nullptr)
  1797. __bucket_list_[__constrain_hash(__h->__next_->__hash_, __bc)] = __h.get();
  1798. }
  1799. else
  1800. {
  1801. __h->__next_ = __pn->__next_;
  1802. __pn->__next_ = __h.get();
  1803. }
  1804. __nd = __h.release();
  1805. // increment size
  1806. ++size();
  1807. __inserted = true;
  1808. }
  1809. __done:
  1810. #if _LIBCPP_DEBUG_LEVEL >= 2
  1811. return pair<iterator, bool>(iterator(__nd, this), __inserted);
  1812. #else
  1813. return pair<iterator, bool>(iterator(__nd), __inserted);
  1814. #endif
  1815. }
  1816. #ifndef _LIBCPP_CXX03_LANG
  1817. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1818. template <class... _Args>
  1819. pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
  1820. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args)
  1821. {
  1822. __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
  1823. pair<iterator, bool> __r = __node_insert_unique(__h.get());
  1824. if (__r.second)
  1825. __h.release();
  1826. return __r;
  1827. }
  1828. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1829. template <class... _Args>
  1830. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
  1831. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args)
  1832. {
  1833. __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
  1834. iterator __r = __node_insert_multi(__h.get());
  1835. __h.release();
  1836. return __r;
  1837. }
  1838. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1839. template <class... _Args>
  1840. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
  1841. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(
  1842. const_iterator __p, _Args&&... __args)
  1843. {
  1844. #if _LIBCPP_DEBUG_LEVEL >= 2
  1845. _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
  1846. "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
  1847. " referring to this unordered container");
  1848. #endif
  1849. __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
  1850. iterator __r = __node_insert_multi(__p, __h.get());
  1851. __h.release();
  1852. return __r;
  1853. }
  1854. #else // _LIBCPP_CXX03_LANG
  1855. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1856. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
  1857. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const __container_value_type& __x)
  1858. {
  1859. __node_holder __h = __construct_node(__x);
  1860. iterator __r = __node_insert_multi(__h.get());
  1861. __h.release();
  1862. return __r;
  1863. }
  1864. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1865. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
  1866. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
  1867. const __container_value_type& __x)
  1868. {
  1869. #if _LIBCPP_DEBUG_LEVEL >= 2
  1870. _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
  1871. "unordered container::insert(const_iterator, lvalue) called with an iterator not"
  1872. " referring to this unordered container");
  1873. #endif
  1874. __node_holder __h = __construct_node(__x);
  1875. iterator __r = __node_insert_multi(__p, __h.get());
  1876. __h.release();
  1877. return __r;
  1878. }
  1879. #endif // _LIBCPP_CXX03_LANG
  1880. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1881. void
  1882. __hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
  1883. {
  1884. if (__n == 1)
  1885. __n = 2;
  1886. else if (__n & (__n - 1))
  1887. __n = __next_prime(__n);
  1888. size_type __bc = bucket_count();
  1889. if (__n > __bc)
  1890. __rehash(__n);
  1891. else if (__n < __bc)
  1892. {
  1893. __n = _VSTD::max<size_type>
  1894. (
  1895. __n,
  1896. __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) :
  1897. __next_prime(size_t(ceil(float(size()) / max_load_factor())))
  1898. );
  1899. if (__n < __bc)
  1900. __rehash(__n);
  1901. }
  1902. }
  1903. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1904. void
  1905. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
  1906. {
  1907. #if _LIBCPP_DEBUG_LEVEL >= 2
  1908. __get_db()->__invalidate_all(this);
  1909. #endif // _LIBCPP_DEBUG_LEVEL >= 2
  1910. __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc();
  1911. __bucket_list_.reset(__nbc > 0 ?
  1912. __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr);
  1913. __bucket_list_.get_deleter().size() = __nbc;
  1914. if (__nbc > 0)
  1915. {
  1916. for (size_type __i = 0; __i < __nbc; ++__i)
  1917. __bucket_list_[__i] = nullptr;
  1918. __node_pointer __pp(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())));
  1919. __node_pointer __cp = __pp->__next_;
  1920. if (__cp != nullptr)
  1921. {
  1922. size_type __chash = __constrain_hash(__cp->__hash_, __nbc);
  1923. __bucket_list_[__chash] = __pp;
  1924. size_type __phash = __chash;
  1925. for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
  1926. __cp = __pp->__next_)
  1927. {
  1928. __chash = __constrain_hash(__cp->__hash_, __nbc);
  1929. if (__chash == __phash)
  1930. __pp = __cp;
  1931. else
  1932. {
  1933. if (__bucket_list_[__chash] == nullptr)
  1934. {
  1935. __bucket_list_[__chash] = __pp;
  1936. __pp = __cp;
  1937. __phash = __chash;
  1938. }
  1939. else
  1940. {
  1941. __node_pointer __np = __cp;
  1942. for (; __np->__next_ != nullptr &&
  1943. key_eq()(__cp->__value_, __np->__next_->__value_);
  1944. __np = __np->__next_)
  1945. ;
  1946. __pp->__next_ = __np->__next_;
  1947. __np->__next_ = __bucket_list_[__chash]->__next_;
  1948. __bucket_list_[__chash]->__next_ = __cp;
  1949. }
  1950. }
  1951. }
  1952. }
  1953. }
  1954. }
  1955. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1956. template <class _Key>
  1957. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
  1958. __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k)
  1959. {
  1960. size_t __hash = hash_function()(__k);
  1961. size_type __bc = bucket_count();
  1962. if (__bc != 0)
  1963. {
  1964. size_t __chash = __constrain_hash(__hash, __bc);
  1965. __node_pointer __nd = __bucket_list_[__chash];
  1966. if (__nd != nullptr)
  1967. {
  1968. for (__nd = __nd->__next_; __nd != nullptr &&
  1969. (__nd->__hash_ == __hash
  1970. || __constrain_hash(__nd->__hash_, __bc) == __chash);
  1971. __nd = __nd->__next_)
  1972. {
  1973. if ((__nd->__hash_ == __hash) && key_eq()(__nd->__value_, __k))
  1974. #if _LIBCPP_DEBUG_LEVEL >= 2
  1975. return iterator(__nd, this);
  1976. #else
  1977. return iterator(__nd);
  1978. #endif
  1979. }
  1980. }
  1981. }
  1982. return end();
  1983. }
  1984. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  1985. template <class _Key>
  1986. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
  1987. __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const
  1988. {
  1989. size_t __hash = hash_function()(__k);
  1990. size_type __bc = bucket_count();
  1991. if (__bc != 0)
  1992. {
  1993. size_t __chash = __constrain_hash(__hash, __bc);
  1994. __node_const_pointer __nd = __bucket_list_[__chash];
  1995. if (__nd != nullptr)
  1996. {
  1997. for (__nd = __nd->__next_; __nd != nullptr &&
  1998. (__hash == __nd->__hash_ || __constrain_hash(__nd->__hash_, __bc) == __chash);
  1999. __nd = __nd->__next_)
  2000. {
  2001. if ((__nd->__hash_ == __hash) && key_eq()(__nd->__value_, __k))
  2002. #if _LIBCPP_DEBUG_LEVEL >= 2
  2003. return const_iterator(__nd, this);
  2004. #else
  2005. return const_iterator(__nd);
  2006. #endif
  2007. }
  2008. }
  2009. }
  2010. return end();
  2011. }
  2012. #ifndef _LIBCPP_CXX03_LANG
  2013. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2014. template <class ..._Args>
  2015. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
  2016. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args)
  2017. {
  2018. static_assert(!__is_hash_value_type<_Args...>::value,
  2019. "Construct cannot be called with a hash value type");
  2020. __node_allocator& __na = __node_alloc();
  2021. __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
  2022. __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...);
  2023. __h.get_deleter().__value_constructed = true;
  2024. __h->__hash_ = hash_function()(__h->__value_);
  2025. __h->__next_ = nullptr;
  2026. return __h;
  2027. }
  2028. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2029. template <class _First, class ..._Rest>
  2030. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
  2031. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(
  2032. size_t __hash, _First&& __f, _Rest&& ...__rest)
  2033. {
  2034. static_assert(!__is_hash_value_type<_First, _Rest...>::value,
  2035. "Construct cannot be called with a hash value type");
  2036. __node_allocator& __na = __node_alloc();
  2037. __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
  2038. __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_),
  2039. _VSTD::forward<_First>(__f),
  2040. _VSTD::forward<_Rest>(__rest)...);
  2041. __h.get_deleter().__value_constructed = true;
  2042. __h->__hash_ = __hash;
  2043. __h->__next_ = nullptr;
  2044. return __h;
  2045. }
  2046. #else // _LIBCPP_CXX03_LANG
  2047. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2048. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
  2049. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const __container_value_type& __v)
  2050. {
  2051. __node_allocator& __na = __node_alloc();
  2052. __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
  2053. __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
  2054. __h.get_deleter().__value_constructed = true;
  2055. __h->__hash_ = hash_function()(__h->__value_);
  2056. __h->__next_ = nullptr;
  2057. return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
  2058. }
  2059. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2060. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
  2061. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash,
  2062. const __container_value_type& __v)
  2063. {
  2064. __node_allocator& __na = __node_alloc();
  2065. __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
  2066. __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
  2067. __h.get_deleter().__value_constructed = true;
  2068. __h->__hash_ = __hash;
  2069. __h->__next_ = nullptr;
  2070. return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
  2071. }
  2072. #endif // _LIBCPP_CXX03_LANG
  2073. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2074. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
  2075. __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
  2076. {
  2077. __node_pointer __np = __p.__node_;
  2078. #if _LIBCPP_DEBUG_LEVEL >= 2
  2079. _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
  2080. "unordered container erase(iterator) called with an iterator not"
  2081. " referring to this container");
  2082. _LIBCPP_ASSERT(__p != end(),
  2083. "unordered container erase(iterator) called with a non-dereferenceable iterator");
  2084. iterator __r(__np, this);
  2085. #else
  2086. iterator __r(__np);
  2087. #endif
  2088. ++__r;
  2089. remove(__p);
  2090. return __r;
  2091. }
  2092. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2093. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
  2094. __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
  2095. const_iterator __last)
  2096. {
  2097. #if _LIBCPP_DEBUG_LEVEL >= 2
  2098. _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
  2099. "unodered container::erase(iterator, iterator) called with an iterator not"
  2100. " referring to this unodered container");
  2101. _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
  2102. "unodered container::erase(iterator, iterator) called with an iterator not"
  2103. " referring to this unodered container");
  2104. #endif
  2105. for (const_iterator __p = __first; __first != __last; __p = __first)
  2106. {
  2107. ++__first;
  2108. erase(__p);
  2109. }
  2110. __node_pointer __np = __last.__node_;
  2111. #if _LIBCPP_DEBUG_LEVEL >= 2
  2112. return iterator (__np, this);
  2113. #else
  2114. return iterator (__np);
  2115. #endif
  2116. }
  2117. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2118. template <class _Key>
  2119. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
  2120. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k)
  2121. {
  2122. iterator __i = find(__k);
  2123. if (__i == end())
  2124. return 0;
  2125. erase(__i);
  2126. return 1;
  2127. }
  2128. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2129. template <class _Key>
  2130. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
  2131. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k)
  2132. {
  2133. size_type __r = 0;
  2134. iterator __i = find(__k);
  2135. if (__i != end())
  2136. {
  2137. iterator __e = end();
  2138. do
  2139. {
  2140. erase(__i++);
  2141. ++__r;
  2142. } while (__i != __e && key_eq()(*__i, __k));
  2143. }
  2144. return __r;
  2145. }
  2146. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2147. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
  2148. __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT
  2149. {
  2150. // current node
  2151. __node_pointer __cn = __p.__node_;
  2152. size_type __bc = bucket_count();
  2153. size_t __chash = __constrain_hash(__cn->__hash_, __bc);
  2154. // find previous node
  2155. __node_pointer __pn = __bucket_list_[__chash];
  2156. for (; __pn->__next_ != __cn; __pn = __pn->__next_)
  2157. ;
  2158. // Fix up __bucket_list_
  2159. // if __pn is not in same bucket (before begin is not in same bucket) &&
  2160. // if __cn->__next_ is not in same bucket (nullptr is not in same bucket)
  2161. if (__pn == static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()))
  2162. || __constrain_hash(__pn->__hash_, __bc) != __chash)
  2163. {
  2164. if (__cn->__next_ == nullptr || __constrain_hash(__cn->__next_->__hash_, __bc) != __chash)
  2165. __bucket_list_[__chash] = nullptr;
  2166. }
  2167. // if __cn->__next_ is not in same bucket (nullptr is in same bucket)
  2168. if (__cn->__next_ != nullptr)
  2169. {
  2170. size_t __nhash = __constrain_hash(__cn->__next_->__hash_, __bc);
  2171. if (__nhash != __chash)
  2172. __bucket_list_[__nhash] = __pn;
  2173. }
  2174. // remove __cn
  2175. __pn->__next_ = __cn->__next_;
  2176. __cn->__next_ = nullptr;
  2177. --size();
  2178. #if _LIBCPP_DEBUG_LEVEL >= 2
  2179. __c_node* __c = __get_db()->__find_c_and_lock(this);
  2180. for (__i_node** __p = __c->end_; __p != __c->beg_; )
  2181. {
  2182. --__p;
  2183. iterator* __i = static_cast<iterator*>((*__p)->__i_);
  2184. if (__i->__node_ == __cn)
  2185. {
  2186. (*__p)->__c_ = nullptr;
  2187. if (--__c->end_ != __p)
  2188. memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
  2189. }
  2190. }
  2191. __get_db()->unlock();
  2192. #endif
  2193. return __node_holder(__cn, _Dp(__node_alloc(), true));
  2194. }
  2195. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2196. template <class _Key>
  2197. inline
  2198. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
  2199. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const
  2200. {
  2201. return static_cast<size_type>(find(__k) != end());
  2202. }
  2203. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2204. template <class _Key>
  2205. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
  2206. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const
  2207. {
  2208. size_type __r = 0;
  2209. const_iterator __i = find(__k);
  2210. if (__i != end())
  2211. {
  2212. const_iterator __e = end();
  2213. do
  2214. {
  2215. ++__i;
  2216. ++__r;
  2217. } while (__i != __e && key_eq()(*__i, __k));
  2218. }
  2219. return __r;
  2220. }
  2221. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2222. template <class _Key>
  2223. pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
  2224. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
  2225. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
  2226. const _Key& __k)
  2227. {
  2228. iterator __i = find(__k);
  2229. iterator __j = __i;
  2230. if (__i != end())
  2231. ++__j;
  2232. return pair<iterator, iterator>(__i, __j);
  2233. }
  2234. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2235. template <class _Key>
  2236. pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
  2237. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
  2238. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
  2239. const _Key& __k) const
  2240. {
  2241. const_iterator __i = find(__k);
  2242. const_iterator __j = __i;
  2243. if (__i != end())
  2244. ++__j;
  2245. return pair<const_iterator, const_iterator>(__i, __j);
  2246. }
  2247. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2248. template <class _Key>
  2249. pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
  2250. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
  2251. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
  2252. const _Key& __k)
  2253. {
  2254. iterator __i = find(__k);
  2255. iterator __j = __i;
  2256. if (__i != end())
  2257. {
  2258. iterator __e = end();
  2259. do
  2260. {
  2261. ++__j;
  2262. } while (__j != __e && key_eq()(*__j, __k));
  2263. }
  2264. return pair<iterator, iterator>(__i, __j);
  2265. }
  2266. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2267. template <class _Key>
  2268. pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
  2269. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
  2270. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
  2271. const _Key& __k) const
  2272. {
  2273. const_iterator __i = find(__k);
  2274. const_iterator __j = __i;
  2275. if (__i != end())
  2276. {
  2277. const_iterator __e = end();
  2278. do
  2279. {
  2280. ++__j;
  2281. } while (__j != __e && key_eq()(*__j, __k));
  2282. }
  2283. return pair<const_iterator, const_iterator>(__i, __j);
  2284. }
  2285. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2286. void
  2287. __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
  2288. #if _LIBCPP_STD_VER <= 11
  2289. _NOEXCEPT_(
  2290. __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
  2291. && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
  2292. || __is_nothrow_swappable<__pointer_allocator>::value)
  2293. && (!__node_traits::propagate_on_container_swap::value
  2294. || __is_nothrow_swappable<__node_allocator>::value)
  2295. )
  2296. #else
  2297. _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value)
  2298. #endif
  2299. {
  2300. {
  2301. __node_pointer_pointer __npp = __bucket_list_.release();
  2302. __bucket_list_.reset(__u.__bucket_list_.release());
  2303. __u.__bucket_list_.reset(__npp);
  2304. }
  2305. _VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size());
  2306. __swap_allocator(__bucket_list_.get_deleter().__alloc(),
  2307. __u.__bucket_list_.get_deleter().__alloc());
  2308. __swap_allocator(__node_alloc(), __u.__node_alloc());
  2309. _VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_);
  2310. __p2_.swap(__u.__p2_);
  2311. __p3_.swap(__u.__p3_);
  2312. if (size() > 0)
  2313. __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
  2314. static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
  2315. if (__u.size() > 0)
  2316. __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash_, __u.bucket_count())] =
  2317. static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__u.__p1_.first()));
  2318. #if _LIBCPP_DEBUG_LEVEL >= 2
  2319. __get_db()->swap(this, &__u);
  2320. #endif
  2321. }
  2322. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2323. typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
  2324. __hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const
  2325. {
  2326. _LIBCPP_ASSERT(__n < bucket_count(),
  2327. "unordered container::bucket_size(n) called with n >= bucket_count()");
  2328. __node_const_pointer __np = __bucket_list_[__n];
  2329. size_type __bc = bucket_count();
  2330. size_type __r = 0;
  2331. if (__np != nullptr)
  2332. {
  2333. for (__np = __np->__next_; __np != nullptr &&
  2334. __constrain_hash(__np->__hash_, __bc) == __n;
  2335. __np = __np->__next_, ++__r)
  2336. ;
  2337. }
  2338. return __r;
  2339. }
  2340. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2341. inline _LIBCPP_INLINE_VISIBILITY
  2342. void
  2343. swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x,
  2344. __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y)
  2345. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  2346. {
  2347. __x.swap(__y);
  2348. }
  2349. #if _LIBCPP_DEBUG_LEVEL >= 2
  2350. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2351. bool
  2352. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const
  2353. {
  2354. return __i->__node_ != nullptr;
  2355. }
  2356. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2357. bool
  2358. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const
  2359. {
  2360. return false;
  2361. }
  2362. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2363. bool
  2364. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
  2365. {
  2366. return false;
  2367. }
  2368. template <class _Tp, class _Hash, class _Equal, class _Alloc>
  2369. bool
  2370. __hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
  2371. {
  2372. return false;
  2373. }
  2374. #endif // _LIBCPP_DEBUG_LEVEL >= 2
  2375. _LIBCPP_END_NAMESPACE_STD
  2376. #endif // _LIBCPP__HASH_TABLE