Skip to content

adt: split interval tree by right endpoint on matched left endpoints #19768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

redwrasse
Copy link
Contributor

@redwrasse redwrasse commented Apr 20, 2025

Splits interval trees by right endpoint on matched left endpoints, to improve exact interval matching performance.
This addresses the issue: #19769

…dpoints, to improve find() performance

Signed-off-by: redwrasse <[email protected]>
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: redwrasse
Once this PR has been reviewed and has the lgtm label, please assign wenjiaswe for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link

Hi @redwrasse. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@redwrasse redwrasse changed the title [DRAFT] adt: split interval tree by right endpoint on matched left endpoints adt: split interval tree by right endpoint on matched left endpoints Apr 20, 2025
@@ -701,16 +716,29 @@ func (ivt *intervalTree) Visit(ivl Interval, ivv IntervalVisitor) {

// find the exact node for a given interval
func (ivt *intervalTree) find(ivl Interval) *intervalNode {
Copy link
Member

Choose a reason for hiding this comment

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

I was not able to find a proper tests for the Find method. Would you mind preparing some tests before we change the logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes,I'll add tests. I was thinking of just adding assertions on the Find operation to the existing TestIntervalTreeRandom here as say

	for ab := range ivs {
		for xy := range ivs {
			v := xy.x + int64(rand.Intn(int(xy.y-xy.x)))
			require.NotEmptyf(t, ivt.Stab(NewInt64Point(v)), "expected %v stab non-zero for [%+v)", v, xy)
			require.Truef(t, ivt.Intersects(NewInt64Point(v)), "did not get %d as expected for [%+v)", v, xy)
		}
		iv := ivt.Find(NewInt64Interval(ab.x, ab.y))
		assert.NotNil(t, iv)
		assert.Equal(t, NewInt64Interval(ab.x, ab.y), iv.Ivl)
		assert.Truef(t, ivt.Delete(NewInt64Interval(ab.x, ab.y)), "did not delete %v as expected", ab)
		delete(ivs, ab)
	}

In addition I can add a separate dedicated unit test for the Find op to test edge cases if that's warranted.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, please send a separate PR. It should be much easier to review and merge a new tests that don't change the logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@serathius opened up a separate MR with IntervalTree.Find() tests: #19801

@serathius
Copy link
Member

Please include benchmark from #19769 in the PR.

@redwrasse
Copy link
Contributor Author

Please include benchmark from #19769 in the PR.

Will do, I'll investigate using benchstats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants