__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 () constvoid clear ()template<typename It> void copy_from_range (It, It)bool empty () constiterator end ()const_iterator end () constiterator 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) constCmp_Fn & get_cmp_fn ()const Cmp_Fn & get_cmp_fn () conststd::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) constsize_type max_size () constnode_iterator node_begin ()β hands you anode_iteratorpointing at the node sitting at the root of the tree. πnode_const_iterator node_begin () constβ same thing but const, so aconstnode_iteratorfor the root node. πnode_iterator node_end ()β hands you anode_iteratorpointing at a node just past a leaf of the tree.node_const_iterator node_end () constβ the const version: a constnode_iteratorfor a node just after a leaf. πmapped_reference operator[] (key_const_reference r_key)reverse_iterator rbegin ()const_reverse_iterator rbegin () constreverse_iterator rend ()const_reverse_iterator rend () constsize_type size () constvoid 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