Skip to content
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

Fix: interval tree complete implemention based on red-black tree #10881

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: interval tree
xkey committed Jul 11, 2019
commit c62f5b7c3e971dea892771d72154fc2f05ca0890
31 changes: 24 additions & 7 deletions pkg/adt/interval_tree.go
Original file line number Diff line number Diff line change
@@ -468,15 +468,32 @@ func (ivt *IntervalTree) Visit(ivl Interval, ivv IntervalVisitor) {

// find the exact node for a given interval
func (ivt *IntervalTree) find(ivl Interval) (ret *intervalNode) {
f := func(n *intervalNode) bool {
if n.iv.Ivl != ivl {
return true
// f := func(n *intervalNode) bool {
// if n.iv.Ivl != ivl {
// return true
// }
// ret = n
// return false
// }
// ivt.root.visit(&ivl, ivt.nilNode, f)

Copy link
Contributor

Choose a reason for hiding this comment

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

remove

x := ivt.root

for x != ivt.nilNode {
if ivl.Begin.Compare(x.iv.Ivl.Begin) == 0 && ivl.End.Compare(x.iv.Ivl.End) == 0 {
break
}

if ivl.End.Compare(x.max) > 0 {
x = ivt.nilNode
} else if ivl.Begin.Compare(x.iv.Ivl.Begin) < 0 {
x = x.left
} else {
x = x.right
}
ret = n
return false
}
ivt.root.visit(&ivl, ivt.nilNode, f)
return ret

return x
}

// Find gets the IntervalValue for the node matching the given interval