abseil-cpp/absl/container/btree_map.h
Go to the documentation of this file.
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. The most consequential differences with respect to
39 // migrating to b-tree from the STL types are listed in the next paragraph.
40 // Other API differences are minor.
41 //
42 // Importantly, insertions and deletions may invalidate outstanding iterators,
43 // pointers, and references to elements. Such invalidations are typically only
44 // an issue if insertion and deletion operations are interleaved with the use of
45 // more than one iterator, pointer, or reference simultaneously. For this
46 // reason, `insert()` and `erase()` return a valid iterator at the current
47 // position. Another important difference is that key-types must be
48 // copy-constructible.
49 
50 #ifndef ABSL_CONTAINER_BTREE_MAP_H_
51 #define ABSL_CONTAINER_BTREE_MAP_H_
52 
53 #include "absl/container/internal/btree.h" // IWYU pragma: export
54 #include "absl/container/internal/btree_container.h" // IWYU pragma: export
55 
56 namespace absl {
58 
59 namespace container_internal {
60 
61 template <typename Key, typename Data, typename Compare, typename Alloc,
62  int TargetNodeSize, bool IsMulti>
63 struct map_params;
64 
65 } // namespace container_internal
66 
67 // absl::btree_map<>
68 //
69 // An `absl::btree_map<K, V>` is an ordered associative container of
70 // unique keys and associated values designed to be a more efficient replacement
71 // for `std::map` (in most cases).
72 //
73 // Keys are sorted using an (optional) comparison function, which defaults to
74 // `std::less<K>`.
75 //
76 // An `absl::btree_map<K, V>` uses a default allocator of
77 // `std::allocator<std::pair<const K, V>>` to allocate (and deallocate)
78 // nodes, and construct and destruct values within those nodes. You may
79 // instead specify a custom allocator `A` (which in turn requires specifying a
80 // custom comparator `C`) as in `absl::btree_map<K, V, C, A>`.
81 //
82 template <typename Key, typename Value, typename Compare = std::less<Key>,
83  typename Alloc = std::allocator<std::pair<const Key, Value>>>
84 class btree_map
86  container_internal::btree<container_internal::map_params<
87  Key, Value, Compare, Alloc, /*TargetNodeSize=*/256,
88  /*IsMulti=*/false>>> {
89  using Base = typename btree_map::btree_map_container;
90 
91  public:
92  // Constructors and Assignment Operators
93  //
94  // A `btree_map` supports the same overload set as `std::map`
95  // for construction and assignment:
96  //
97  // * Default constructor
98  //
99  // absl::btree_map<int, std::string> map1;
100  //
101  // * Initializer List constructor
102  //
103  // absl::btree_map<int, std::string> map2 =
104  // {{1, "huey"}, {2, "dewey"}, {3, "louie"},};
105  //
106  // * Copy constructor
107  //
108  // absl::btree_map<int, std::string> map3(map2);
109  //
110  // * Copy assignment operator
111  //
112  // absl::btree_map<int, std::string> map4;
113  // map4 = map3;
114  //
115  // * Move constructor
116  //
117  // // Move is guaranteed efficient
118  // absl::btree_map<int, std::string> map5(std::move(map4));
119  //
120  // * Move assignment operator
121  //
122  // // May be efficient if allocators are compatible
123  // absl::btree_map<int, std::string> map6;
124  // map6 = std::move(map5);
125  //
126  // * Range constructor
127  //
128  // std::vector<std::pair<int, std::string>> v = {{1, "a"}, {2, "b"}};
129  // absl::btree_map<int, std::string> map7(v.begin(), v.end());
131  using Base::Base;
132 
133  // btree_map::begin()
134  //
135  // Returns an iterator to the beginning of the `btree_map`.
136  using Base::begin;
137 
138  // btree_map::cbegin()
139  //
140  // Returns a const iterator to the beginning of the `btree_map`.
141  using Base::cbegin;
142 
143  // btree_map::end()
144  //
145  // Returns an iterator to the end of the `btree_map`.
146  using Base::end;
147 
148  // btree_map::cend()
149  //
150  // Returns a const iterator to the end of the `btree_map`.
151  using Base::cend;
152 
153  // btree_map::empty()
154  //
155  // Returns whether or not the `btree_map` is empty.
156  using Base::empty;
157 
158  // btree_map::max_size()
159  //
160  // Returns the largest theoretical possible number of elements within a
161  // `btree_map` under current memory constraints. This value can be thought
162  // of as the largest value of `std::distance(begin(), end())` for a
163  // `btree_map<Key, T>`.
164  using Base::max_size;
165 
166  // btree_map::size()
167  //
168  // Returns the number of elements currently within the `btree_map`.
169  using Base::size;
170 
171  // btree_map::clear()
172  //
173  // Removes all elements from the `btree_map`. Invalidates any references,
174  // pointers, or iterators referring to contained elements.
175  using Base::clear;
176 
177  // btree_map::erase()
178  //
179  // Erases elements within the `btree_map`. If an erase occurs, any references,
180  // pointers, or iterators are invalidated.
181  // Overloads are listed below.
182  //
183  // iterator erase(iterator position):
184  // iterator erase(const_iterator position):
185  //
186  // Erases the element at `position` of the `btree_map`, returning
187  // the iterator pointing to the element after the one that was erased
188  // (or end() if none exists).
189  //
190  // iterator erase(const_iterator first, const_iterator last):
191  //
192  // Erases the elements in the open interval [`first`, `last`), returning
193  // the iterator pointing to the element after the interval that was erased
194  // (or end() if none exists).
195  //
196  // template <typename K> size_type erase(const K& key):
197  //
198  // Erases the element with the matching key, if it exists, returning the
199  // number of elements erased (0 or 1).
200  using Base::erase;
201 
202  // btree_map::insert()
203  //
204  // Inserts an element of the specified value into the `btree_map`,
205  // returning an iterator pointing to the newly inserted element, provided that
206  // an element with the given key does not already exist. If an insertion
207  // occurs, any references, pointers, or iterators are invalidated.
208  // Overloads are listed below.
209  //
210  // std::pair<iterator,bool> insert(const value_type& value):
211  //
212  // Inserts a value into the `btree_map`. Returns a pair consisting of an
213  // iterator to the inserted element (or to the element that prevented the
214  // insertion) and a bool denoting whether the insertion took place.
215  //
216  // std::pair<iterator,bool> insert(value_type&& value):
217  //
218  // Inserts a moveable value into the `btree_map`. Returns a pair
219  // consisting of an iterator to the inserted element (or to the element that
220  // prevented the insertion) and a bool denoting whether the insertion took
221  // place.
222  //
223  // iterator insert(const_iterator hint, const value_type& value):
224  // iterator insert(const_iterator hint, value_type&& value):
225  //
226  // Inserts a value, using the position of `hint` as a non-binding suggestion
227  // for where to begin the insertion search. Returns an iterator to the
228  // inserted element, or to the existing element that prevented the
229  // insertion.
230  //
231  // void insert(InputIterator first, InputIterator last):
232  //
233  // Inserts a range of values [`first`, `last`).
234  //
235  // void insert(std::initializer_list<init_type> ilist):
236  //
237  // Inserts the elements within the initializer list `ilist`.
238  using Base::insert;
239 
240  // btree_map::insert_or_assign()
241  //
242  // Inserts an element of the specified value into the `btree_map` provided
243  // that a value with the given key does not already exist, or replaces the
244  // corresponding mapped type with the forwarded `obj` argument if a key for
245  // that value already exists, returning an iterator pointing to the newly
246  // inserted element. Overloads are listed below.
247  //
248  // pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj):
249  // pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj):
250  //
251  // Inserts/Assigns (or moves) the element of the specified key into the
252  // `btree_map`. If the returned bool is true, insertion took place, and if
253  // it's false, assignment took place.
254  //
255  // iterator insert_or_assign(const_iterator hint,
256  // const key_type& k, M&& obj):
257  // iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj):
258  //
259  // Inserts/Assigns (or moves) the element of the specified key into the
260  // `btree_map` using the position of `hint` as a non-binding suggestion
261  // for where to begin the insertion search.
262  using Base::insert_or_assign;
263 
264  // btree_map::emplace()
265  //
266  // Inserts an element of the specified value by constructing it in-place
267  // within the `btree_map`, provided that no element with the given key
268  // already exists.
269  //
270  // The element may be constructed even if there already is an element with the
271  // key in the container, in which case the newly constructed element will be
272  // destroyed immediately. Prefer `try_emplace()` unless your key is not
273  // copyable or moveable.
274  //
275  // If an insertion occurs, any references, pointers, or iterators are
276  // invalidated.
277  using Base::emplace;
278 
279  // btree_map::emplace_hint()
280  //
281  // Inserts an element of the specified value by constructing it in-place
282  // within the `btree_map`, using the position of `hint` as a non-binding
283  // suggestion for where to begin the insertion search, and only inserts
284  // provided that no element with the given key already exists.
285  //
286  // The element may be constructed even if there already is an element with the
287  // key in the container, in which case the newly constructed element will be
288  // destroyed immediately. Prefer `try_emplace()` unless your key is not
289  // copyable or moveable.
290  //
291  // If an insertion occurs, any references, pointers, or iterators are
292  // invalidated.
293  using Base::emplace_hint;
294 
295  // btree_map::try_emplace()
296  //
297  // Inserts an element of the specified value by constructing it in-place
298  // within the `btree_map`, provided that no element with the given key
299  // already exists. Unlike `emplace()`, if an element with the given key
300  // already exists, we guarantee that no element is constructed.
301  //
302  // If an insertion occurs, any references, pointers, or iterators are
303  // invalidated.
304  //
305  // Overloads are listed below.
306  //
307  // std::pair<iterator, bool> try_emplace(const key_type& k, Args&&... args):
308  // std::pair<iterator, bool> try_emplace(key_type&& k, Args&&... args):
309  //
310  // Inserts (via copy or move) the element of the specified key into the
311  // `btree_map`.
312  //
313  // iterator try_emplace(const_iterator hint,
314  // const key_type& k, Args&&... args):
315  // iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args):
316  //
317  // Inserts (via copy or move) the element of the specified key into the
318  // `btree_map` using the position of `hint` as a non-binding suggestion
319  // for where to begin the insertion search.
320  using Base::try_emplace;
321 
322  // btree_map::extract()
323  //
324  // Extracts the indicated element, erasing it in the process, and returns it
325  // as a C++17-compatible node handle. Overloads are listed below.
326  //
327  // node_type extract(const_iterator position):
328  //
329  // Extracts the element at the indicated position and returns a node handle
330  // owning that extracted data.
331  //
332  // template <typename K> node_type extract(const K& k):
333  //
334  // Extracts the element with the key matching the passed key value and
335  // returns a node handle owning that extracted data. If the `btree_map`
336  // does not contain an element with a matching key, this function returns an
337  // empty node handle.
338  //
339  // NOTE: when compiled in an earlier version of C++ than C++17,
340  // `node_type::key()` returns a const reference to the key instead of a
341  // mutable reference. We cannot safely return a mutable reference without
342  // std::launder (which is not available before C++17).
343  //
344  // NOTE: In this context, `node_type` refers to the C++17 concept of a
345  // move-only type that owns and provides access to the elements in associative
346  // containers (https://en.cppreference.com/w/cpp/container/node_handle).
347  // It does NOT refer to the data layout of the underlying btree.
348  using Base::extract;
349 
350  // btree_map::merge()
351  //
352  // Extracts elements from a given `source` btree_map into this
353  // `btree_map`. If the destination `btree_map` already contains an
354  // element with an equivalent key, that element is not extracted.
355  using Base::merge;
356 
357  // btree_map::swap(btree_map& other)
358  //
359  // Exchanges the contents of this `btree_map` with those of the `other`
360  // btree_map, avoiding invocation of any move, copy, or swap operations on
361  // individual elements.
362  //
363  // All iterators and references on the `btree_map` remain valid, excepting
364  // for the past-the-end iterator, which is invalidated.
365  using Base::swap;
366 
367  // btree_map::at()
368  //
369  // Returns a reference to the mapped value of the element with key equivalent
370  // to the passed key.
371  using Base::at;
372 
373  // btree_map::contains()
374  //
375  // template <typename K> bool contains(const K& key) const:
376  //
377  // Determines whether an element comparing equal to the given `key` exists
378  // within the `btree_map`, returning `true` if so or `false` otherwise.
379  //
380  // Supports heterogeneous lookup, provided that the map has a compatible
381  // heterogeneous comparator.
382  using Base::contains;
383 
384  // btree_map::count()
385  //
386  // template <typename K> size_type count(const K& key) const:
387  //
388  // Returns the number of elements comparing equal to the given `key` within
389  // the `btree_map`. Note that this function will return either `1` or `0`
390  // since duplicate elements are not allowed within a `btree_map`.
391  //
392  // Supports heterogeneous lookup, provided that the map has a compatible
393  // heterogeneous comparator.
394  using Base::count;
395 
396  // btree_map::equal_range()
397  //
398  // Returns a half-open range [first, last), defined by a `std::pair` of two
399  // iterators, containing all elements with the passed key in the `btree_map`.
400  using Base::equal_range;
401 
402  // btree_map::find()
403  //
404  // template <typename K> iterator find(const K& key):
405  // template <typename K> const_iterator find(const K& key) const:
406  //
407  // Finds an element with the passed `key` within the `btree_map`.
408  //
409  // Supports heterogeneous lookup, provided that the map has a compatible
410  // heterogeneous comparator.
411  using Base::find;
412 
413  // btree_map::lower_bound()
414  //
415  // template <typename K> iterator lower_bound(const K& key):
416  // template <typename K> const_iterator lower_bound(const K& key) const:
417  //
418  // Finds the first element with a key that is not less than `key` within the
419  // `btree_map`.
420  //
421  // Supports heterogeneous lookup, provided that the map has a compatible
422  // heterogeneous comparator.
423  using Base::lower_bound;
424 
425  // btree_map::upper_bound()
426  //
427  // template <typename K> iterator upper_bound(const K& key):
428  // template <typename K> const_iterator upper_bound(const K& key) const:
429  //
430  // Finds the first element with a key that is greater than `key` within the
431  // `btree_map`.
432  //
433  // Supports heterogeneous lookup, provided that the map has a compatible
434  // heterogeneous comparator.
435  using Base::upper_bound;
436 
437  // btree_map::operator[]()
438  //
439  // Returns a reference to the value mapped to the passed key within the
440  // `btree_map`, performing an `insert()` if the key does not already
441  // exist.
442  //
443  // If an insertion occurs, any references, pointers, or iterators are
444  // invalidated. Otherwise iterators are not affected and references are not
445  // invalidated. Overloads are listed below.
446  //
447  // T& operator[](key_type&& key):
448  // T& operator[](const key_type& key):
449  //
450  // Inserts a value_type object constructed in-place if the element with the
451  // given key does not exist.
452  using Base::operator[];
453 
454  // btree_map::get_allocator()
455  //
456  // Returns the allocator function associated with this `btree_map`.
457  using Base::get_allocator;
458 
459  // btree_map::key_comp();
460  //
461  // Returns the key comparator associated with this `btree_map`.
462  using Base::key_comp;
463 
464  // btree_map::value_comp();
465  //
466  // Returns the value comparator associated with this `btree_map`.
467  using Base::value_comp;
468 };
469 
470 // absl::swap(absl::btree_map<>, absl::btree_map<>)
471 //
472 // Swaps the contents of two `absl::btree_map` containers.
473 template <typename K, typename V, typename C, typename A>
475  return x.swap(y);
476 }
477 
478 // absl::erase_if(absl::btree_map<>, Pred)
479 //
480 // Erases all elements that satisfy the predicate pred from the container.
481 // Returns the number of erased elements.
482 template <typename K, typename V, typename C, typename A, typename Pred>
484  btree_map<K, V, C, A> &map, Pred pred) {
486 }
487 
488 // absl::btree_multimap
489 //
490 // An `absl::btree_multimap<K, V>` is an ordered associative container of
491 // keys and associated values designed to be a more efficient replacement for
492 // `std::multimap` (in most cases). Unlike `absl::btree_map`, a B-tree multimap
493 // allows multiple elements with equivalent keys.
494 //
495 // Keys are sorted using an (optional) comparison function, which defaults to
496 // `std::less<K>`.
497 //
498 // An `absl::btree_multimap<K, V>` uses a default allocator of
499 // `std::allocator<std::pair<const K, V>>` to allocate (and deallocate)
500 // nodes, and construct and destruct values within those nodes. You may
501 // instead specify a custom allocator `A` (which in turn requires specifying a
502 // custom comparator `C`) as in `absl::btree_multimap<K, V, C, A>`.
503 //
504 template <typename Key, typename Value, typename Compare = std::less<Key>,
505  typename Alloc = std::allocator<std::pair<const Key, Value>>>
508  container_internal::btree<container_internal::map_params<
509  Key, Value, Compare, Alloc, /*TargetNodeSize=*/256,
510  /*IsMulti=*/true>>> {
511  using Base = typename btree_multimap::btree_multimap_container;
512 
513  public:
514  // Constructors and Assignment Operators
515  //
516  // A `btree_multimap` supports the same overload set as `std::multimap`
517  // for construction and assignment:
518  //
519  // * Default constructor
520  //
521  // absl::btree_multimap<int, std::string> map1;
522  //
523  // * Initializer List constructor
524  //
525  // absl::btree_multimap<int, std::string> map2 =
526  // {{1, "huey"}, {2, "dewey"}, {3, "louie"},};
527  //
528  // * Copy constructor
529  //
530  // absl::btree_multimap<int, std::string> map3(map2);
531  //
532  // * Copy assignment operator
533  //
534  // absl::btree_multimap<int, std::string> map4;
535  // map4 = map3;
536  //
537  // * Move constructor
538  //
539  // // Move is guaranteed efficient
540  // absl::btree_multimap<int, std::string> map5(std::move(map4));
541  //
542  // * Move assignment operator
543  //
544  // // May be efficient if allocators are compatible
545  // absl::btree_multimap<int, std::string> map6;
546  // map6 = std::move(map5);
547  //
548  // * Range constructor
549  //
550  // std::vector<std::pair<int, std::string>> v = {{1, "a"}, {2, "b"}};
551  // absl::btree_multimap<int, std::string> map7(v.begin(), v.end());
553  using Base::Base;
554 
555  // btree_multimap::begin()
556  //
557  // Returns an iterator to the beginning of the `btree_multimap`.
558  using Base::begin;
559 
560  // btree_multimap::cbegin()
561  //
562  // Returns a const iterator to the beginning of the `btree_multimap`.
563  using Base::cbegin;
564 
565  // btree_multimap::end()
566  //
567  // Returns an iterator to the end of the `btree_multimap`.
568  using Base::end;
569 
570  // btree_multimap::cend()
571  //
572  // Returns a const iterator to the end of the `btree_multimap`.
573  using Base::cend;
574 
575  // btree_multimap::empty()
576  //
577  // Returns whether or not the `btree_multimap` is empty.
578  using Base::empty;
579 
580  // btree_multimap::max_size()
581  //
582  // Returns the largest theoretical possible number of elements within a
583  // `btree_multimap` under current memory constraints. This value can be
584  // thought of as the largest value of `std::distance(begin(), end())` for a
585  // `btree_multimap<Key, T>`.
586  using Base::max_size;
587 
588  // btree_multimap::size()
589  //
590  // Returns the number of elements currently within the `btree_multimap`.
591  using Base::size;
592 
593  // btree_multimap::clear()
594  //
595  // Removes all elements from the `btree_multimap`. Invalidates any references,
596  // pointers, or iterators referring to contained elements.
597  using Base::clear;
598 
599  // btree_multimap::erase()
600  //
601  // Erases elements within the `btree_multimap`. If an erase occurs, any
602  // references, pointers, or iterators are invalidated.
603  // Overloads are listed below.
604  //
605  // iterator erase(iterator position):
606  // iterator erase(const_iterator position):
607  //
608  // Erases the element at `position` of the `btree_multimap`, returning
609  // the iterator pointing to the element after the one that was erased
610  // (or end() if none exists).
611  //
612  // iterator erase(const_iterator first, const_iterator last):
613  //
614  // Erases the elements in the open interval [`first`, `last`), returning
615  // the iterator pointing to the element after the interval that was erased
616  // (or end() if none exists).
617  //
618  // template <typename K> size_type erase(const K& key):
619  //
620  // Erases the elements matching the key, if any exist, returning the
621  // number of elements erased.
622  using Base::erase;
623 
624  // btree_multimap::insert()
625  //
626  // Inserts an element of the specified value into the `btree_multimap`,
627  // returning an iterator pointing to the newly inserted element.
628  // Any references, pointers, or iterators are invalidated. Overloads are
629  // listed below.
630  //
631  // iterator insert(const value_type& value):
632  //
633  // Inserts a value into the `btree_multimap`, returning an iterator to the
634  // inserted element.
635  //
636  // iterator insert(value_type&& value):
637  //
638  // Inserts a moveable value into the `btree_multimap`, returning an iterator
639  // to the inserted element.
640  //
641  // iterator insert(const_iterator hint, const value_type& value):
642  // iterator insert(const_iterator hint, value_type&& value):
643  //
644  // Inserts a value, using the position of `hint` as a non-binding suggestion
645  // for where to begin the insertion search. Returns an iterator to the
646  // inserted element.
647  //
648  // void insert(InputIterator first, InputIterator last):
649  //
650  // Inserts a range of values [`first`, `last`).
651  //
652  // void insert(std::initializer_list<init_type> ilist):
653  //
654  // Inserts the elements within the initializer list `ilist`.
655  using Base::insert;
656 
657  // btree_multimap::emplace()
658  //
659  // Inserts an element of the specified value by constructing it in-place
660  // within the `btree_multimap`. Any references, pointers, or iterators are
661  // invalidated.
662  using Base::emplace;
663 
664  // btree_multimap::emplace_hint()
665  //
666  // Inserts an element of the specified value by constructing it in-place
667  // within the `btree_multimap`, using the position of `hint` as a non-binding
668  // suggestion for where to begin the insertion search.
669  //
670  // Any references, pointers, or iterators are invalidated.
671  using Base::emplace_hint;
672 
673  // btree_multimap::extract()
674  //
675  // Extracts the indicated element, erasing it in the process, and returns it
676  // as a C++17-compatible node handle. Overloads are listed below.
677  //
678  // node_type extract(const_iterator position):
679  //
680  // Extracts the element at the indicated position and returns a node handle
681  // owning that extracted data.
682  //
683  // template <typename K> node_type extract(const K& k):
684  //
685  // Extracts the element with the key matching the passed key value and
686  // returns a node handle owning that extracted data. If the `btree_multimap`
687  // does not contain an element with a matching key, this function returns an
688  // empty node handle.
689  //
690  // NOTE: when compiled in an earlier version of C++ than C++17,
691  // `node_type::key()` returns a const reference to the key instead of a
692  // mutable reference. We cannot safely return a mutable reference without
693  // std::launder (which is not available before C++17).
694  //
695  // NOTE: In this context, `node_type` refers to the C++17 concept of a
696  // move-only type that owns and provides access to the elements in associative
697  // containers (https://en.cppreference.com/w/cpp/container/node_handle).
698  // It does NOT refer to the data layout of the underlying btree.
699  using Base::extract;
700 
701  // btree_multimap::merge()
702  //
703  // Extracts all elements from a given `source` btree_multimap into this
704  // `btree_multimap`.
705  using Base::merge;
706 
707  // btree_multimap::swap(btree_multimap& other)
708  //
709  // Exchanges the contents of this `btree_multimap` with those of the `other`
710  // btree_multimap, avoiding invocation of any move, copy, or swap operations
711  // on individual elements.
712  //
713  // All iterators and references on the `btree_multimap` remain valid,
714  // excepting for the past-the-end iterator, which is invalidated.
715  using Base::swap;
716 
717  // btree_multimap::contains()
718  //
719  // template <typename K> bool contains(const K& key) const:
720  //
721  // Determines whether an element comparing equal to the given `key` exists
722  // within the `btree_multimap`, returning `true` if so or `false` otherwise.
723  //
724  // Supports heterogeneous lookup, provided that the map has a compatible
725  // heterogeneous comparator.
726  using Base::contains;
727 
728  // btree_multimap::count()
729  //
730  // template <typename K> size_type count(const K& key) const:
731  //
732  // Returns the number of elements comparing equal to the given `key` within
733  // the `btree_multimap`.
734  //
735  // Supports heterogeneous lookup, provided that the map has a compatible
736  // heterogeneous comparator.
737  using Base::count;
738 
739  // btree_multimap::equal_range()
740  //
741  // Returns a half-open range [first, last), defined by a `std::pair` of two
742  // iterators, containing all elements with the passed key in the
743  // `btree_multimap`.
744  using Base::equal_range;
745 
746  // btree_multimap::find()
747  //
748  // template <typename K> iterator find(const K& key):
749  // template <typename K> const_iterator find(const K& key) const:
750  //
751  // Finds an element with the passed `key` within the `btree_multimap`.
752  //
753  // Supports heterogeneous lookup, provided that the map has a compatible
754  // heterogeneous comparator.
755  using Base::find;
756 
757  // btree_multimap::lower_bound()
758  //
759  // template <typename K> iterator lower_bound(const K& key):
760  // template <typename K> const_iterator lower_bound(const K& key) const:
761  //
762  // Finds the first element with a key that is not less than `key` within the
763  // `btree_multimap`.
764  //
765  // Supports heterogeneous lookup, provided that the map has a compatible
766  // heterogeneous comparator.
767  using Base::lower_bound;
768 
769  // btree_multimap::upper_bound()
770  //
771  // template <typename K> iterator upper_bound(const K& key):
772  // template <typename K> const_iterator upper_bound(const K& key) const:
773  //
774  // Finds the first element with a key that is greater than `key` within the
775  // `btree_multimap`.
776  //
777  // Supports heterogeneous lookup, provided that the map has a compatible
778  // heterogeneous comparator.
779  using Base::upper_bound;
780 
781  // btree_multimap::get_allocator()
782  //
783  // Returns the allocator function associated with this `btree_multimap`.
784  using Base::get_allocator;
785 
786  // btree_multimap::key_comp();
787  //
788  // Returns the key comparator associated with this `btree_multimap`.
789  using Base::key_comp;
790 
791  // btree_multimap::value_comp();
792  //
793  // Returns the value comparator associated with this `btree_multimap`.
794  using Base::value_comp;
795 };
796 
797 // absl::swap(absl::btree_multimap<>, absl::btree_multimap<>)
798 //
799 // Swaps the contents of two `absl::btree_multimap` containers.
800 template <typename K, typename V, typename C, typename A>
802  return x.swap(y);
803 }
804 
805 // absl::erase_if(absl::btree_multimap<>, Pred)
806 //
807 // Erases all elements that satisfy the predicate pred from the container.
808 // Returns the number of erased elements.
809 template <typename K, typename V, typename C, typename A, typename Pred>
811  btree_multimap<K, V, C, A> &map, Pred pred) {
813 }
814 
815 namespace container_internal {
816 
817 // A parameters structure for holding the type parameters for a btree_map.
818 // Compare and Alloc should be nothrow copy-constructible.
819 template <typename Key, typename Data, typename Compare, typename Alloc,
820  int TargetNodeSize, bool IsMulti>
821 struct map_params : common_params<Key, Compare, Alloc, TargetNodeSize, IsMulti,
822  /*IsMap=*/true, map_slot_policy<Key, Data>> {
823  using super_type = typename map_params::common_params;
824  using mapped_type = Data;
825  // This type allows us to move keys when it is safe to do so. It is safe
826  // for maps in which value_type and mutable_value_type are layout compatible.
827  using slot_policy = typename super_type::slot_policy;
828  using slot_type = typename super_type::slot_type;
830  using init_type = typename super_type::init_type;
831 
832  template <typename V>
833  static auto key(const V &value) -> decltype(value.first) {
834  return value.first;
835  }
836  static const Key &key(const slot_type *s) { return slot_policy::key(s); }
837  static const Key &key(slot_type *s) { return slot_policy::key(s); }
838  // For use in node handle.
839  static auto mutable_key(slot_type *s)
840  -> decltype(slot_policy::mutable_key(s)) {
841  return slot_policy::mutable_key(s);
842  }
843  static mapped_type &value(value_type *value) { return value->second; }
844 };
845 
846 } // namespace container_internal
847 
849 } // namespace absl
850 
851 #endif // ABSL_CONTAINER_BTREE_MAP_H_
absl::container_internal::btree_multimap_container
Definition: abseil-cpp/absl/container/internal/btree_container.h:682
find
static void ** find(grpc_chttp2_stream_map *map, uint32_t key)
Definition: stream_map.cc:99
absl::container_internal::map_params::value
static mapped_type & value(value_type *value)
Definition: abseil-cpp/absl/container/btree_map.h:843
begin
char * begin
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1007
absl::container_internal::map_params::mutable_key
static auto mutable_key(slot_type *s) -> decltype(slot_policy::mutable_key(s))
Definition: abseil-cpp/absl/container/btree_map.h:839
absl::btree_multimap::btree_multimap
btree_multimap()
Definition: abseil-cpp/absl/container/btree_map.h:552
y
const double y
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3611
absl::container_internal::map_params::value_type
typename super_type::value_type value_type
Definition: abseil-cpp/absl/container/btree_map.h:829
absl::FormatConversionChar::s
@ s
absl::container_internal::btree_map_container
Definition: abseil-cpp/absl/container/internal/btree_container.h:397
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
absl::container_internal::map_params::super_type
typename map_params::common_params super_type
Definition: abseil-cpp/absl/container/btree_map.h:823
absl::container_internal::map_params
Definition: abseil-cpp/absl/container/btree_map.h:63
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:480
absl::container_internal::btree_access::erase_if
static auto erase_if(BtreeContainer &container, Pred pred) -> typename BtreeContainer::size_type
Definition: abseil-cpp/absl/container/internal/btree.h:2808
absl::btree_map::btree_map
btree_map()
Definition: abseil-cpp/absl/container/btree_map.h:130
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
swap
#define swap(a, b)
Definition: qsort.h:111
absl::swap
void swap(btree_map< K, V, C, A > &x, btree_map< K, V, C, A > &y)
Definition: abseil-cpp/absl/container/btree_map.h:474
extract
int extract(FILE *in, struct access *index, off_t offset, unsigned char *buf, int len)
Definition: bloaty/third_party/zlib/examples/zran.c:249
absl::compare_internal::value_type
int8_t value_type
Definition: abseil-cpp/absl/types/compare.h:45
Base
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5141
absl::erase_if
btree_map< K, V, C, A >::size_type erase_if(btree_map< K, V, C, A > &map, Pred pred)
Definition: abseil-cpp/absl/container/btree_map.h:483
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
absl::flags_internal::Alloc
void * Alloc(FlagOpFn op)
Definition: abseil-cpp/absl/flags/internal/flag.h:102
absl::container_internal::map_params::key
static auto key(const V &value) -> decltype(value.first)
Definition: abseil-cpp/absl/container/btree_map.h:833
google_benchmark.example.empty
def empty(state)
Definition: example.py:31
absl::container_internal::map_params::key
static const Key & key(slot_type *s)
Definition: abseil-cpp/absl/container/btree_map.h:837
key
const char * key
Definition: hpack_parser_table.cc:164
absl::container_internal::map_params::mapped_type
Data mapped_type
Definition: abseil-cpp/absl/container/btree_map.h:824
insert
static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey, upb_value val, uint32_t hash, hashfunc_t *hashfunc, eqlfunc_t *eql)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:1431
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
testing::Key
internal::KeyMatcher< M > Key(M inner_matcher)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:9141
absl::container_internal::map_params::key
static const Key & key(const slot_type *s)
Definition: abseil-cpp/absl/container/btree_map.h:836
absl::container_internal::map_params::slot_policy
typename super_type::slot_policy slot_policy
Definition: abseil-cpp/absl/container/btree_map.h:827
absl::strings_internal::Compare
int Compare(const BigUnsigned< N > &lhs, const BigUnsigned< M > &rhs)
Definition: abseil-cpp/absl/strings/internal/charconv_bigint.h:353
absl::container_internal::map_params::init_type
typename super_type::init_type init_type
Definition: abseil-cpp/absl/container/btree_map.h:830
absl::container_internal::map_params::slot_type
typename super_type::slot_type slot_type
Definition: abseil-cpp/absl/container/btree_map.h:828
contains
static int contains(grpc_timer_heap *pq, grpc_timer *el)
Definition: iomgr/timer_heap_test.cc:43
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
absl::btree_multimap
Definition: abseil-cpp/absl/container/btree_map.h:506
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
generate-asm-lcov.merge
def merge(callgrind_files, srcs)
Definition: generate-asm-lcov.py:50
absl::btree_map
Definition: abseil-cpp/absl/container/btree_map.h:84


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:50