concurrent_flat_set.hpp 24 KB

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