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