Add a complete example to tsearch(3)
ClosedPublic

Authored by brd on Jun 5 2017, 5:07 AM.

Details

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
brd created this revision.Jun 5 2017, 5:07 AM
sevan added a subscriber: sevan.Jun 5 2017, 11:42 AM
sevan added inline comments.
head/lib/libc/stdlib/tsearch.3
134

"each one of them against each other"?

135

"by adding them to the tree and attempting"?

136

s/uses/using?

brueffer added inline comments.
head/lib/libc/stdlib/tsearch.3
136

.Fn tfind (see the .Fn twalk just above the EXAMPLES section); same for tdelete.

137

Please start a new sentence on a new line; ".Fn twalk" (same as above).

brd updated this revision to Diff 29255.Jun 6 2017, 2:11 AM
brd marked 5 inline comments as done.

Address feedback

sevan added inline comments.Jun 12 2017, 10:43 PM
head/lib/libc/stdlib/tsearch.3
134–140

I find the paragraph to be quite difficult to parse in one pass.
Just a suggestion but It may be better to break it up rather than using more than one conjunction to say it as one.

"The following example takes in four strings and compares each one of them against each other before adding them to the tree. The fourth string is added a second time. tfind is used to verify that a duplicate is not added and tdelete is used to remove it"

question, is the it on the end of the sentence referring to a duplicate or any entry that's been added?

brueffer added inline comments.Jun 13 2017, 10:20 AM
head/lib/libc/stdlib/tsearch.3
134–140

I agree with sevan, I've had problems understanding that paragraph (refrained from commenting since he already had :-). The suggested re-wording sounds like an improvement. The rest looks good!

wblock added inline comments.Jun 16 2017, 4:20 PM
head/lib/libc/stdlib/tsearch.3
134–140

Hm. The example code is... not overly clear. But maybe this describes it?

This example uses
.Fn tsearch
to search for four strings in
.Dv root .
Because the strings are not already present, they are added.
.Fn tsearch
is called twice on the fourth string to demonstrate that a string is not added when it is already present.
.Fn tfind
is used to find the single instance of the fourth string, and
.Fn tdelete
removes it.
Finally,
.Fn twalk
is used to return and display the resulting binary search tree.
brd updated this revision to Diff 30746.Jul 13 2017, 9:14 PM

Thanks @wblock! That is much better!

brd marked 3 inline comments as done.Jul 13 2017, 9:15 PM
wblock accepted this revision.Jul 14 2017, 4:00 PM

Thank you. Please check with igor and mandoc -Tlint before commit.

This revision is now accepted and ready to land.Jul 14 2017, 4:00 PM
This revision was automatically updated to reflect the committed changes.