Skip to content

8379744: Add a way to update the key of a red-black tree node#30183

Open
caspernorrbin wants to merge 3 commits intoopenjdk:masterfrom
caspernorrbin:rbtree-update_key
Open

8379744: Add a way to update the key of a red-black tree node#30183
caspernorrbin wants to merge 3 commits intoopenjdk:masterfrom
caspernorrbin:rbtree-update_key

Conversation

@caspernorrbin
Copy link
Member

@caspernorrbin caspernorrbin commented Mar 11, 2026

Hi everyone,

For more advanced users of the red-black tree, we should add a way to update the key of an existing node. This can be needed if, for example, a node represents a range that has been expanded. Updating the key avoids having to remove and re-insert the node, both of which can trigger tree balancing. In contrast, updating the key can be done efficiently with only a lookup.

Assuming the tree is not ill-formed, it is sufficient to validate the new key against the node's local neighbours to ensure that we do not violate ordering. We assert for this in debug builds. It is the user's responsibility to ensure that the new key does not break tree invariants. The tree performs no additional operations besides updating the key.

Testing:

  • Oracle tier 1
  • 2 new gtests covering both success and failure cases

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8379744: Add a way to update the key of a red-black tree node (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30183/head:pull/30183
$ git checkout pull/30183

Update a local copy of the PR:
$ git checkout pull/30183
$ git pull https://git.openjdk.org/jdk.git pull/30183/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30183

View PR using the GUI difftool:
$ git pr show -t 30183

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30183.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 11, 2026

👋 Welcome back cnorrbin! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Mar 11, 2026

@caspernorrbin This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8379744: Add a way to update the key of a red-black tree node

Reviewed-by: jsikstro

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 64 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk
Copy link

openjdk bot commented Mar 11, 2026

@caspernorrbin The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 11, 2026
@mlbridge
Copy link

mlbridge bot commented Mar 11, 2026

Webrevs

Copy link
Member

@jsikstro jsikstro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. This is useful in use-cases we have in ZGC where we would like to avoid calls to malloc/free when we know by invariant that we could just update a node's key.

It's worth mentioning that this might not be the case for other usages of the tree, and using this function can, as you say, break the invariants. I think the asserts are an OK approach to maintain the tree's invariants, but can definitely shoot you in the leg if used incorrectly.


void free_node(RBNode<K, V>* node);

// Updates the key in the given the node or node cursor.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Updates the key in the given the node or node cursor.
// Updates the key in the given node or node cursor.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot [email protected] ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants