__GNU_PBDS::DETAIL::RB_TREE_MAP(3)

πŸ’… __gnu_pbds::detail::rb_tree_map πŸ’…

okay so bestie, you just opened the Library Functions Manual page (section 3) for __gnu_pbds::detail::rb_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc >, and it ships with libstdc++. She's a red-black tree. A classic. An icon. Sit down, hydrate, we're doing this together. πŸ¦‹


✨ NAME ✨

__gnu_pbds::detail::rb_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc > β€” Red-Black tree.

That's the whole name. That's the whole energy. 🌳


✨ SYNOPSIS ✨

First things first, you gotta pull her in:

#include <rb_tree_.hpp>

πŸŽ€ Public Types πŸŽ€

all the type aliases she's serving, no cap:

typedef _Alloc allocator_type
typedef Cmp_Fn cmp_fn
typedef std::pair< size_type, size_type > comp_hash
typedef base_type::const_iterator const_iterator
typedef base_type::const_pointer const_pointer
typedef base_type::const_reference const_reference
typedef base_type::const_reverse_iterator const_reverse_iterator
typedef rb_tree_tag container_category
typedef _Alloc::difference_type difference_type
typedef base_type::iterator iterator
typedef base_type::key_const_pointer key_const_pointer
typedef base_type::key_const_reference key_const_reference
typedef base_type::key_pointer key_pointer
typedef base_type::key_reference key_reference
typedef base_type::key_type key_type
typedef base_type::mapped_const_pointer mapped_const_pointer
typedef base_type::mapped_const_reference mapped_const_reference
typedef base_type::mapped_pointer mapped_pointer
typedef base_type::mapped_reference mapped_reference
typedef base_type::mapped_type mapped_type
typedef __nothrowcopy::indicator no_throw_indicator
typedef traits_type::node_const_iterator node_const_iterator
typedef traits_type::node_iterator node_iterator
typedef base_type::node_update node_update
typedef base_type::const_iterator point_const_iterator
typedef base_type::point_iterator point_iterator
typedef base_type::pointer pointer
typedef base_type::reference reference
typedef base_type::reverse_iterator reverse_iterator
typedef _Alloc::size_type size_type
typedef integral_constant< int, Store_Hash > store_extra
typedef stored_data< value_type, size_type, Store_Hash > stored_data_type
typedef base_type::value_type value_type

🌸 Public Member Functions 🌸

here's every single one, we do not skip, we do not gatekeep:

  • rb_tree_map (const Cmp_Fn &)
  • rb_tree_map (const Cmp_Fn &, const node_update &)
  • rb_tree_map (const rb_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc > &)
  • iterator begin ()
  • const_iterator begin () const
  • void clear ()
  • template<typename It> void copy_from_range (It, It)
  • bool empty () const
  • iterator end ()
  • const_iterator end () const
  • iterator erase (iterator)
  • bool erase (key_const_reference)
  • reverse_iterator erase (reverse_iterator)
  • template<typename Pred> size_type erase_if (Pred)
  • point_iterator find (key_const_reference)
  • point_const_iterator find (key_const_reference) const
  • Cmp_Fn & get_cmp_fn ()
  • const Cmp_Fn & get_cmp_fn () const
  • std::pair< point_iterator, bool > insert (const_reference)
  • void join (rb_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc > &)
  • point_iterator lower_bound (key_const_reference)
  • point_const_iterator lower_bound (key_const_reference) const
  • size_type max_size () const
  • node_iterator node_begin () β€” hands you a node_iterator pointing at the node sitting at the root of the tree. πŸ‘‘
  • node_const_iterator node_begin () const β€” same thing but const, so a const node_iterator for the root node. πŸ”’
  • node_iterator node_end () β€” hands you a node_iterator pointing at a node just past a leaf of the tree.
  • node_const_iterator node_end () const β€” the const version: a const node_iterator for a node just after a leaf. πŸƒ
  • mapped_reference operator[] (key_const_reference r_key)
  • reverse_iterator rbegin ()
  • const_reverse_iterator rbegin () const
  • reverse_iterator rend ()
  • const_reverse_iterator rend () const
  • size_type size () const
  • void split (key_const_reference, rb_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc > &)
  • void swap (bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc > &)
  • void swap (rb_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc > &)
  • point_iterator upper_bound (key_const_reference)
  • point_const_iterator upper_bound (key_const_reference) const

πŸ’– Public Attributes πŸ’–

just two lil guys, and yes, they're public:

no_throw_indicator m_no_throw_copies_indicator
store_extra m_store_extra_indicator

🧚 Protected Types 🧚

for the inner circle only:

typedef node_alloc_traits::value_type node
typedef node_alloc_traits::allocator_type node_allocator
typedef traits_type::null_node_update_pointer null_node_update_pointer
typedef types_traits< Key, Mapped, _Alloc, false > traits_base

πŸ”₯ Protected Member Functions πŸ”₯

the backstage crew. still listing all of them, obviously:

void actual_erase_node (node_pointer)
template<typename Node_Update_> void apply_update (node_pointer, Node_Update_ *)
void apply_update (node_pointer, null_node_update_pointer)
std::pair< node_pointer, bool > erase (node_pointer)
node_pointer get_new_node_for_leaf_insert (const_reference, false_type)
node_pointer get_new_node_for_leaf_insert (const_reference, true_type)
void initialize_min_max ()
iterator insert_imp_empty (const_reference)
std::pair< point_iterator, bool > insert_leaf (const_reference)
iterator insert_leaf_new (const_reference, node_pointer, bool)
void join_finish (bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc > &)
bool join_prep (bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc > &)
size_type recursive_count (node_pointer) const
void rotate_left (node_pointer)
void rotate_parent (node_pointer)
void rotate_right (node_pointer)
void split_finish (bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc > &)
bool split_prep (key_const_reference, bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc > &)
void update_min_max_for_erased_node (node_pointer)
void update_subtree_size (node_pointer)
template<typename Node_Update_> void update_to_top (node_pointer, Node_Update_ *)
void update_to_top (node_pointer, null_node_update_pointer)
void value_swap (bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc > &)

look at rotate_left and rotate_right sitting there being the whole point of a red-black tree. main character behavior fr. πŸ’…

⭐ Static Protected Member Functions ⭐

one single static, and she's protected:

static void clear_imp (node_pointer)

πŸ“ Protected Attributes πŸ“

node_pointer m_p_head
size_type m_size

🌈 Static Protected Attributes 🌈

static node_allocator s_node_allocator

πŸ’œ Detailed Description πŸ’œ

the class, in her full template glory:

template<typename Key, typename Mapped, typename Cmp_Fn, typename Node_And_It_Traits, typename _Alloc>
class __gnu_pbds::detail::rb_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc >

and the description glued onto her is Red-Black tree. β€” yes, the source literally has a stray " mashed in front of it (_Alloc >"Red-Black tree.). Doxygen has zero chill and we respect it. 😭

okay and the actual tea about the implementation:

This implementation uses an idea from the SGI STL (using a header node which is needed for efficient iteration).

header node = efficient iteration. she said i'm not walking that whole tree for nothing. πŸšΆβ€β™€οΈ


🫢 Member Function Documentation 🫢

these next ones are all [inline] and all [inherited] β€” they come from bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc >, so show them some love too. πŸ’–

bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc >::node_iterator β€” __gnu_pbds::detail::bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc >::node_begin () [inline], [inherited]

hands back a node_iterator for the node at the root of the tree. 🌳

bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc >::node_const_iterator β€” __gnu_pbds::detail::bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc >::node_begin () const [inline], [inherited]

same deal, but const: a const node_iterator pointing at the root node. πŸ”’

bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc >::node_iterator β€” __gnu_pbds::detail::bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc >::node_end () [inline], [inherited]

gives you a node_iterator for a node that sits just after a leaf of the tree. πŸƒ

bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc >::node_const_iterator β€” __gnu_pbds::detail::bin_search_tree_map< Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc >::node_end () const [inline], [inherited]

the const twin: a const node_iterator for a node just after a leaf of the tree. ✨


πŸ‘‘ Author πŸ‘‘

Generated automatically by Doxygen for libstdc++ from the source code.

Doxygen wrote it, not a human, and honestly she ate anyway. πŸ€–πŸ’…


and that's the page, bestie!! this was section 3 of the libstdc++ manual, filed under __gnu_pbds..., _Alloc >(3), brought to you by libstdc++. go forth and balance your trees, you've got this πŸŽ€βœ¨πŸ’–

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms