RFR: 8345314: Add a red–black tree as a utility data structure [v4]
Casper Norrbin
cnorrbin at openjdk.org
Thu Dec 12 14:22:44 UTC 2024
On Thu, 12 Dec 2024 14:03:15 GMT, Casper Norrbin <cnorrbin at openjdk.org> wrote:
>> Hi everyone,
>>
>> This effort began as an exploration of replacing the current NMT treap with a red-black tree. Along the way, I discovered that others were also interested in having a general-purpose tree structure available within HotSpot.
>>
>> The red-black tree is designed to serve as a drop-in replacement for the existing NMT treap, keeping a nearly identical interface. However, I’ve also added a few additional requested features, such as an iterator.
>>
>> Testing builds off the treap tests, adding a few extra that inserts/removes and checks that the tree is correct. Testing uses the function `verify_self`, which iterates over the tree and checks that all red-black tree properties hold. Additionally, the tree has been tested in vmatree instead of the treap without any errors.
>>
>> For those who may want to revisit the fundamentals of red-black trees, [Wikipedia](https://en.wikipedia.org/wiki/Red%E2%80%93black_tree) offers a great summary with tables covering the various balancing cases. Alternatively, your favorite data structure book could provide even more insight.
>
> Casper Norrbin has updated the pull request incrementally with one additional commit since the last revision:
>
> feedback fixes + moved functions to inline file
Thank you everyone for the comments!
I split the tree into `rbTree.hpp` and `rbTree.inline.hpp`, which is similar to how `concurrentHashTable` works. The original file is now much more readable, with some additional added comments to the public functions. All the internal functions is hidden away in the inline file.
I also added a check to `verify_self()` which ensures that the tree is balanced, i.e. the upper bound of $2log_2(n+1)$ is never exceeded, which should have been checked for previously. Thanks @afshin-zafari for pointing it out.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/22360#issuecomment-2539087965
More information about the hotspot-dev
mailing list