RFR: 8345314: Add a red–black tree as a utility data structure [v17]

Casper Norrbin cnorrbin at openjdk.org
Wed Jan 29 10:11:40 UTC 2025


On Wed, 29 Jan 2025 06:04:44 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:

>> Casper Norrbin has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 36 commits:
>> 
>>  - merge fixes
>>  - Merge branch 'master' into rb-tree
>>  - readd find_enclosing_range
>>  - Merge branch 'master' into rb-tree
>>  - treap swap fix
>>  - const functions
>>  - thomas feedback
>>  - axel feedback
>>  - clarified comment
>>  - Improved comments
>>  - ... and 26 more: https://git.openjdk.org/jdk/compare/ad01dfb6...b7219a93
>
> src/hotspot/share/utilities/rbTree.hpp line 247:
> 
>> 245: 
>> 246:   const RBNode* closest_leq(const K& k, BoundMode mode = INCLUSIVE) const {
>> 247:     return const_cast<RBTree<K, V, COMPARATOR, ALLOCATOR>*>(this)->closest_leq(k, mode);
> 
> When it comes to `const` overloads of `accessor` like member functions I prefer that we invert the `const` cast logic. That is that it is the `const` variant that includes the implementation. And that the non-`const` variant dispatches to the `const` versions and then casts away the the `const` qualifier on the result. This ensures that the implementation does not break the `const` property of the class, and is less bug prone.

Swapped them around to have the non-const depend on the const version

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/22360#discussion_r1933594842


More information about the hotspot-dev mailing list