concurrent_flat_set.hpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /* Fast open-addressing concurrent hashset.
  2. *
  3. * Copyright 2023 Christian Mazakas.
  4. * Copyright 2023 Joaquin M Lopez Munoz.
  5. * Distributed under the Boost Software License, Version 1.0.
  6. * (See accompanying file LICENSE_1_0.txt or copy at
  7. * http://www.boost.org/LICENSE_1_0.txt)
  8. *
  9. * See https://www.boost.org/libs/unordered for library home page.
  10. */
  11. #ifndef BOOST_UNORDERED_CONCURRENT_FLAT_SET_HPP
  12. #define BOOST_UNORDERED_CONCURRENT_FLAT_SET_HPP
  13. #include <boost/unordered/concurrent_flat_set_fwd.hpp>
  14. #include <boost/unordered/detail/concurrent_static_asserts.hpp>
  15. #include <boost/unordered/detail/foa/concurrent_table.hpp>
  16. #include <boost/unordered/detail/foa/flat_set_types.hpp>
  17. #include <boost/unordered/detail/type_traits.hpp>
  18. #include <boost/unordered/unordered_flat_set_fwd.hpp>
  19. #include <boost/container_hash/hash.hpp>
  20. #include <boost/core/allocator_access.hpp>
  21. #include <boost/core/serialization.hpp>
  22. #include <utility>
  23. namespace boost {
  24. namespace unordered {
  25. template <class Key, class Hash, class Pred, class Allocator>
  26. class concurrent_flat_set
  27. {
  28. private:
  29. template <class Key2, class Hash2, class Pred2, class Allocator2>
  30. friend class concurrent_flat_set;
  31. template <class Key2, class Hash2, class Pred2, class Allocator2>
  32. friend class unordered_flat_set;
  33. using type_policy = detail::foa::flat_set_types<Key>;
  34. using table_type =
  35. detail::foa::concurrent_table<type_policy, Hash, Pred, Allocator>;
  36. table_type table_;
  37. template <class K, class H, class KE, class A>
  38. bool friend operator==(concurrent_flat_set<K, H, KE, A> const& lhs,
  39. concurrent_flat_set<K, H, KE, A> const& rhs);
  40. template <class K, class H, class KE, class A, class Predicate>
  41. friend typename concurrent_flat_set<K, H, KE, A>::size_type erase_if(
  42. concurrent_flat_set<K, H, KE, A>& set, Predicate pred);
  43. template<class Archive, class K, class H, class KE, class A>
  44. friend void serialize(
  45. Archive& ar, concurrent_flat_set<K, H, KE, A>& c,
  46. unsigned int version);
  47. public:
  48. using key_type = Key;
  49. using value_type = typename type_policy::value_type;
  50. using init_type = typename type_policy::init_type;
  51. using size_type = std::size_t;
  52. using difference_type = std::ptrdiff_t;
  53. using hasher = typename boost::unordered::detail::type_identity<Hash>::type;
  54. using key_equal = typename boost::unordered::detail::type_identity<Pred>::type;
  55. using allocator_type = typename boost::unordered::detail::type_identity<Allocator>::type;
  56. using reference = value_type&;
  57. using const_reference = value_type const&;
  58. using pointer = typename boost::allocator_pointer<allocator_type>::type;
  59. using const_pointer =
  60. typename boost::allocator_const_pointer<allocator_type>::type;
  61. static constexpr size_type bulk_visit_size = table_type::bulk_visit_size;
  62. concurrent_flat_set()
  63. : concurrent_flat_set(detail::foa::default_bucket_count)
  64. {
  65. }
  66. explicit concurrent_flat_set(size_type n, const hasher& hf = hasher(),
  67. const key_equal& eql = key_equal(),
  68. const allocator_type& a = allocator_type())
  69. : table_(n, hf, eql, a)
  70. {
  71. }
  72. template <class InputIterator>
  73. concurrent_flat_set(InputIterator f, InputIterator l,
  74. size_type n = detail::foa::default_bucket_count,
  75. const hasher& hf = hasher(), const key_equal& eql = key_equal(),
  76. const allocator_type& a = allocator_type())
  77. : table_(n, hf, eql, a)
  78. {
  79. this->insert(f, l);
  80. }
  81. concurrent_flat_set(concurrent_flat_set const& rhs)
  82. : table_(rhs.table_,
  83. boost::allocator_select_on_container_copy_construction(
  84. rhs.get_allocator()))
  85. {
  86. }
  87. concurrent_flat_set(concurrent_flat_set&& rhs)
  88. : table_(std::move(rhs.table_))
  89. {
  90. }
  91. template <class InputIterator>
  92. concurrent_flat_set(
  93. InputIterator f, InputIterator l, allocator_type const& a)
  94. : concurrent_flat_set(f, l, 0, hasher(), key_equal(), a)
  95. {
  96. }
  97. explicit concurrent_flat_set(allocator_type const& a)
  98. : table_(detail::foa::default_bucket_count, hasher(), key_equal(), a)
  99. {
  100. }
  101. concurrent_flat_set(
  102. concurrent_flat_set const& rhs, allocator_type const& a)
  103. : table_(rhs.table_, a)
  104. {
  105. }
  106. concurrent_flat_set(concurrent_flat_set&& rhs, allocator_type const& a)
  107. : table_(std::move(rhs.table_), a)
  108. {
  109. }
  110. concurrent_flat_set(std::initializer_list<value_type> il,
  111. size_type n = detail::foa::default_bucket_count,
  112. const hasher& hf = hasher(), const key_equal& eql = key_equal(),
  113. const allocator_type& a = allocator_type())
  114. : concurrent_flat_set(n, hf, eql, a)
  115. {
  116. this->insert(il.begin(), il.end());
  117. }
  118. concurrent_flat_set(size_type n, const allocator_type& a)
  119. : concurrent_flat_set(n, hasher(), key_equal(), a)
  120. {
  121. }
  122. concurrent_flat_set(
  123. size_type n, const hasher& hf, const allocator_type& a)
  124. : concurrent_flat_set(n, hf, key_equal(), a)
  125. {
  126. }
  127. template <typename InputIterator>
  128. concurrent_flat_set(
  129. InputIterator f, InputIterator l, size_type n, const allocator_type& a)
  130. : concurrent_flat_set(f, l, n, hasher(), key_equal(), a)
  131. {
  132. }
  133. template <typename InputIterator>
  134. concurrent_flat_set(InputIterator f, InputIterator l, size_type n,
  135. const hasher& hf, const allocator_type& a)
  136. : concurrent_flat_set(f, l, n, hf, key_equal(), a)
  137. {
  138. }
  139. concurrent_flat_set(
  140. std::initializer_list<value_type> il, const allocator_type& a)
  141. : concurrent_flat_set(
  142. il, detail::foa::default_bucket_count, hasher(), key_equal(), a)
  143. {
  144. }
  145. concurrent_flat_set(std::initializer_list<value_type> il, size_type n,
  146. const allocator_type& a)
  147. : concurrent_flat_set(il, n, hasher(), key_equal(), a)
  148. {
  149. }
  150. concurrent_flat_set(std::initializer_list<value_type> il, size_type n,
  151. const hasher& hf, const allocator_type& a)
  152. : concurrent_flat_set(il, n, hf, key_equal(), a)
  153. {
  154. }
  155. concurrent_flat_set(
  156. unordered_flat_set<Key, Hash, Pred, Allocator>&& other)
  157. : table_(std::move(other.table_))
  158. {
  159. }
  160. ~concurrent_flat_set() = default;
  161. concurrent_flat_set& operator=(concurrent_flat_set const& rhs)
  162. {
  163. table_ = rhs.table_;
  164. return *this;
  165. }
  166. concurrent_flat_set& operator=(concurrent_flat_set&& rhs)
  167. noexcept(boost::allocator_is_always_equal<Allocator>::type::value ||
  168. boost::allocator_propagate_on_container_move_assignment<
  169. Allocator>::type::value)
  170. {
  171. table_ = std::move(rhs.table_);
  172. return *this;
  173. }
  174. concurrent_flat_set& operator=(std::initializer_list<value_type> ilist)
  175. {
  176. table_ = ilist;
  177. return *this;
  178. }
  179. /// Capacity
  180. ///
  181. size_type size() const noexcept { return table_.size(); }
  182. size_type max_size() const noexcept { return table_.max_size(); }
  183. BOOST_ATTRIBUTE_NODISCARD bool empty() const noexcept
  184. {
  185. return size() == 0;
  186. }
  187. template <class F>
  188. BOOST_FORCEINLINE size_type visit(key_type const& k, F f) const
  189. {
  190. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  191. return table_.visit(k, f);
  192. }
  193. template <class F>
  194. BOOST_FORCEINLINE size_type cvisit(key_type const& k, F f) const
  195. {
  196. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  197. return table_.visit(k, f);
  198. }
  199. template <class K, class F>
  200. BOOST_FORCEINLINE typename std::enable_if<
  201. detail::are_transparent<K, hasher, key_equal>::value, size_type>::type
  202. visit(K&& k, F f) const
  203. {
  204. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  205. return table_.visit(std::forward<K>(k), f);
  206. }
  207. template <class K, class F>
  208. BOOST_FORCEINLINE typename std::enable_if<
  209. detail::are_transparent<K, hasher, key_equal>::value, size_type>::type
  210. cvisit(K&& k, F f) const
  211. {
  212. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  213. return table_.visit(std::forward<K>(k), f);
  214. }
  215. template<class FwdIterator, class F>
  216. BOOST_FORCEINLINE
  217. size_t visit(FwdIterator first, FwdIterator last, F f) const
  218. {
  219. BOOST_UNORDERED_STATIC_ASSERT_BULK_VISIT_ITERATOR(FwdIterator)
  220. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  221. return table_.visit(first, last, f);
  222. }
  223. template<class FwdIterator, class F>
  224. BOOST_FORCEINLINE
  225. size_t cvisit(FwdIterator first, FwdIterator last, F f) const
  226. {
  227. BOOST_UNORDERED_STATIC_ASSERT_BULK_VISIT_ITERATOR(FwdIterator)
  228. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  229. return table_.visit(first, last, f);
  230. }
  231. template <class F> size_type visit_all(F f) const
  232. {
  233. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  234. return table_.visit_all(f);
  235. }
  236. template <class F> size_type cvisit_all(F f) const
  237. {
  238. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  239. return table_.cvisit_all(f);
  240. }
  241. #if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS)
  242. template <class ExecPolicy, class F>
  243. typename std::enable_if<detail::is_execution_policy<ExecPolicy>::value,
  244. void>::type
  245. visit_all(ExecPolicy&& p, F f) const
  246. {
  247. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  248. BOOST_UNORDERED_STATIC_ASSERT_EXEC_POLICY(ExecPolicy)
  249. table_.visit_all(p, f);
  250. }
  251. template <class ExecPolicy, class F>
  252. typename std::enable_if<detail::is_execution_policy<ExecPolicy>::value,
  253. void>::type
  254. cvisit_all(ExecPolicy&& p, F f) const
  255. {
  256. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  257. BOOST_UNORDERED_STATIC_ASSERT_EXEC_POLICY(ExecPolicy)
  258. table_.cvisit_all(p, f);
  259. }
  260. #endif
  261. template <class F> bool visit_while(F f) const
  262. {
  263. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  264. return table_.visit_while(f);
  265. }
  266. template <class F> bool cvisit_while(F f) const
  267. {
  268. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  269. return table_.cvisit_while(f);
  270. }
  271. #if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS)
  272. template <class ExecPolicy, class F>
  273. typename std::enable_if<detail::is_execution_policy<ExecPolicy>::value,
  274. bool>::type
  275. visit_while(ExecPolicy&& p, F f) const
  276. {
  277. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  278. BOOST_UNORDERED_STATIC_ASSERT_EXEC_POLICY(ExecPolicy)
  279. return table_.visit_while(p, f);
  280. }
  281. template <class ExecPolicy, class F>
  282. typename std::enable_if<detail::is_execution_policy<ExecPolicy>::value,
  283. bool>::type
  284. cvisit_while(ExecPolicy&& p, F f) const
  285. {
  286. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  287. BOOST_UNORDERED_STATIC_ASSERT_EXEC_POLICY(ExecPolicy)
  288. return table_.cvisit_while(p, f);
  289. }
  290. #endif
  291. /// Modifiers
  292. ///
  293. BOOST_FORCEINLINE bool insert(value_type const& obj)
  294. {
  295. return table_.insert(obj);
  296. }
  297. BOOST_FORCEINLINE bool insert(value_type&& obj)
  298. {
  299. return table_.insert(std::move(obj));
  300. }
  301. template <class K>
  302. BOOST_FORCEINLINE typename std::enable_if<
  303. detail::are_transparent<K, hasher, key_equal>::value,
  304. bool >::type
  305. insert(K&& k)
  306. {
  307. return table_.try_emplace(std::forward<K>(k));
  308. }
  309. template <class InputIterator>
  310. void insert(InputIterator begin, InputIterator end)
  311. {
  312. for (auto pos = begin; pos != end; ++pos) {
  313. table_.emplace(*pos);
  314. }
  315. }
  316. void insert(std::initializer_list<value_type> ilist)
  317. {
  318. this->insert(ilist.begin(), ilist.end());
  319. }
  320. template <class F>
  321. BOOST_FORCEINLINE bool insert_or_visit(value_type const& obj, F f)
  322. {
  323. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  324. return table_.insert_or_cvisit(obj, f);
  325. }
  326. template <class F>
  327. BOOST_FORCEINLINE bool insert_or_visit(value_type&& obj, F f)
  328. {
  329. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  330. return table_.insert_or_cvisit(std::move(obj), f);
  331. }
  332. template <class K, class F>
  333. BOOST_FORCEINLINE typename std::enable_if<
  334. detail::are_transparent<K, hasher, key_equal>::value,
  335. bool >::type
  336. insert_or_visit(K&& k, F f)
  337. {
  338. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  339. return table_.try_emplace_or_cvisit(std::forward<K>(k), f);
  340. }
  341. template <class InputIterator, class F>
  342. void insert_or_visit(InputIterator first, InputIterator last, F f)
  343. {
  344. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  345. for (; first != last; ++first) {
  346. table_.emplace_or_cvisit(*first, f);
  347. }
  348. }
  349. template <class F>
  350. void insert_or_visit(std::initializer_list<value_type> ilist, F f)
  351. {
  352. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  353. this->insert_or_cvisit(ilist.begin(), ilist.end(), f);
  354. }
  355. template <class F>
  356. BOOST_FORCEINLINE bool insert_or_cvisit(value_type const& obj, F f)
  357. {
  358. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  359. return table_.insert_or_cvisit(obj, f);
  360. }
  361. template <class F>
  362. BOOST_FORCEINLINE bool insert_or_cvisit(value_type&& obj, F f)
  363. {
  364. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  365. return table_.insert_or_cvisit(std::move(obj), f);
  366. }
  367. template <class K, class F>
  368. BOOST_FORCEINLINE typename std::enable_if<
  369. detail::are_transparent<K, hasher, key_equal>::value,
  370. bool >::type
  371. insert_or_cvisit(K&& k, F f)
  372. {
  373. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  374. return table_.try_emplace_or_cvisit(std::forward<K>(k), f);
  375. }
  376. template <class InputIterator, class F>
  377. void insert_or_cvisit(InputIterator first, InputIterator last, F f)
  378. {
  379. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  380. for (; first != last; ++first) {
  381. table_.emplace_or_cvisit(*first, f);
  382. }
  383. }
  384. template <class F>
  385. void insert_or_cvisit(std::initializer_list<value_type> ilist, F f)
  386. {
  387. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F)
  388. this->insert_or_cvisit(ilist.begin(), ilist.end(), f);
  389. }
  390. template <class... Args> BOOST_FORCEINLINE bool emplace(Args&&... args)
  391. {
  392. return table_.emplace(std::forward<Args>(args)...);
  393. }
  394. template <class Arg, class... Args>
  395. BOOST_FORCEINLINE bool emplace_or_visit(Arg&& arg, Args&&... args)
  396. {
  397. BOOST_UNORDERED_STATIC_ASSERT_LAST_ARG_CONST_INVOCABLE(Arg, Args...)
  398. return table_.emplace_or_cvisit(
  399. std::forward<Arg>(arg), std::forward<Args>(args)...);
  400. }
  401. template <class Arg, class... Args>
  402. BOOST_FORCEINLINE bool emplace_or_cvisit(Arg&& arg, Args&&... args)
  403. {
  404. BOOST_UNORDERED_STATIC_ASSERT_LAST_ARG_CONST_INVOCABLE(Arg, Args...)
  405. return table_.emplace_or_cvisit(
  406. std::forward<Arg>(arg), std::forward<Args>(args)...);
  407. }
  408. BOOST_FORCEINLINE size_type erase(key_type const& k)
  409. {
  410. return table_.erase(k);
  411. }
  412. template <class K>
  413. BOOST_FORCEINLINE typename std::enable_if<
  414. detail::are_transparent<K, hasher, key_equal>::value, size_type>::type
  415. erase(K&& k)
  416. {
  417. return table_.erase(std::forward<K>(k));
  418. }
  419. template <class F>
  420. BOOST_FORCEINLINE size_type erase_if(key_type const& k, F f)
  421. {
  422. return table_.erase_if(k, f);
  423. }
  424. template <class K, class F>
  425. BOOST_FORCEINLINE typename std::enable_if<
  426. detail::are_transparent<K, hasher, key_equal>::value &&
  427. !detail::is_execution_policy<K>::value,
  428. size_type>::type
  429. erase_if(K&& k, F f)
  430. {
  431. return table_.erase_if(std::forward<K>(k), f);
  432. }
  433. #if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS)
  434. template <class ExecPolicy, class F>
  435. typename std::enable_if<detail::is_execution_policy<ExecPolicy>::value,
  436. void>::type
  437. erase_if(ExecPolicy&& p, F f)
  438. {
  439. BOOST_UNORDERED_STATIC_ASSERT_EXEC_POLICY(ExecPolicy)
  440. table_.erase_if(p, f);
  441. }
  442. #endif
  443. template <class F> size_type erase_if(F f) { return table_.erase_if(f); }
  444. void swap(concurrent_flat_set& other) noexcept(
  445. boost::allocator_is_always_equal<Allocator>::type::value ||
  446. boost::allocator_propagate_on_container_swap<Allocator>::type::value)
  447. {
  448. return table_.swap(other.table_);
  449. }
  450. void clear() noexcept { table_.clear(); }
  451. template <typename H2, typename P2>
  452. size_type merge(concurrent_flat_set<Key, H2, P2, Allocator>& x)
  453. {
  454. BOOST_ASSERT(get_allocator() == x.get_allocator());
  455. return table_.merge(x.table_);
  456. }
  457. template <typename H2, typename P2>
  458. size_type merge(concurrent_flat_set<Key, H2, P2, Allocator>&& x)
  459. {
  460. return merge(x);
  461. }
  462. BOOST_FORCEINLINE size_type count(key_type const& k) const
  463. {
  464. return table_.count(k);
  465. }
  466. template <class K>
  467. BOOST_FORCEINLINE typename std::enable_if<
  468. detail::are_transparent<K, hasher, key_equal>::value, size_type>::type
  469. count(K const& k)
  470. {
  471. return table_.count(k);
  472. }
  473. BOOST_FORCEINLINE bool contains(key_type const& k) const
  474. {
  475. return table_.contains(k);
  476. }
  477. template <class K>
  478. BOOST_FORCEINLINE typename std::enable_if<
  479. detail::are_transparent<K, hasher, key_equal>::value, bool>::type
  480. contains(K const& k) const
  481. {
  482. return table_.contains(k);
  483. }
  484. /// Hash Policy
  485. ///
  486. size_type bucket_count() const noexcept { return table_.capacity(); }
  487. float load_factor() const noexcept { return table_.load_factor(); }
  488. float max_load_factor() const noexcept
  489. {
  490. return table_.max_load_factor();
  491. }
  492. void max_load_factor(float) {}
  493. size_type max_load() const noexcept { return table_.max_load(); }
  494. void rehash(size_type n) { table_.rehash(n); }
  495. void reserve(size_type n) { table_.reserve(n); }
  496. /// Observers
  497. ///
  498. allocator_type get_allocator() const noexcept
  499. {
  500. return table_.get_allocator();
  501. }
  502. hasher hash_function() const { return table_.hash_function(); }
  503. key_equal key_eq() const { return table_.key_eq(); }
  504. };
  505. template <class Key, class Hash, class KeyEqual, class Allocator>
  506. bool operator==(
  507. concurrent_flat_set<Key, Hash, KeyEqual, Allocator> const& lhs,
  508. concurrent_flat_set<Key, Hash, KeyEqual, Allocator> const& rhs)
  509. {
  510. return lhs.table_ == rhs.table_;
  511. }
  512. template <class Key, class Hash, class KeyEqual, class Allocator>
  513. bool operator!=(
  514. concurrent_flat_set<Key, Hash, KeyEqual, Allocator> const& lhs,
  515. concurrent_flat_set<Key, Hash, KeyEqual, Allocator> const& rhs)
  516. {
  517. return !(lhs == rhs);
  518. }
  519. template <class Key, class Hash, class Pred, class Alloc>
  520. void swap(concurrent_flat_set<Key, Hash, Pred, Alloc>& x,
  521. concurrent_flat_set<Key, Hash, Pred, Alloc>& y)
  522. noexcept(noexcept(x.swap(y)))
  523. {
  524. x.swap(y);
  525. }
  526. template <class K, class H, class P, class A, class Predicate>
  527. typename concurrent_flat_set<K, H, P, A>::size_type erase_if(
  528. concurrent_flat_set<K, H, P, A>& c, Predicate pred)
  529. {
  530. return c.table_.erase_if(pred);
  531. }
  532. template<class Archive, class K, class H, class KE, class A>
  533. void serialize(
  534. Archive& ar, concurrent_flat_set<K, H, KE, A>& c, unsigned int)
  535. {
  536. ar & core::make_nvp("table",c.table_);
  537. }
  538. #if BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES
  539. template <class InputIterator,
  540. class Hash =
  541. boost::hash<typename std::iterator_traits<InputIterator>::value_type>,
  542. class Pred =
  543. std::equal_to<typename std::iterator_traits<InputIterator>::value_type>,
  544. class Allocator = std::allocator<
  545. typename std::iterator_traits<InputIterator>::value_type>,
  546. class = std::enable_if_t<detail::is_input_iterator_v<InputIterator> >,
  547. class = std::enable_if_t<detail::is_hash_v<Hash> >,
  548. class = std::enable_if_t<detail::is_pred_v<Pred> >,
  549. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  550. concurrent_flat_set(InputIterator, InputIterator,
  551. std::size_t = boost::unordered::detail::foa::default_bucket_count,
  552. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  553. -> concurrent_flat_set<
  554. typename std::iterator_traits<InputIterator>::value_type, Hash, Pred,
  555. Allocator>;
  556. template <class T, class Hash = boost::hash<T>,
  557. class Pred = std::equal_to<T>, class Allocator = std::allocator<T>,
  558. class = std::enable_if_t<detail::is_hash_v<Hash> >,
  559. class = std::enable_if_t<detail::is_pred_v<Pred> >,
  560. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  561. concurrent_flat_set(std::initializer_list<T>,
  562. std::size_t = boost::unordered::detail::foa::default_bucket_count,
  563. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  564. -> concurrent_flat_set< T, Hash, Pred, Allocator>;
  565. template <class InputIterator, class Allocator,
  566. class = std::enable_if_t<detail::is_input_iterator_v<InputIterator> >,
  567. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  568. concurrent_flat_set(InputIterator, InputIterator, std::size_t, Allocator)
  569. -> concurrent_flat_set<
  570. typename std::iterator_traits<InputIterator>::value_type,
  571. boost::hash<typename std::iterator_traits<InputIterator>::value_type>,
  572. std::equal_to<typename std::iterator_traits<InputIterator>::value_type>,
  573. Allocator>;
  574. template <class InputIterator, class Allocator,
  575. class = std::enable_if_t<detail::is_input_iterator_v<InputIterator> >,
  576. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  577. concurrent_flat_set(InputIterator, InputIterator, Allocator)
  578. -> concurrent_flat_set<
  579. typename std::iterator_traits<InputIterator>::value_type,
  580. boost::hash<typename std::iterator_traits<InputIterator>::value_type>,
  581. std::equal_to<typename std::iterator_traits<InputIterator>::value_type>,
  582. Allocator>;
  583. template <class InputIterator, class Hash, class Allocator,
  584. class = std::enable_if_t<detail::is_hash_v<Hash> >,
  585. class = std::enable_if_t<detail::is_input_iterator_v<InputIterator> >,
  586. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  587. concurrent_flat_set(
  588. InputIterator, InputIterator, std::size_t, Hash, Allocator)
  589. -> concurrent_flat_set<
  590. typename std::iterator_traits<InputIterator>::value_type, Hash,
  591. std::equal_to<typename std::iterator_traits<InputIterator>::value_type>,
  592. Allocator>;
  593. template <class T, class Allocator,
  594. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  595. concurrent_flat_set(std::initializer_list<T>, std::size_t, Allocator)
  596. -> concurrent_flat_set<T, boost::hash<T>,std::equal_to<T>, Allocator>;
  597. template <class T, class Allocator,
  598. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  599. concurrent_flat_set(std::initializer_list<T >, Allocator)
  600. -> concurrent_flat_set<T, boost::hash<T>, std::equal_to<T>, Allocator>;
  601. template <class T, class Hash, class Allocator,
  602. class = std::enable_if_t<detail::is_hash_v<Hash> >,
  603. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  604. concurrent_flat_set(std::initializer_list<T >, std::size_t,Hash, Allocator)
  605. -> concurrent_flat_set<T, Hash, std::equal_to<T>, Allocator>;
  606. #endif
  607. } // namespace unordered
  608. } // namespace boost
  609. #endif // BOOST_UNORDERED_CONCURRENT_FLAT_SET_HPP