Page MenuHomeFreeBSD

D3371.id7911.diff
No OneTemporary

D3371.id7911.diff

Index: share/man/man3/tree.3
===================================================================
--- share/man/man3/tree.3
+++ share/man/man3/tree.3
@@ -30,7 +30,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd January 24, 2015
+.Dd August 12, 2015
.Dt TREE 3
.Os
.Sh NAME
@@ -95,6 +95,7 @@
.Nm RB_FOREACH_REVERSE_SAFE ,
.Nm RB_INIT ,
.Nm RB_INSERT ,
+.Nm RB_NUMNODES ,
.Nm RB_REMOVE
.Nd "implementations of splay and red-black trees"
.Sh SYNOPSIS
@@ -186,6 +187,8 @@
.Fn RB_INSERT NAME "RB_HEAD *head" "struct TYPE *elm"
.Ft "struct TYPE *"
.Fn RB_REMOVE NAME "RB_HEAD *head" "struct TYPE *elm"
+.Ft void
+.Fn RB_NUMNODES "TYPE" "NAME" "RB_HEAD *head" "COUNTER"
.Sh DESCRIPTION
These macros define data structures for different types of trees:
splay trees and red-black trees.
@@ -557,6 +560,14 @@
The
.Fn RB_EMPTY
macro should be used to check whether a red-black tree is empty.
+.Pp
+The
+.Fn RB_NUMNODES
+macro traverse the tree referenced by
+.Ar head
+counting the number of nodes.
+.Ar COUNTER
+is initialized to 0 before traversing and incremented by one for each nodes.
.Sh NOTES
Trying to free a tree in the following way is a common error:
.Bd -literal -offset indent
Index: sys/sys/tree.h
===================================================================
--- sys/sys/tree.h
+++ sys/sys/tree.h
@@ -798,4 +798,12 @@
((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \
(x) = (y))
+#define RB_NUMNODES(type, name, head, cnt) do { \
+ type *t; \
+ cnt = 0; \
+ RB_FOREACH(t, name, head) { \
+ cnt++; \
+ } \
+} while (0);
+
#endif /* _SYS_TREE_H_ */

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 13, 3:53 PM (7 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26934851
Default Alt Text
D3371.id7911.diff (1 KB)

Event Timeline