RFR: 8345314: Add a red–black tree as a utility data structure [v7]
Thomas Stuefe
stuefe at openjdk.org
Tue Jan 7 16:34:48 UTC 2025
On Wed, 18 Dec 2024 10:46:53 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:
>
> renamed coloring functions
This is highly welcome. Thank you for this work!
Will this implementation guarantee address stability and identity of the nodes themselves? Meaning, can I use this RB for memory management, with the Nodes themselves being the blocks being managed, and their identity is the address/size of the node memory block?
The reason I ask is that IIRC many RB implementations will, at some point (I believe during deletion) copy node content around. j.u.TreeSet does this, for instance. Back in 2020 I briefly attempted to replace the Metaspace dictionary with an RB tree, but IIRC that point thwarted me. I dimly remember that the only implementation I found that could do this was the Linux kernel RB implementation (which would not be a bad implementation to copy, btw).
-------------
PR Comment: https://git.openjdk.org/jdk/pull/22360#issuecomment-2575738516
More information about the hotspot-dev
mailing list