[libcxx-commits] [libcxx] [libc++] Document how __tree is layed out and how we iterate through it (PR #152453)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 11 12:52:31 PDT 2025
================
@@ -49,6 +49,27 @@
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
+// __tree is a red-black-tree implementation used for the associative containers (i.e. (multi)map/set). To allow for
+// constant time lookup, it stores
+// - (1) a pointer to the node with the smallest (i.e. leftmost) element, namely __begin_node_
+// - (2) the number of nodes in the tree, namely __size_
----------------
ldionne wrote:
```suggestion
// __tree is a red-black-tree implementation used for the associative containers (i.e. (multi)map/set). It stores:
// - (1) a pointer to the node with the smallest (i.e. leftmost) element, namely __begin_node_
// - (2) the number of nodes in the tree, namely __size_
// - (3) a pointer to the root of the tree, namely __end_node_.
//
// Storing (1) and (2) is required to allow for constant time lookups. A tree looks like this in memory:
//
// etc...
```
https://github.com/llvm/llvm-project/pull/152453
More information about the libcxx-commits
mailing list