btree_map.h 25 KB

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