/[base]/head/sys/sys/tree.h
ViewVC logotype

Log of /head/sys/sys/tree.h

Parent Directory Parent Directory | Revision Log Revision Log


Links to HEAD: (view) (download) (annotate)
Sticky Revision:

Revision 365223 - (view) (download) (annotate) - [select for diffs]
Modified Tue Sep 1 22:12:58 2020 UTC (3 years, 3 months ago) by mjg
File length: 28604 byte(s)
Diff to previous 363450
sys: clean up empty lines in .c and .h files


Revision 363450 - (view) (download) (annotate) - [select for diffs]
Modified Thu Jul 23 17:16:20 2020 UTC (3 years, 4 months ago) by dougm
File length: 28606 byte(s)
Diff to previous 362617
Rank balanced (RB) trees are a class of balanced trees that includes
AVL trees, red-black trees, and others. Weak AVL (wavl) trees are a
recently discovered member of that class. This change replaces
red-black rebalancing with weak AVL rebalancing in the RB tree macros.

Wavl trees sit between AVL and red-black trees in terms of how
strictly balance is enforced. They have the stricter balance of AVL
trees as the tree is built - a wavl tree is an AVL tree until the
first deletion. Once removals start, wavl trees are lazier about
rebalancing than AVL trees, so that removals can be fast, but the
balance of the tree can decay to that of a red-black tree. Subsequent
insertions can push balance back toward the stricter AVL conditions.

Removing a node from a wavl tree never requires more than two
rotations, which is better than either red-black or AVL
trees. Inserting a node into a wavl tree never requires more than two
rotations, which matches red-black and AVL trees. The only
disadvantage of wavl trees to red-black trees is that more insertions
are likely to adjust the tree a bit. That's the cost of keeping the
tree more balanced.

Testing has shown that for the cases where red-black trees do worst,
wavl trees better balance leads to faster lookups, so that if lookups
outnumber insertions by a nontrivial amount, lookup time saved exceeds
the extra cost of balancing.

Reviewed by:	alc, gbe, markj
Tested by:	pho
Discussed with:	emaste
Differential Revision:	https://reviews.freebsd.org/D25480


Revision 362617 - (view) (download) (annotate) - [select for diffs]
Modified Thu Jun 25 17:44:14 2020 UTC (3 years, 5 months ago) by dougm
File length: 28520 byte(s)
Diff to previous 362552
Eliminate the color field from the RB element struct. Identify the
color of a node (or, really, the color of the link from the parent to
the node) by using one of the last two bits of the parent pointer in
that parent node. Adjust rebalancing methods to account for where
colors are stored, and the fact that null children have a color too.

Adjust RB_PARENT and RB_SET_PARENT to account for this change.

Reviewed by:	markj
Tested by:	pho, hselasky
Differential Revision:	https://reviews.freebsd.org/D25418


Revision 362552 - (view) (download) (annotate) - [select for diffs]
Modified Tue Jun 23 20:02:55 2020 UTC (3 years, 5 months ago) by dougm
File length: 27034 byte(s)
Diff to previous 362450
Define RB_SET_PARENT to do all assignments to rb parent
pointers. Define RB_SWAP_CHILD to replace the child of a parent with
its twin, and use it in 4 places. Use RB_SET in rb_link_node to remove
the only linuxkpi reference to color, and then drop color- and
parent-related definitions that are defined and used only in rbtree.h.

This is intended to be entirely cosmetic, with no impact on program
behavior, and leave RB_PARENT and RB_SET_PARENT as the only ways to
read and write rb parent pointers.

Reviewed by:	markj, kib
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D25264


Revision 362450 - (view) (download) (annotate) - [select for diffs]
Modified Sat Jun 20 20:25:39 2020 UTC (3 years, 5 months ago) by dougm
File length: 27152 byte(s)
Diff to previous 362139
In concluding RB_REMOVE_COLOR, in the case when the sibling of the
root of the too-short tree is black and at least one of the children
of that sibling is red, either one or two rotations finish the
rebalancing. In the case when both of the children are red, the
current implementation uses two rotations where only one is
necessary. This change removes that extra rotation, and in that case
also removes a needless black-to-red-to-black recoloring.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D25335


Revision 362139 - (view) (download) (annotate) - [select for diffs]
Modified Sat Jun 13 01:54:09 2020 UTC (3 years, 6 months ago) by dougm
File length: 27362 byte(s)
Diff to previous 362000
Linuxkpi uses the rb-tree structures without using their interfaces,
making them break when the representation changes. Revert changes that
eliminated the color field from rb-trees, leaving everything as it was
before.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D25250


Revision 362000 - (view) (download) (annotate) - [select for diffs]
Modified Wed Jun 10 03:36:17 2020 UTC (3 years, 6 months ago) by dougm
File length: 27525 byte(s)
Diff to previous 361997
Fixup r361997 by balancing parens.  Duh.


Revision 361997 - (view) (download) (annotate) - [select for diffs]
Modified Wed Jun 10 02:50:25 2020 UTC (3 years, 6 months ago) by dougm
File length: 27524 byte(s)
Diff to previous 361984
Restore an RB_COLOR macro, for the benefit of a bit of DIAGNOSTIC code
that depends on it.

Reported by:	rpokala, mjguzik
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D25204


Revision 361984 - (view) (download) (annotate) - [select for diffs]
Modified Tue Jun 9 20:19:11 2020 UTC (3 years, 6 months ago) by dougm
File length: 27259 byte(s)
Diff to previous 361727
To reduce the size of an rb_node, drop the color field. Set the least
significant bit in the pointer to the node from its parent to indicate
that the node is red. Have the tree rotation macros leave the
old-parent/new-child node red and the new-parent/old-child node black.

This change makes RB_LEFT and RB_RIGHT no longer assignable, and
RB_COLOR no longer defined. Any code that modifies the tree or
examines a node color would have to be modified after this change.

Reviewed by:	markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D25105


Revision 361727 - (view) (download) (annotate) - [select for diffs]
Modified Tue Jun 2 17:18:16 2020 UTC (3 years, 6 months ago) by dougm
File length: 27362 byte(s)
Diff to previous 361640
Remove from RB_REMOVE_COLOR some null checks where the pointer checked
is provably never null.  Restructure the surrounding code just enough
to make the non-nullness obvious.

Reviewed by:	markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D25089


Revision 361640 - (view) (download) (annotate) - [select for diffs]
Modified Sat May 30 01:48:12 2020 UTC (3 years, 6 months ago) by dougm
File length: 27499 byte(s)
Diff to previous 361324
RB_REMOVE invokes RB_REMOVE_COLOR either when child is red or child is
null. In the first case, RB_REMOVE_COLOR just changes the child to
black and returns. With this change, RB_REMOVE handles that case, and
drops the child argument to RB_REMOVE_COLOR, since that value is
always null.

RB_REMOVE_COLOR is changed to remove a couple of unneeded tests, and
to eliminate some deep indentation.

RB_ISRED is defined to combine a null check with a test for redness,
to replace that combination in several places.

Reviewed by:	markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D25032


Revision 361324 - (view) (download) (annotate) - [select for diffs]
Modified Thu May 21 05:34:02 2020 UTC (3 years, 6 months ago) by dougm
File length: 27901 byte(s)
Diff to previous 357173
For the case when RB_REMOVE requires a nontrivial search to find the
node to replace the one being removed, restructure to first remove the
replacement node and correct the parent pointers around it, and then
let the all-cases code at the end deal with the parent of the deleted
node, making it point to the replacement node. This removes one or two
conditional branches.

Reviewed by:	markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D24845


Revision 357173 - (view) (download) (annotate) - [select for diffs]
Modified Mon Jan 27 15:09:13 2020 UTC (3 years, 10 months ago) by dougm
File length: 27938 byte(s)
Diff to previous 352837
Correct the use of RB_AUGMENT in the RB_TREE macros so that is invoked
at the root of every subtree that changes in an insert or delete, and
only once, and ordered from the bottom of the tree to the top.  For
intel_gas.c, the only user of RB_AUGMENT I can find, change the
augmenting routine so that it does not climb from entry to tree root
on every call, and remove a 'tree correcting' function that can be
supplanted by proper tree augmentation.

Reviewed by:	kib
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D23189


Revision 352837 - (view) (download) (annotate) - [select for diffs]
Modified Sat Sep 28 09:22:52 2019 UTC (4 years, 2 months ago) by trasz
File length: 28341 byte(s)
Diff to previous 347360
Add RB_REINSERT(3), a low overhead alternative to removing a node
and reinserting it back with an updated key.

This is one of dependencies for the upcoming stats(3) code.

Reviewed by:	cem
Obtained from:	Netflix
MFC after:	2 weeks
Sponsored by:	Klara Inc, Netflix
Differential Revision:	https://reviews.freebsd.org/D21786


Revision 347360 - (view) (download) (annotate) - [select for diffs]
Modified Wed May 8 18:47:00 2019 UTC (4 years, 7 months ago) by trasz
File length: 27507 byte(s)
Diff to previous 326256
Mark inline functions with __unused; prevents compiler warning
when they end up being unused.

Reviewed by:	kib
Obtained from:	OpenBSD
MFC after:	2 weeks
Sponsored by:	Klara Inc.
Differential Revision:	https://reviews.freebsd.org/D20185


Revision 326256 - (view) (download) (annotate) - [select for diffs]
Modified Mon Nov 27 15:01:59 2017 UTC (6 years ago) by pfg
File length: 27483 byte(s)
Diff to previous 277642
sys/sys: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


Revision 277642 - (view) (download) (annotate) - [select for diffs]
Modified Sat Jan 24 12:43:36 2015 UTC (8 years, 10 months ago) by kib
File length: 27431 byte(s)
Diff to previous 189204
Provide individual prototype and generate macros for the red-black tree.
This helps to reduce code size in statically linked applications.

Submitted by:	Sebastian Huber <sebastian.huber@embedded-brains.de>
MFC after:	2 weeks


Revision 189204 - (view) (download) (annotate) - [select for diffs]
Modified Sun Mar 1 04:57:23 2009 UTC (14 years, 9 months ago) by bms
File length: 25776 byte(s)
Diff to previous 186479
In sys/tree.h:
 * Add RB_FOREACH_FROM() which continues traversal *at*
   the y-node provided. There is no pre-increment.
 * Nuke RB_FOREACH_SAFE as it was buggy; it would omit the final node.
 * Replace RB_FOREACH_SAFE() with a working implementation
   derived from RB_FOREACH_FROM().
   The key observation is that we now only check the loop-control
   variable, but still cache the next member pointer.
 * Add RB_FOREACH_REVERSE_FROM() which continues backwards
   traversal *at* the y-node provided. There is no pre-increment.
   Typically this is used to back out of allocations made
   whilst walking an RB-tree.
 * Add RB_FOREACH_REVERSE_SAFE() which performs insertion and
   deletion safe backwards traversal.


Revision 186479 - (view) (download) (annotate) - [select for diffs]
Modified Wed Dec 24 19:57:22 2008 UTC (14 years, 11 months ago) by bms
File length: 25285 byte(s)
Diff to previous 174955
Add macro RB_FOREACH_SAFE(), which accepts an additional argument
specifying a temporary tree node pointer. It may be used in a
similar way to the *_SAFE() macros in <sys/queue.h>.


Revision 174955 - (view) (download) (annotate) - [select for diffs]
Modified Fri Dec 28 07:03:26 2007 UTC (15 years, 11 months ago) by jasone
File length: 25130 byte(s)
Diff to previous 170779
Implement RB_PREV() AND RB_FOREACH_REVERSE().


Revision 170779 - (view) (download) (annotate) - [select for diffs]
Modified Fri Jun 15 16:09:47 2007 UTC (16 years, 6 months ago) by jasone
File length: 24246 byte(s)
Diff to previous 154548
Simplify/optimize RB_NFIND().

Submitted by:	Andriy Gapon <avg@icyb.net.ua>


Revision 154548 - (view) (download) (annotate) - [select for diffs]
Modified Thu Jan 19 07:20:20 2006 UTC (17 years, 11 months ago) by jasone
File length: 24470 byte(s)
Diff to previous 154227
Add the RB_PROTOTYPE_STATIC and RB_GENERATE_STATIC macros.

Approved by:	markm (mentor)


Revision 154227 - (view) (download) (annotate) - [select for diffs]
Modified Wed Jan 11 15:48:36 2006 UTC (17 years, 11 months ago) by jasone
File length: 23919 byte(s)
Diff to previous 147245
Add the RB_NFIND() macro, which is useful for red-black tree searches
for which there may not be an exact match.

Reviewed by:	glebius, julian
Approved by:	markm (mentor)


Revision 147245 - (view) (download) (annotate) - [select for diffs]
Modified Fri Jun 10 11:44:57 2005 UTC (18 years, 6 months ago) by harti
File length: 23027 byte(s)
Diff to previous 139824
Make the default RB_AUGMENT() produce a 'do {} while (0)' instead
of nothing. This prevents the compiler from complaining about empty
if statements when compiled with higher WARN levels.


Revision 139824 - (view) (download) (annotate) - [select for diffs]
Modified Fri Jan 7 02:28:28 2005 UTC (18 years, 11 months ago) by imp
File length: 23011 byte(s)
Diff to previous 127564
Add FreeBSD tag


Revision 127564 - (view) (download) (annotate) - [select for diffs]
Modified Mon Mar 29 11:18:25 2004 UTC (19 years, 8 months ago) by des
File length: 22993 byte(s)
Copied from: vendor/NetBSD/dist/sys/sys/tree.h revision 127563
Diff to previous 127563
This commit was generated by cvs2svn to compensate for changes in r127563,
which included commits to RCS files with non-trunk default branches.


Revision 127563 - (view) (download) (annotate) - [select for diffs]
Modified Mon Mar 29 11:18:25 2004 UTC (19 years, 8 months ago) by des
Original Path: vendor/NetBSD/dist/sys/sys/tree.h
File length: 22993 byte(s)
Diff to previous 127403
Synch with NetBSD: avoid "unused parameter" warning.


Revision 127403 - (view) (download) (annotate) - [select for diffs]
Modified Thu Mar 25 12:44:08 2004 UTC (19 years, 8 months ago) by des
Original Path: vendor/NetBSD/dist/sys/sys/tree.h
File length: 23029 byte(s)
Diff to previous 127208
Import the original directly from NetBSD instead of via OpenBSD.


Revision 127208 - (view) (download) (annotate) - [select for diffs]
Modified Fri Mar 19 20:14:23 2004 UTC (19 years, 9 months ago) by des
Original Path: vendor/NetBSD/dist/sys/sys/tree.h
File length: 22693 byte(s)
Diff to previous 98679
Sync with OpenBSD (two-year old bug fix)


Revision 98679 - (view) (download) (annotate) - [select for diffs]
Added Sun Jun 23 14:38:51 2002 UTC (21 years, 5 months ago) by des
Original Path: vendor/NetBSD/dist/sys/sys/tree.h
File length: 22624 byte(s)
Import OpenBSD's <sys/tree.h>, needed by OpenSSH.

Obtained from:	OpenBSD


This form allows you to request diffs between any two revisions of this file. For each of the two "sides" of the diff, enter a numeric revision.

  Diffs between and
  Type of Diff should be a

  ViewVC Help
Powered by ViewVC 1.1.27