Skip to content

Commit 42c8986

Browse files
authored
Merge pull request #588 from sysprog21/refine-rb-comment
Refine rbtree comment for clarity and accuracy
2 parents 0daac70 + 066602e commit 42c8986

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/map.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ struct map_internal {
3030
map_cmp_t (*comparator)(const void *, const void *);
3131
};
3232

33-
/* Each node in the red-black tree consumes at least 1 byte of space (for the
34-
* linkage if nothing else), so there are a maximum of sizeof(void *) << 3
35-
* red-black tree nodes in any process (and thus, at most sizeof(void *) << 3
36-
* nodes in any red-black tree). The choice of algorithm bounds the depth of
37-
* a tree to twice the binary logarithm (base 2) of the number of elements in
38-
* the tree; the following bound applies.
33+
/* Each red–black tree node requires at least one byte of storage (for its
34+
* linkage). A one-byte object could support up to 2^{sizeof(void *) * 8} nodes
35+
* in an address space. However, the red–black tree algorithm guarantees that
36+
* the tree depth is bounded by 2 * log₂(n), where n is the number of nodes.
37+
*
38+
* For operations such as insertion and deletion, a fixed-size array is used to
39+
* track the path through the tree. RB_MAX_DEPTH is conservatively defined as 16
40+
* times the size of a pointer to ensure that the array is large enough for any
41+
* realistic tree, regardless of the theoretical maximum node count.
3942
*/
4043
#define RB_MAX_DEPTH (sizeof(void *) << 4)
4144

0 commit comments

Comments
 (0)