hash_set 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. // -*- C++ -*-
  2. //===------------------------- hash_set ------------------------------------===//
  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_SET
  11. #define _LIBCPP_HASH_SET
  12. /*
  13. hash_set synopsis
  14. namespace __gnu_cxx
  15. {
  16. template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
  17. class Alloc = allocator<Value>>
  18. class hash_set
  19. {
  20. public:
  21. // types
  22. typedef Value key_type;
  23. typedef key_type value_type;
  24. typedef Hash hasher;
  25. typedef Pred key_equal;
  26. typedef Alloc allocator_type;
  27. typedef value_type& reference;
  28. typedef const value_type& const_reference;
  29. typedef typename allocator_traits<allocator_type>::pointer pointer;
  30. typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
  31. typedef typename allocator_traits<allocator_type>::size_type size_type;
  32. typedef typename allocator_traits<allocator_type>::difference_type difference_type;
  33. typedef /unspecified/ iterator;
  34. typedef /unspecified/ const_iterator;
  35. explicit hash_set(size_type n = 193, const hasher& hf = hasher(),
  36. const key_equal& eql = key_equal(),
  37. const allocator_type& a = allocator_type());
  38. template <class InputIterator>
  39. hash_set(InputIterator f, InputIterator l,
  40. size_type n = 193, const hasher& hf = hasher(),
  41. const key_equal& eql = key_equal(),
  42. const allocator_type& a = allocator_type());
  43. hash_set(const hash_set&);
  44. ~hash_set();
  45. hash_set& operator=(const hash_set&);
  46. allocator_type get_allocator() const;
  47. bool empty() const;
  48. size_type size() const;
  49. size_type max_size() const;
  50. iterator begin();
  51. iterator end();
  52. const_iterator begin() const;
  53. const_iterator end() const;
  54. pair<iterator, bool> insert(const value_type& obj);
  55. template <class InputIterator>
  56. void insert(InputIterator first, InputIterator last);
  57. void erase(const_iterator position);
  58. size_type erase(const key_type& k);
  59. void erase(const_iterator first, const_iterator last);
  60. void clear();
  61. void swap(hash_set&);
  62. hasher hash_funct() const;
  63. key_equal key_eq() const;
  64. iterator find(const key_type& k);
  65. const_iterator find(const key_type& k) const;
  66. size_type count(const key_type& k) const;
  67. pair<iterator, iterator> equal_range(const key_type& k);
  68. pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
  69. size_type bucket_count() const;
  70. size_type max_bucket_count() const;
  71. size_type elems_in_bucket(size_type n) const;
  72. void resize(size_type n);
  73. };
  74. template <class Value, class Hash, class Pred, class Alloc>
  75. void swap(hash_set<Value, Hash, Pred, Alloc>& x,
  76. hash_set<Value, Hash, Pred, Alloc>& y);
  77. template <class Value, class Hash, class Pred, class Alloc>
  78. bool
  79. operator==(const hash_set<Value, Hash, Pred, Alloc>& x,
  80. const hash_set<Value, Hash, Pred, Alloc>& y);
  81. template <class Value, class Hash, class Pred, class Alloc>
  82. bool
  83. operator!=(const hash_set<Value, Hash, Pred, Alloc>& x,
  84. const hash_set<Value, Hash, Pred, Alloc>& y);
  85. template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
  86. class Alloc = allocator<Value>>
  87. class hash_multiset
  88. {
  89. public:
  90. // types
  91. typedef Value key_type;
  92. typedef key_type value_type;
  93. typedef Hash hasher;
  94. typedef Pred key_equal;
  95. typedef Alloc allocator_type;
  96. typedef value_type& reference;
  97. typedef const value_type& const_reference;
  98. typedef typename allocator_traits<allocator_type>::pointer pointer;
  99. typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
  100. typedef typename allocator_traits<allocator_type>::size_type size_type;
  101. typedef typename allocator_traits<allocator_type>::difference_type difference_type;
  102. typedef /unspecified/ iterator;
  103. typedef /unspecified/ const_iterator;
  104. explicit hash_multiset(size_type n = 193, const hasher& hf = hasher(),
  105. const key_equal& eql = key_equal(),
  106. const allocator_type& a = allocator_type());
  107. template <class InputIterator>
  108. hash_multiset(InputIterator f, InputIterator l,
  109. size_type n = 193, const hasher& hf = hasher(),
  110. const key_equal& eql = key_equal(),
  111. const allocator_type& a = allocator_type());
  112. hash_multiset(const hash_multiset&);
  113. ~hash_multiset();
  114. hash_multiset& operator=(const hash_multiset&);
  115. allocator_type get_allocator() const;
  116. bool empty() const;
  117. size_type size() const;
  118. size_type max_size() const;
  119. iterator begin();
  120. iterator end();
  121. const_iterator begin() const;
  122. const_iterator end() const;
  123. iterator insert(const value_type& obj);
  124. template <class InputIterator>
  125. void insert(InputIterator first, InputIterator last);
  126. void erase(const_iterator position);
  127. size_type erase(const key_type& k);
  128. void erase(const_iterator first, const_iterator last);
  129. void clear();
  130. void swap(hash_multiset&);
  131. hasher hash_funct() const;
  132. key_equal key_eq() const;
  133. iterator find(const key_type& k);
  134. const_iterator find(const key_type& k) const;
  135. size_type count(const key_type& k) const;
  136. pair<iterator, iterator> equal_range(const key_type& k);
  137. pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
  138. size_type bucket_count() const;
  139. size_type max_bucket_count() const;
  140. size_type elems_in_bucket(size_type n) const;
  141. void resize(size_type n);
  142. };
  143. template <class Value, class Hash, class Pred, class Alloc>
  144. void swap(hash_multiset<Value, Hash, Pred, Alloc>& x,
  145. hash_multiset<Value, Hash, Pred, Alloc>& y);
  146. template <class Value, class Hash, class Pred, class Alloc>
  147. bool
  148. operator==(const hash_multiset<Value, Hash, Pred, Alloc>& x,
  149. const hash_multiset<Value, Hash, Pred, Alloc>& y);
  150. template <class Value, class Hash, class Pred, class Alloc>
  151. bool
  152. operator!=(const hash_multiset<Value, Hash, Pred, Alloc>& x,
  153. const hash_multiset<Value, Hash, Pred, Alloc>& y);
  154. } // __gnu_cxx
  155. */
  156. #include <__config>
  157. #include <__hash_table>
  158. #include <functional>
  159. #include <ext/__hash>
  160. #if __DEPRECATED
  161. #if defined(_MSC_VER) && ! defined(__clang__)
  162. _LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>")
  163. #else
  164. # warning Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>
  165. #endif
  166. #endif
  167. namespace __gnu_cxx {
  168. using namespace std;
  169. template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
  170. class _Alloc = allocator<_Value> >
  171. class _LIBCPP_TYPE_VIS_ONLY hash_set
  172. {
  173. public:
  174. // types
  175. typedef _Value key_type;
  176. typedef key_type value_type;
  177. typedef _Hash hasher;
  178. typedef _Pred key_equal;
  179. typedef _Alloc allocator_type;
  180. typedef value_type& reference;
  181. typedef const value_type& const_reference;
  182. private:
  183. typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
  184. __table __table_;
  185. public:
  186. typedef typename __table::pointer pointer;
  187. typedef typename __table::const_pointer const_pointer;
  188. typedef typename __table::size_type size_type;
  189. typedef typename __table::difference_type difference_type;
  190. typedef typename __table::const_iterator iterator;
  191. typedef typename __table::const_iterator const_iterator;
  192. _LIBCPP_INLINE_VISIBILITY
  193. hash_set() {__table_.rehash(193);}
  194. explicit hash_set(size_type __n, const hasher& __hf = hasher(),
  195. const key_equal& __eql = key_equal());
  196. hash_set(size_type __n, const hasher& __hf, const key_equal& __eql,
  197. const allocator_type& __a);
  198. template <class _InputIterator>
  199. hash_set(_InputIterator __first, _InputIterator __last);
  200. template <class _InputIterator>
  201. hash_set(_InputIterator __first, _InputIterator __last,
  202. size_type __n, const hasher& __hf = hasher(),
  203. const key_equal& __eql = key_equal());
  204. template <class _InputIterator>
  205. hash_set(_InputIterator __first, _InputIterator __last,
  206. size_type __n, const hasher& __hf, const key_equal& __eql,
  207. const allocator_type& __a);
  208. hash_set(const hash_set& __u);
  209. _LIBCPP_INLINE_VISIBILITY
  210. allocator_type get_allocator() const
  211. {return allocator_type(__table_.__node_alloc());}
  212. _LIBCPP_INLINE_VISIBILITY
  213. bool empty() const {return __table_.size() == 0;}
  214. _LIBCPP_INLINE_VISIBILITY
  215. size_type size() const {return __table_.size();}
  216. _LIBCPP_INLINE_VISIBILITY
  217. size_type max_size() const {return __table_.max_size();}
  218. _LIBCPP_INLINE_VISIBILITY
  219. iterator begin() {return __table_.begin();}
  220. _LIBCPP_INLINE_VISIBILITY
  221. iterator end() {return __table_.end();}
  222. _LIBCPP_INLINE_VISIBILITY
  223. const_iterator begin() const {return __table_.begin();}
  224. _LIBCPP_INLINE_VISIBILITY
  225. const_iterator end() const {return __table_.end();}
  226. _LIBCPP_INLINE_VISIBILITY
  227. pair<iterator, bool> insert(const value_type& __x)
  228. {return __table_.__insert_unique(__x);}
  229. _LIBCPP_INLINE_VISIBILITY
  230. iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;}
  231. template <class _InputIterator>
  232. _LIBCPP_INLINE_VISIBILITY
  233. void insert(_InputIterator __first, _InputIterator __last);
  234. _LIBCPP_INLINE_VISIBILITY
  235. void erase(const_iterator __p) {__table_.erase(__p);}
  236. _LIBCPP_INLINE_VISIBILITY
  237. size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
  238. _LIBCPP_INLINE_VISIBILITY
  239. void erase(const_iterator __first, const_iterator __last)
  240. {__table_.erase(__first, __last);}
  241. _LIBCPP_INLINE_VISIBILITY
  242. void clear() {__table_.clear();}
  243. _LIBCPP_INLINE_VISIBILITY
  244. void swap(hash_set& __u) {__table_.swap(__u.__table_);}
  245. _LIBCPP_INLINE_VISIBILITY
  246. hasher hash_funct() const {return __table_.hash_function();}
  247. _LIBCPP_INLINE_VISIBILITY
  248. key_equal key_eq() const {return __table_.key_eq();}
  249. _LIBCPP_INLINE_VISIBILITY
  250. iterator find(const key_type& __k) {return __table_.find(__k);}
  251. _LIBCPP_INLINE_VISIBILITY
  252. const_iterator find(const key_type& __k) const {return __table_.find(__k);}
  253. _LIBCPP_INLINE_VISIBILITY
  254. size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
  255. _LIBCPP_INLINE_VISIBILITY
  256. pair<iterator, iterator> equal_range(const key_type& __k)
  257. {return __table_.__equal_range_unique(__k);}
  258. _LIBCPP_INLINE_VISIBILITY
  259. pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
  260. {return __table_.__equal_range_unique(__k);}
  261. _LIBCPP_INLINE_VISIBILITY
  262. size_type bucket_count() const {return __table_.bucket_count();}
  263. _LIBCPP_INLINE_VISIBILITY
  264. size_type max_bucket_count() const {return __table_.max_bucket_count();}
  265. _LIBCPP_INLINE_VISIBILITY
  266. size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);}
  267. _LIBCPP_INLINE_VISIBILITY
  268. void resize(size_type __n) {__table_.rehash(__n);}
  269. };
  270. template <class _Value, class _Hash, class _Pred, class _Alloc>
  271. hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n,
  272. const hasher& __hf, const key_equal& __eql)
  273. : __table_(__hf, __eql)
  274. {
  275. __table_.rehash(__n);
  276. }
  277. template <class _Value, class _Hash, class _Pred, class _Alloc>
  278. hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n,
  279. const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  280. : __table_(__hf, __eql, __a)
  281. {
  282. __table_.rehash(__n);
  283. }
  284. template <class _Value, class _Hash, class _Pred, class _Alloc>
  285. template <class _InputIterator>
  286. hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
  287. _InputIterator __first, _InputIterator __last)
  288. {
  289. __table_.rehash(193);
  290. insert(__first, __last);
  291. }
  292. template <class _Value, class _Hash, class _Pred, class _Alloc>
  293. template <class _InputIterator>
  294. hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
  295. _InputIterator __first, _InputIterator __last, size_type __n,
  296. const hasher& __hf, const key_equal& __eql)
  297. : __table_(__hf, __eql)
  298. {
  299. __table_.rehash(__n);
  300. insert(__first, __last);
  301. }
  302. template <class _Value, class _Hash, class _Pred, class _Alloc>
  303. template <class _InputIterator>
  304. hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
  305. _InputIterator __first, _InputIterator __last, size_type __n,
  306. const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  307. : __table_(__hf, __eql, __a)
  308. {
  309. __table_.rehash(__n);
  310. insert(__first, __last);
  311. }
  312. template <class _Value, class _Hash, class _Pred, class _Alloc>
  313. hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
  314. const hash_set& __u)
  315. : __table_(__u.__table_)
  316. {
  317. __table_.rehash(__u.bucket_count());
  318. insert(__u.begin(), __u.end());
  319. }
  320. template <class _Value, class _Hash, class _Pred, class _Alloc>
  321. template <class _InputIterator>
  322. inline
  323. void
  324. hash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
  325. _InputIterator __last)
  326. {
  327. for (; __first != __last; ++__first)
  328. __table_.__insert_unique(*__first);
  329. }
  330. template <class _Value, class _Hash, class _Pred, class _Alloc>
  331. inline _LIBCPP_INLINE_VISIBILITY
  332. void
  333. swap(hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
  334. hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
  335. {
  336. __x.swap(__y);
  337. }
  338. template <class _Value, class _Hash, class _Pred, class _Alloc>
  339. bool
  340. operator==(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
  341. const hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
  342. {
  343. if (__x.size() != __y.size())
  344. return false;
  345. typedef typename hash_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
  346. const_iterator;
  347. for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
  348. __i != __ex; ++__i)
  349. {
  350. const_iterator __j = __y.find(*__i);
  351. if (__j == __ey || !(*__i == *__j))
  352. return false;
  353. }
  354. return true;
  355. }
  356. template <class _Value, class _Hash, class _Pred, class _Alloc>
  357. inline _LIBCPP_INLINE_VISIBILITY
  358. bool
  359. operator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
  360. const hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
  361. {
  362. return !(__x == __y);
  363. }
  364. template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
  365. class _Alloc = allocator<_Value> >
  366. class _LIBCPP_TYPE_VIS_ONLY hash_multiset
  367. {
  368. public:
  369. // types
  370. typedef _Value key_type;
  371. typedef key_type value_type;
  372. typedef _Hash hasher;
  373. typedef _Pred key_equal;
  374. typedef _Alloc allocator_type;
  375. typedef value_type& reference;
  376. typedef const value_type& const_reference;
  377. private:
  378. typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
  379. __table __table_;
  380. public:
  381. typedef typename __table::pointer pointer;
  382. typedef typename __table::const_pointer const_pointer;
  383. typedef typename __table::size_type size_type;
  384. typedef typename __table::difference_type difference_type;
  385. typedef typename __table::const_iterator iterator;
  386. typedef typename __table::const_iterator const_iterator;
  387. _LIBCPP_INLINE_VISIBILITY
  388. hash_multiset() {__table_.rehash(193);}
  389. explicit hash_multiset(size_type __n, const hasher& __hf = hasher(),
  390. const key_equal& __eql = key_equal());
  391. hash_multiset(size_type __n, const hasher& __hf,
  392. const key_equal& __eql, const allocator_type& __a);
  393. template <class _InputIterator>
  394. hash_multiset(_InputIterator __first, _InputIterator __last);
  395. template <class _InputIterator>
  396. hash_multiset(_InputIterator __first, _InputIterator __last,
  397. size_type __n, const hasher& __hf = hasher(),
  398. const key_equal& __eql = key_equal());
  399. template <class _InputIterator>
  400. hash_multiset(_InputIterator __first, _InputIterator __last,
  401. size_type __n , const hasher& __hf,
  402. const key_equal& __eql, const allocator_type& __a);
  403. hash_multiset(const hash_multiset& __u);
  404. _LIBCPP_INLINE_VISIBILITY
  405. allocator_type get_allocator() const
  406. {return allocator_type(__table_.__node_alloc());}
  407. _LIBCPP_INLINE_VISIBILITY
  408. bool empty() const {return __table_.size() == 0;}
  409. _LIBCPP_INLINE_VISIBILITY
  410. size_type size() const {return __table_.size();}
  411. _LIBCPP_INLINE_VISIBILITY
  412. size_type max_size() const {return __table_.max_size();}
  413. _LIBCPP_INLINE_VISIBILITY
  414. iterator begin() {return __table_.begin();}
  415. _LIBCPP_INLINE_VISIBILITY
  416. iterator end() {return __table_.end();}
  417. _LIBCPP_INLINE_VISIBILITY
  418. const_iterator begin() const {return __table_.begin();}
  419. _LIBCPP_INLINE_VISIBILITY
  420. const_iterator end() const {return __table_.end();}
  421. _LIBCPP_INLINE_VISIBILITY
  422. iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
  423. _LIBCPP_INLINE_VISIBILITY
  424. iterator insert(const_iterator, const value_type& __x) {return insert(__x);}
  425. template <class _InputIterator>
  426. _LIBCPP_INLINE_VISIBILITY
  427. void insert(_InputIterator __first, _InputIterator __last);
  428. _LIBCPP_INLINE_VISIBILITY
  429. void erase(const_iterator __p) {__table_.erase(__p);}
  430. _LIBCPP_INLINE_VISIBILITY
  431. size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
  432. _LIBCPP_INLINE_VISIBILITY
  433. void erase(const_iterator __first, const_iterator __last)
  434. {__table_.erase(__first, __last);}
  435. _LIBCPP_INLINE_VISIBILITY
  436. void clear() {__table_.clear();}
  437. _LIBCPP_INLINE_VISIBILITY
  438. void swap(hash_multiset& __u) {__table_.swap(__u.__table_);}
  439. _LIBCPP_INLINE_VISIBILITY
  440. hasher hash_funct() const {return __table_.hash_function();}
  441. _LIBCPP_INLINE_VISIBILITY
  442. key_equal key_eq() const {return __table_.key_eq();}
  443. _LIBCPP_INLINE_VISIBILITY
  444. iterator find(const key_type& __k) {return __table_.find(__k);}
  445. _LIBCPP_INLINE_VISIBILITY
  446. const_iterator find(const key_type& __k) const {return __table_.find(__k);}
  447. _LIBCPP_INLINE_VISIBILITY
  448. size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
  449. _LIBCPP_INLINE_VISIBILITY
  450. pair<iterator, iterator> equal_range(const key_type& __k)
  451. {return __table_.__equal_range_multi(__k);}
  452. _LIBCPP_INLINE_VISIBILITY
  453. pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
  454. {return __table_.__equal_range_multi(__k);}
  455. _LIBCPP_INLINE_VISIBILITY
  456. size_type bucket_count() const {return __table_.bucket_count();}
  457. _LIBCPP_INLINE_VISIBILITY
  458. size_type max_bucket_count() const {return __table_.max_bucket_count();}
  459. _LIBCPP_INLINE_VISIBILITY
  460. size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);}
  461. _LIBCPP_INLINE_VISIBILITY
  462. void resize(size_type __n) {__table_.rehash(__n);}
  463. };
  464. template <class _Value, class _Hash, class _Pred, class _Alloc>
  465. hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
  466. size_type __n, const hasher& __hf, const key_equal& __eql)
  467. : __table_(__hf, __eql)
  468. {
  469. __table_.rehash(__n);
  470. }
  471. template <class _Value, class _Hash, class _Pred, class _Alloc>
  472. hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
  473. size_type __n, const hasher& __hf, const key_equal& __eql,
  474. const allocator_type& __a)
  475. : __table_(__hf, __eql, __a)
  476. {
  477. __table_.rehash(__n);
  478. }
  479. template <class _Value, class _Hash, class _Pred, class _Alloc>
  480. template <class _InputIterator>
  481. hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
  482. _InputIterator __first, _InputIterator __last)
  483. {
  484. __table_.rehash(193);
  485. insert(__first, __last);
  486. }
  487. template <class _Value, class _Hash, class _Pred, class _Alloc>
  488. template <class _InputIterator>
  489. hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
  490. _InputIterator __first, _InputIterator __last, size_type __n,
  491. const hasher& __hf, const key_equal& __eql)
  492. : __table_(__hf, __eql)
  493. {
  494. __table_.rehash(__n);
  495. insert(__first, __last);
  496. }
  497. template <class _Value, class _Hash, class _Pred, class _Alloc>
  498. template <class _InputIterator>
  499. hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
  500. _InputIterator __first, _InputIterator __last, size_type __n,
  501. const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  502. : __table_(__hf, __eql, __a)
  503. {
  504. __table_.rehash(__n);
  505. insert(__first, __last);
  506. }
  507. template <class _Value, class _Hash, class _Pred, class _Alloc>
  508. hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
  509. const hash_multiset& __u)
  510. : __table_(__u.__table_)
  511. {
  512. __table_.rehash(__u.bucket_count());
  513. insert(__u.begin(), __u.end());
  514. }
  515. template <class _Value, class _Hash, class _Pred, class _Alloc>
  516. template <class _InputIterator>
  517. inline
  518. void
  519. hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
  520. _InputIterator __last)
  521. {
  522. for (; __first != __last; ++__first)
  523. __table_.__insert_multi(*__first);
  524. }
  525. template <class _Value, class _Hash, class _Pred, class _Alloc>
  526. inline _LIBCPP_INLINE_VISIBILITY
  527. void
  528. swap(hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  529. hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  530. {
  531. __x.swap(__y);
  532. }
  533. template <class _Value, class _Hash, class _Pred, class _Alloc>
  534. bool
  535. operator==(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  536. const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  537. {
  538. if (__x.size() != __y.size())
  539. return false;
  540. typedef typename hash_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
  541. const_iterator;
  542. typedef pair<const_iterator, const_iterator> _EqRng;
  543. for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
  544. {
  545. _EqRng __xeq = __x.equal_range(*__i);
  546. _EqRng __yeq = __y.equal_range(*__i);
  547. if (_VSTD::distance(__xeq.first, __xeq.second) !=
  548. _VSTD::distance(__yeq.first, __yeq.second) ||
  549. !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
  550. return false;
  551. __i = __xeq.second;
  552. }
  553. return true;
  554. }
  555. template <class _Value, class _Hash, class _Pred, class _Alloc>
  556. inline _LIBCPP_INLINE_VISIBILITY
  557. bool
  558. operator!=(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  559. const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  560. {
  561. return !(__x == __y);
  562. }
  563. } // __gnu_cxx
  564. #endif // _LIBCPP_HASH_SET