Page MenuHomeFreeBSD

Drop unneeded rotation from RB_REMOVE_COLOR
ClosedPublic

Authored by dougm on Jun 18 2020, 3:45 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 14 2024, 5:44 PM
Unknown Object (File)
Mar 8 2024, 12:04 AM
Unknown Object (File)
Jan 24 2024, 10:27 AM
Unknown Object (File)
Dec 20 2023, 4:49 AM
Unknown Object (File)
Dec 5 2023, 5:48 PM
Unknown Object (File)
Aug 20 2023, 6:38 PM
Unknown Object (File)
Jul 2 2023, 6:26 AM
Unknown Object (File)
Jun 27 2023, 4:34 AM
Subscribers

Details

Summary

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 are 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.

Any fan of dichromatic trees is welcome to review.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

dougm requested review of this revision.Jun 18 2020, 3:45 AM
dougm created this revision.

A little test program. Enter a positive number to insert into the tree and a negative number to remove its inverse from the tree.

If you want to see the effect of this patch, try entering this sequence into the test program

6 4 8 2 5 7 9 10 -10 -9 -8 -7

and you'll see that the patch changes the resulting tree in the last operation, but doesn't violate red-black properties.

Drop redundant assignments.

dougm added a reviewer: danfe.

If I understand correctly, with the original code, the intermediate state of the tree prior to the second rotation after removing 7 is:

B6:17
    B5:11
        B4:6
            R2:2
This revision is now accepted and ready to land.Jun 20 2020, 4:49 PM

If I understand correctly, with the original code, the intermediate state of the tree prior to the second rotation after removing 7 is:

B6:17
    B5:11
        B4:6
            R2:2

That's right.