8379744: Add a way to update the key of a red-black tree node#30183
8379744: Add a way to update the key of a red-black tree node#30183caspernorrbin wants to merge 3 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back cnorrbin! A progress list of the required criteria for merging this PR into |
|
@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: 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
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 |
|
@caspernorrbin The following label will be automatically applied to this pull request:
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. |
Webrevs
|
jsikstro
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
| // Updates the key in the given the node or node cursor. | |
| // Updates the key in the given node or node cursor. |
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:
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30183/head:pull/30183$ git checkout pull/30183Update a local copy of the PR:
$ git checkout pull/30183$ git pull https://git.openjdk.org/jdk.git pull/30183/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 30183View PR using the GUI difftool:
$ git pr show -t 30183Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30183.diff
Using Webrev
Link to Webrev Comment