rb_tree: add augmentation comments

Add comments to better explain why augmentation is done in several places.
Reviewed by:	alc
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D36646
This commit is contained in:
Doug Moore 2022-09-26 12:39:16 -05:00
parent f375bf0e6f
commit b5b07c71e8

View File

@ -598,6 +598,10 @@ name##_RB_INSERT_COLOR(struct name *head, \
RB_ROTATE(parent, child, sibdir, field); \
_RB_UP(child, field) = gpar; \
RB_SWAP_CHILD(head, gpar, parent, child, field); \
/* \
* Elements rotated down have new, smaller subtrees, \
* so update augmentation for them. \
*/ \
if (elm != child) \
RB_AUGMENT_CHECK(elm); \
RB_AUGMENT_CHECK(parent); \
@ -724,6 +728,11 @@ name##_RB_REMOVE_COLOR(struct name *head, \
RB_ROTATE(parent, elm, elmdir, field); \
RB_SET_PARENT(elm, gpar, field); \
RB_SWAP_CHILD(head, gpar, parent, elm, field); \
/* \
* An element rotated down, but not into the search \
* path has a new, smaller subtree, so update \
* augmentation for it. \
*/ \
if (sib != elm) \
RB_AUGMENT_CHECK(sib); \
return (parent); \
@ -779,6 +788,11 @@ name##_RB_REMOVE(struct name *head, struct type *out) \
} \
_RB_AUGMENT_WALK(parent, opar, field); \
if (opar != NULL) { \
/* \
* Elements rotated into the search path have \
* changed subtrees, so update augmentation for \
* them if AUGMENT_WALK didn't. \
*/ \
RB_AUGMENT_CHECK(opar); \
RB_AUGMENT_CHECK(RB_PARENT(opar, field)); \
} \
@ -811,6 +825,11 @@ name##_RB_INSERT(struct name *head, struct type *elm) \
tmp = name##_RB_INSERT_COLOR(head, parent, elm); \
_RB_AUGMENT_WALK(elm, tmp, field); \
if (tmp != NULL) \
/* \
* An element rotated into the search path has a \
* changed subtree, so update augmentation for it if \
* AUGMENT_WALK didn't. \
*/ \
RB_AUGMENT_CHECK(tmp); \
return (NULL); \
}