diff --git a/share/man/man3/tree.3 b/share/man/man3/tree.3 index e6d855c5ade0..83d005a5e481 100644 --- a/share/man/man3/tree.3 +++ b/share/man/man3/tree.3 @@ -28,7 +28,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd July 27, 2020 +.Dd August 2, 2024 .Dt TREE 3 .Os .Sh NAME @@ -675,6 +675,8 @@ To maintain the sum of the values in the tree, each element maintains the sum of its value and the sums from its left and right subtrees. Lastly, the internal structure of the tree is printed. .Bd -literal -offset 3n +#define RB_AUGMENT(entry) sumaug(entry) + #include #include #include @@ -691,7 +693,7 @@ intcmp(struct node *e1, struct node *e2) return (e1->i < e2->i ? -1 : e1->i > e2->i); } -int +void sumaug(struct node *e) { e->sum = e->i; @@ -700,7 +702,6 @@ sumaug(struct node *e) if (RB_RIGHT(e, entry) != NULL) e->sum += RB_RIGHT(e, entry)->sum; } -#define RB_AUGMENT(entry) sumaug(entry) RB_HEAD(inttree, node) head = RB_INITIALIZER(&head); RB_GENERATE(inttree, node, entry, intcmp) @@ -749,8 +750,7 @@ main(void) printf("%d\en", n->i); } print_tree(RB_ROOT(&head)); - printf("Sum of values = %d\n", RB_ROOT(&head)->sum); - printf("\en"); + printf("\enSum of values = %d\en", RB_ROOT(&head)->sum); return (0); } .Ed