aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Konovalov <maxim@FreeBSD.org>2024-08-03 19:45:47 +0000
committerMaxim Konovalov <maxim@FreeBSD.org>2024-08-03 19:45:47 +0000
commit503b7f94d831642308585c980a7cabe4470960d0 (patch)
treebe19a01629b6519406722403e6b598b178ae0125
parent2edac5a60a57a2a6ef80c61079d427c4ee31b7a9 (diff)
tree.3: the example code fixed
PR: 280566 Reviewed by: dougm
-rw-r--r--share/man/man3/tree.310
1 files changed, 5 insertions, 5 deletions
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 <sys/tree.h>
#include <err.h>
#include <stdio.h>
@@ -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