btree_set.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. // Copyright 2018 The Abseil Authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // -----------------------------------------------------------------------------
  16. // File: btree_set.h
  17. // -----------------------------------------------------------------------------
  18. //
  19. // This header file defines B-tree sets: sorted associative containers of
  20. // values.
  21. //
  22. // * `absl::btree_set<>`
  23. // * `absl::btree_multiset<>`
  24. //
  25. // These B-tree types are similar to the corresponding types in the STL
  26. // (`std::set` and `std::multiset`) and generally conform to the STL interfaces
  27. // of those types. However, because they are implemented using B-trees, they
  28. // are more efficient in most situations.
  29. //
  30. // Unlike `std::set` and `std::multiset`, which are commonly implemented using
  31. // red-black tree nodes, B-tree sets use more generic B-tree nodes able to hold
  32. // multiple values per node. Holding multiple values per node often makes
  33. // B-tree sets perform better than their `std::set` counterparts, because
  34. // multiple entries can be checked within the same cache hit.
  35. //
  36. // However, these types should not be considered drop-in replacements for
  37. // `std::set` and `std::multiset` as there are some API differences, which are
  38. // noted in this header file.
  39. //
  40. // Importantly, insertions and deletions may invalidate outstanding iterators,
  41. // pointers, and references to elements. Such invalidations are typically only
  42. // an issue if insertion and deletion operations are interleaved with the use of
  43. // more than one iterator, pointer, or reference simultaneously. For this
  44. // reason, `insert()` and `erase()` return a valid iterator at the current
  45. // position.
  46. #ifndef ABSL_CONTAINER_BTREE_SET_H_
  47. #define ABSL_CONTAINER_BTREE_SET_H_
  48. #include "absl/container/internal/btree.h" // IWYU pragma: export
  49. #include "absl/container/internal/btree_container.h" // IWYU pragma: export
  50. namespace absl {
  51. ABSL_NAMESPACE_BEGIN
  52. // absl::btree_set<>
  53. //
  54. // An `absl::btree_set<K>` is an ordered associative container of unique key
  55. // values designed to be a more efficient replacement for `std::set` (in most
  56. // cases).
  57. //
  58. // Keys are sorted using an (optional) comparison function, which defaults to
  59. // `std::less<K>`.
  60. //
  61. // An `absl::btree_set<K>` uses a default allocator of `std::allocator<K>` to
  62. // allocate (and deallocate) nodes, and construct and destruct values within
  63. // those nodes. You may instead specify a custom allocator `A` (which in turn
  64. // requires specifying a custom comparator `C`) as in
  65. // `absl::btree_set<K, C, A>`.
  66. //
  67. template <typename Key, typename Compare = std::less<Key>,
  68. typename Alloc = std::allocator<Key>>
  69. class btree_set
  70. : public container_internal::btree_set_container<
  71. container_internal::btree<container_internal::set_params<
  72. Key, Compare, Alloc, /*TargetNodeSize=*/256,
  73. /*Multi=*/false>>> {
  74. using Base = typename btree_set::btree_set_container;
  75. public:
  76. // Constructors and Assignment Operators
  77. //
  78. // A `btree_set` supports the same overload set as `std::set`
  79. // for construction and assignment:
  80. //
  81. // * Default constructor
  82. //
  83. // absl::btree_set<std::string> set1;
  84. //
  85. // * Initializer List constructor
  86. //
  87. // absl::btree_set<std::string> set2 =
  88. // {{"huey"}, {"dewey"}, {"louie"},};
  89. //
  90. // * Copy constructor
  91. //
  92. // absl::btree_set<std::string> set3(set2);
  93. //
  94. // * Copy assignment operator
  95. //
  96. // absl::btree_set<std::string> set4;
  97. // set4 = set3;
  98. //
  99. // * Move constructor
  100. //
  101. // // Move is guaranteed efficient
  102. // absl::btree_set<std::string> set5(std::move(set4));
  103. //
  104. // * Move assignment operator
  105. //
  106. // // May be efficient if allocators are compatible
  107. // absl::btree_set<std::string> set6;
  108. // set6 = std::move(set5);
  109. //
  110. // * Range constructor
  111. //
  112. // std::vector<std::string> v = {"a", "b"};
  113. // absl::btree_set<std::string> set7(v.begin(), v.end());
  114. btree_set() {}
  115. using Base::Base;
  116. // btree_set::begin()
  117. //
  118. // Returns an iterator to the beginning of the `btree_set`.
  119. using Base::begin;
  120. // btree_set::cbegin()
  121. //
  122. // Returns a const iterator to the beginning of the `btree_set`.
  123. using Base::cbegin;
  124. // btree_set::end()
  125. //
  126. // Returns an iterator to the end of the `btree_set`.
  127. using Base::end;
  128. // btree_set::cend()
  129. //
  130. // Returns a const iterator to the end of the `btree_set`.
  131. using Base::cend;
  132. // btree_set::empty()
  133. //
  134. // Returns whether or not the `btree_set` is empty.
  135. using Base::empty;
  136. // btree_set::max_size()
  137. //
  138. // Returns the largest theoretical possible number of elements within a
  139. // `btree_set` under current memory constraints. This value can be thought
  140. // of as the largest value of `std::distance(begin(), end())` for a
  141. // `btree_set<Key>`.
  142. using Base::max_size;
  143. // btree_set::size()
  144. //
  145. // Returns the number of elements currently within the `btree_set`.
  146. using Base::size;
  147. // btree_set::clear()
  148. //
  149. // Removes all elements from the `btree_set`. Invalidates any references,
  150. // pointers, or iterators referring to contained elements.
  151. using Base::clear;
  152. // btree_set::erase()
  153. //
  154. // Erases elements within the `btree_set`. Overloads are listed below.
  155. //
  156. // iterator erase(iterator position):
  157. // iterator erase(const_iterator position):
  158. //
  159. // Erases the element at `position` of the `btree_set`, returning
  160. // the iterator pointing to the element after the one that was erased
  161. // (or end() if none exists).
  162. //
  163. // iterator erase(const_iterator first, const_iterator last):
  164. //
  165. // Erases the elements in the open interval [`first`, `last`), returning
  166. // the iterator pointing to the element after the interval that was erased
  167. // (or end() if none exists).
  168. //
  169. // template <typename K> size_type erase(const K& key):
  170. //
  171. // Erases the element with the matching key, if it exists, returning the
  172. // number of elements erased (0 or 1).
  173. using Base::erase;
  174. // btree_set::insert()
  175. //
  176. // Inserts an element of the specified value into the `btree_set`,
  177. // returning an iterator pointing to the newly inserted element, provided that
  178. // an element with the given key does not already exist. If an insertion
  179. // occurs, any references, pointers, or iterators are invalidated.
  180. // Overloads are listed below.
  181. //
  182. // std::pair<iterator,bool> insert(const value_type& value):
  183. //
  184. // Inserts a value into the `btree_set`. Returns a pair consisting of an
  185. // iterator to the inserted element (or to the element that prevented the
  186. // insertion) and a bool denoting whether the insertion took place.
  187. //
  188. // std::pair<iterator,bool> insert(value_type&& value):
  189. //
  190. // Inserts a moveable value into the `btree_set`. Returns a pair
  191. // consisting of an iterator to the inserted element (or to the element that
  192. // prevented the insertion) and a bool denoting whether the insertion took
  193. // place.
  194. //
  195. // iterator insert(const_iterator hint, const value_type& value):
  196. // iterator insert(const_iterator hint, value_type&& value):
  197. //
  198. // Inserts a value, using the position of `hint` as a non-binding suggestion
  199. // for where to begin the insertion search. Returns an iterator to the
  200. // inserted element, or to the existing element that prevented the
  201. // insertion.
  202. //
  203. // void insert(InputIterator first, InputIterator last):
  204. //
  205. // Inserts a range of values [`first`, `last`).
  206. //
  207. // void insert(std::initializer_list<init_type> ilist):
  208. //
  209. // Inserts the elements within the initializer list `ilist`.
  210. using Base::insert;
  211. // btree_set::emplace()
  212. //
  213. // Inserts an element of the specified value by constructing it in-place
  214. // within the `btree_set`, provided that no element with the given key
  215. // already exists.
  216. //
  217. // The element may be constructed even if there already is an element with the
  218. // key in the container, in which case the newly constructed element will be
  219. // destroyed immediately.
  220. //
  221. // If an insertion occurs, any references, pointers, or iterators are
  222. // invalidated.
  223. using Base::emplace;
  224. // btree_set::emplace_hint()
  225. //
  226. // Inserts an element of the specified value by constructing it in-place
  227. // within the `btree_set`, using the position of `hint` as a non-binding
  228. // suggestion for where to begin the insertion search, and only inserts
  229. // provided that no element with the given key already exists.
  230. //
  231. // The element may be constructed even if there already is an element with the
  232. // key in the container, in which case the newly constructed element will be
  233. // destroyed immediately.
  234. //
  235. // If an insertion occurs, any references, pointers, or iterators are
  236. // invalidated.
  237. using Base::emplace_hint;
  238. // btree_set::extract()
  239. //
  240. // Extracts the indicated element, erasing it in the process, and returns it
  241. // as a C++17-compatible node handle. Overloads are listed below.
  242. //
  243. // node_type extract(const_iterator position):
  244. //
  245. // Extracts the element at the indicated position and returns a node handle
  246. // owning that extracted data.
  247. //
  248. // template <typename K> node_type extract(const K& k):
  249. //
  250. // Extracts the element with the key matching the passed key value and
  251. // returns a node handle owning that extracted data. If the `btree_set`
  252. // does not contain an element with a matching key, this function returns an
  253. // empty node handle.
  254. //
  255. // NOTE: In this context, `node_type` refers to the C++17 concept of a
  256. // move-only type that owns and provides access to the elements in associative
  257. // containers (https://en.cppreference.com/w/cpp/container/node_handle).
  258. // It does NOT refer to the data layout of the underlying btree.
  259. using Base::extract;
  260. // btree_set::merge()
  261. //
  262. // Extracts elements from a given `source` btree_set into this
  263. // `btree_set`. If the destination `btree_set` already contains an
  264. // element with an equivalent key, that element is not extracted.
  265. using Base::merge;
  266. // btree_set::swap(btree_set& other)
  267. //
  268. // Exchanges the contents of this `btree_set` with those of the `other`
  269. // btree_set, avoiding invocation of any move, copy, or swap operations on
  270. // individual elements.
  271. //
  272. // All iterators and references on the `btree_set` remain valid, excepting
  273. // for the past-the-end iterator, which is invalidated.
  274. using Base::swap;
  275. // btree_set::contains()
  276. //
  277. // template <typename K> bool contains(const K& key) const:
  278. //
  279. // Determines whether an element comparing equal to the given `key` exists
  280. // within the `btree_set`, returning `true` if so or `false` otherwise.
  281. //
  282. // Supports heterogeneous lookup, provided that the set is provided a
  283. // compatible heterogeneous comparator.
  284. using Base::contains;
  285. // btree_set::count()
  286. //
  287. // template <typename K> size_type count(const K& key) const:
  288. //
  289. // Returns the number of elements comparing equal to the given `key` within
  290. // the `btree_set`. Note that this function will return either `1` or `0`
  291. // since duplicate elements are not allowed within a `btree_set`.
  292. //
  293. // Supports heterogeneous lookup, provided that the set is provided a
  294. // compatible heterogeneous comparator.
  295. using Base::count;
  296. // btree_set::equal_range()
  297. //
  298. // Returns a closed range [first, last], defined by a `std::pair` of two
  299. // iterators, containing all elements with the passed key in the
  300. // `btree_set`.
  301. using Base::equal_range;
  302. // btree_set::find()
  303. //
  304. // template <typename K> iterator find(const K& key):
  305. // template <typename K> const_iterator find(const K& key) const:
  306. //
  307. // Finds an element with the passed `key` within the `btree_set`.
  308. //
  309. // Supports heterogeneous lookup, provided that the set is provided a
  310. // compatible heterogeneous comparator.
  311. using Base::find;
  312. // btree_set::get_allocator()
  313. //
  314. // Returns the allocator function associated with this `btree_set`.
  315. using Base::get_allocator;
  316. // btree_set::key_comp();
  317. //
  318. // Returns the key comparator associated with this `btree_set`.
  319. using Base::key_comp;
  320. // btree_set::value_comp();
  321. //
  322. // Returns the value comparator associated with this `btree_set`. The keys to
  323. // sort the elements are the values themselves, therefore `value_comp` and its
  324. // sibling member function `key_comp` are equivalent.
  325. using Base::value_comp;
  326. };
  327. // absl::swap(absl::btree_set<>, absl::btree_set<>)
  328. //
  329. // Swaps the contents of two `absl::btree_set` containers.
  330. template <typename K, typename C, typename A>
  331. void swap(btree_set<K, C, A> &x, btree_set<K, C, A> &y) {
  332. return x.swap(y);
  333. }
  334. // absl::erase_if(absl::btree_set<>, Pred)
  335. //
  336. // Erases all elements that satisfy the predicate pred from the container.
  337. template <typename K, typename C, typename A, typename Pred>
  338. void erase_if(btree_set<K, C, A> &set, Pred pred) {
  339. for (auto it = set.begin(); it != set.end();) {
  340. if (pred(*it)) {
  341. it = set.erase(it);
  342. } else {
  343. ++it;
  344. }
  345. }
  346. }
  347. // absl::btree_multiset<>
  348. //
  349. // An `absl::btree_multiset<K>` is an ordered associative container of
  350. // keys and associated values designed to be a more efficient replacement
  351. // for `std::multiset` (in most cases). Unlike `absl::btree_set`, a B-tree
  352. // multiset allows equivalent elements.
  353. //
  354. // Keys are sorted using an (optional) comparison function, which defaults to
  355. // `std::less<K>`.
  356. //
  357. // An `absl::btree_multiset<K>` uses a default allocator of `std::allocator<K>`
  358. // to allocate (and deallocate) nodes, and construct and destruct values within
  359. // those nodes. You may instead specify a custom allocator `A` (which in turn
  360. // requires specifying a custom comparator `C`) as in
  361. // `absl::btree_multiset<K, C, A>`.
  362. //
  363. template <typename Key, typename Compare = std::less<Key>,
  364. typename Alloc = std::allocator<Key>>
  365. class btree_multiset
  366. : public container_internal::btree_multiset_container<
  367. container_internal::btree<container_internal::set_params<
  368. Key, Compare, Alloc, /*TargetNodeSize=*/256,
  369. /*Multi=*/true>>> {
  370. using Base = typename btree_multiset::btree_multiset_container;
  371. public:
  372. // Constructors and Assignment Operators
  373. //
  374. // A `btree_multiset` supports the same overload set as `std::set`
  375. // for construction and assignment:
  376. //
  377. // * Default constructor
  378. //
  379. // absl::btree_multiset<std::string> set1;
  380. //
  381. // * Initializer List constructor
  382. //
  383. // absl::btree_multiset<std::string> set2 =
  384. // {{"huey"}, {"dewey"}, {"louie"},};
  385. //
  386. // * Copy constructor
  387. //
  388. // absl::btree_multiset<std::string> set3(set2);
  389. //
  390. // * Copy assignment operator
  391. //
  392. // absl::btree_multiset<std::string> set4;
  393. // set4 = set3;
  394. //
  395. // * Move constructor
  396. //
  397. // // Move is guaranteed efficient
  398. // absl::btree_multiset<std::string> set5(std::move(set4));
  399. //
  400. // * Move assignment operator
  401. //
  402. // // May be efficient if allocators are compatible
  403. // absl::btree_multiset<std::string> set6;
  404. // set6 = std::move(set5);
  405. //
  406. // * Range constructor
  407. //
  408. // std::vector<std::string> v = {"a", "b"};
  409. // absl::btree_multiset<std::string> set7(v.begin(), v.end());
  410. btree_multiset() {}
  411. using Base::Base;
  412. // btree_multiset::begin()
  413. //
  414. // Returns an iterator to the beginning of the `btree_multiset`.
  415. using Base::begin;
  416. // btree_multiset::cbegin()
  417. //
  418. // Returns a const iterator to the beginning of the `btree_multiset`.
  419. using Base::cbegin;
  420. // btree_multiset::end()
  421. //
  422. // Returns an iterator to the end of the `btree_multiset`.
  423. using Base::end;
  424. // btree_multiset::cend()
  425. //
  426. // Returns a const iterator to the end of the `btree_multiset`.
  427. using Base::cend;
  428. // btree_multiset::empty()
  429. //
  430. // Returns whether or not the `btree_multiset` is empty.
  431. using Base::empty;
  432. // btree_multiset::max_size()
  433. //
  434. // Returns the largest theoretical possible number of elements within a
  435. // `btree_multiset` under current memory constraints. This value can be
  436. // thought of as the largest value of `std::distance(begin(), end())` for a
  437. // `btree_multiset<Key>`.
  438. using Base::max_size;
  439. // btree_multiset::size()
  440. //
  441. // Returns the number of elements currently within the `btree_multiset`.
  442. using Base::size;
  443. // btree_multiset::clear()
  444. //
  445. // Removes all elements from the `btree_multiset`. Invalidates any references,
  446. // pointers, or iterators referring to contained elements.
  447. using Base::clear;
  448. // btree_multiset::erase()
  449. //
  450. // Erases elements within the `btree_multiset`. Overloads are listed below.
  451. //
  452. // iterator erase(iterator position):
  453. // iterator erase(const_iterator position):
  454. //
  455. // Erases the element at `position` of the `btree_multiset`, returning
  456. // the iterator pointing to the element after the one that was erased
  457. // (or end() if none exists).
  458. //
  459. // iterator erase(const_iterator first, const_iterator last):
  460. //
  461. // Erases the elements in the open interval [`first`, `last`), returning
  462. // the iterator pointing to the element after the interval that was erased
  463. // (or end() if none exists).
  464. //
  465. // template <typename K> size_type erase(const K& key):
  466. //
  467. // Erases the elements matching the key, if any exist, returning the
  468. // number of elements erased.
  469. using Base::erase;
  470. // btree_multiset::insert()
  471. //
  472. // Inserts an element of the specified value into the `btree_multiset`,
  473. // returning an iterator pointing to the newly inserted element.
  474. // Any references, pointers, or iterators are invalidated. Overloads are
  475. // listed below.
  476. //
  477. // iterator insert(const value_type& value):
  478. //
  479. // Inserts a value into the `btree_multiset`, returning an iterator to the
  480. // inserted element.
  481. //
  482. // iterator insert(value_type&& value):
  483. //
  484. // Inserts a moveable value into the `btree_multiset`, returning an iterator
  485. // to the inserted element.
  486. //
  487. // iterator insert(const_iterator hint, const value_type& value):
  488. // iterator insert(const_iterator hint, value_type&& value):
  489. //
  490. // Inserts a value, using the position of `hint` as a non-binding suggestion
  491. // for where to begin the insertion search. Returns an iterator to the
  492. // inserted element.
  493. //
  494. // void insert(InputIterator first, InputIterator last):
  495. //
  496. // Inserts a range of values [`first`, `last`).
  497. //
  498. // void insert(std::initializer_list<init_type> ilist):
  499. //
  500. // Inserts the elements within the initializer list `ilist`.
  501. using Base::insert;
  502. // btree_multiset::emplace()
  503. //
  504. // Inserts an element of the specified value by constructing it in-place
  505. // within the `btree_multiset`. Any references, pointers, or iterators are
  506. // invalidated.
  507. using Base::emplace;
  508. // btree_multiset::emplace_hint()
  509. //
  510. // Inserts an element of the specified value by constructing it in-place
  511. // within the `btree_multiset`, using the position of `hint` as a non-binding
  512. // suggestion for where to begin the insertion search.
  513. //
  514. // Any references, pointers, or iterators are invalidated.
  515. using Base::emplace_hint;
  516. // btree_multiset::extract()
  517. //
  518. // Extracts the indicated element, erasing it in the process, and returns it
  519. // as a C++17-compatible node handle. Overloads are listed below.
  520. //
  521. // node_type extract(const_iterator position):
  522. //
  523. // Extracts the element at the indicated position and returns a node handle
  524. // owning that extracted data.
  525. //
  526. // template <typename K> node_type extract(const K& k):
  527. //
  528. // Extracts the element with the key matching the passed key value and
  529. // returns a node handle owning that extracted data. If the `btree_multiset`
  530. // does not contain an element with a matching key, this function returns an
  531. // empty node handle.
  532. //
  533. // NOTE: In this context, `node_type` refers to the C++17 concept of a
  534. // move-only type that owns and provides access to the elements in associative
  535. // containers (https://en.cppreference.com/w/cpp/container/node_handle).
  536. // It does NOT refer to the data layout of the underlying btree.
  537. using Base::extract;
  538. // btree_multiset::merge()
  539. //
  540. // Extracts elements from a given `source` btree_multiset into this
  541. // `btree_multiset`. If the destination `btree_multiset` already contains an
  542. // element with an equivalent key, that element is not extracted.
  543. using Base::merge;
  544. // btree_multiset::swap(btree_multiset& other)
  545. //
  546. // Exchanges the contents of this `btree_multiset` with those of the `other`
  547. // btree_multiset, avoiding invocation of any move, copy, or swap operations
  548. // on individual elements.
  549. //
  550. // All iterators and references on the `btree_multiset` remain valid,
  551. // excepting for the past-the-end iterator, which is invalidated.
  552. using Base::swap;
  553. // btree_multiset::contains()
  554. //
  555. // template <typename K> bool contains(const K& key) const:
  556. //
  557. // Determines whether an element comparing equal to the given `key` exists
  558. // within the `btree_multiset`, returning `true` if so or `false` otherwise.
  559. //
  560. // Supports heterogeneous lookup, provided that the set is provided a
  561. // compatible heterogeneous comparator.
  562. using Base::contains;
  563. // btree_multiset::count()
  564. //
  565. // template <typename K> size_type count(const K& key) const:
  566. //
  567. // Returns the number of elements comparing equal to the given `key` within
  568. // the `btree_multiset`.
  569. //
  570. // Supports heterogeneous lookup, provided that the set is provided a
  571. // compatible heterogeneous comparator.
  572. using Base::count;
  573. // btree_multiset::equal_range()
  574. //
  575. // Returns a closed range [first, last], defined by a `std::pair` of two
  576. // iterators, containing all elements with the passed key in the
  577. // `btree_multiset`.
  578. using Base::equal_range;
  579. // btree_multiset::find()
  580. //
  581. // template <typename K> iterator find(const K& key):
  582. // template <typename K> const_iterator find(const K& key) const:
  583. //
  584. // Finds an element with the passed `key` within the `btree_multiset`.
  585. //
  586. // Supports heterogeneous lookup, provided that the set is provided a
  587. // compatible heterogeneous comparator.
  588. using Base::find;
  589. // btree_multiset::get_allocator()
  590. //
  591. // Returns the allocator function associated with this `btree_multiset`.
  592. using Base::get_allocator;
  593. // btree_multiset::key_comp();
  594. //
  595. // Returns the key comparator associated with this `btree_multiset`.
  596. using Base::key_comp;
  597. // btree_multiset::value_comp();
  598. //
  599. // Returns the value comparator associated with this `btree_multiset`. The
  600. // keys to sort the elements are the values themselves, therefore `value_comp`
  601. // and its sibling member function `key_comp` are equivalent.
  602. using Base::value_comp;
  603. };
  604. // absl::swap(absl::btree_multiset<>, absl::btree_multiset<>)
  605. //
  606. // Swaps the contents of two `absl::btree_multiset` containers.
  607. template <typename K, typename C, typename A>
  608. void swap(btree_multiset<K, C, A> &x, btree_multiset<K, C, A> &y) {
  609. return x.swap(y);
  610. }
  611. // absl::erase_if(absl::btree_multiset<>, Pred)
  612. //
  613. // Erases all elements that satisfy the predicate pred from the container.
  614. template <typename K, typename C, typename A, typename Pred>
  615. void erase_if(btree_multiset<K, C, A> &set, Pred pred) {
  616. for (auto it = set.begin(); it != set.end();) {
  617. if (pred(*it)) {
  618. it = set.erase(it);
  619. } else {
  620. ++it;
  621. }
  622. }
  623. }
  624. ABSL_NAMESPACE_END
  625. } // namespace absl
  626. #endif // ABSL_CONTAINER_BTREE_SET_H_