]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
rb_tree: augmentation shortcut
authorDoug Moore <dougm@FreeBSD.org>
Wed, 21 Sep 2022 04:21:14 +0000 (23:21 -0500)
committerDoug Moore <dougm@FreeBSD.org>
Wed, 21 Sep 2022 04:21:14 +0000 (23:21 -0500)
commitb16f993ec2cafe48fae96ca0eb27224951b30d7e
tree2cb094cc37bb8d06deb392cced533384a1ebceee
parentd0b235c7152cde08c741f08e5e0834eb07651799
rb_tree: augmentation shortcut

RB-tree augmentation maintains data in each node of the tree that
represents the product of some associative operator applied to all the
nodes of the subtree rooted at that node. If a node in the tree
changes, augmentation data for the node is updated for that node and
all nodes on the path from that node to the tree root. However,
sometimes, augmenting a node changes no data in that node,
particularly if the associated operation is something involving 'max'
or 'min'. If augmentation changes nothing in a node, then the work of
walking to the tree root from that point is pointless, because
augmentation will change nothing in those nodes either. This change
makes it possible to avoid that wasted work.

Define RB_AUGMENT_CHECK as a macro much like RB_AUGMENT, but which
returns a value 'true' when augmentation changes the augmentation data
of a node, and false otherwise. Change code that unconditionally walks
and augments to the top of tree to code that stops once an
augmentation has no effect. In the case of rebalancing the tree after
insertion or deletion, where previously a node rotated into the path
was inevitably augmented on the march to the tree root, now check to
see if it needs augmentation because the march to the tree root
stopped before reaching it.

Change the augmentation function in iommu_gas.c so that it returns
true/false to indicate whether the augmentation had any effect.

Reviewed by: alc, kib
MFC after: 3 weeks
Differential Revision: https://reviews.freebsd.org/D36509
share/man/man3/Makefile
share/man/man3/tree.3
sys/dev/iommu/iommu_gas.c
sys/sys/tree.h