Skip to content

Commit e57298d

Browse files
committed
Reset interval_tree to master
1 parent ebcd68d commit e57298d

File tree

1 file changed

+9
-40
lines changed

1 file changed

+9
-40
lines changed

src/utils/interval_tree.jl

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -195,44 +195,11 @@ function Base.delete!(tree::IntervalTree{M,E}, span::M) where {M,E}
195195
parent_of_succ.right = replacement
196196
end
197197

198-
target.span = successor.span
199-
replacement = target
200-
end
201-
202-
# Phase 3: Handle overlap case - add remaining portions
203-
if target_type == :overlap
204-
original_start = span_start(original_span)
205-
original_end = span_end(original_span)
206-
del_start = span_start(span)
207-
del_end = span_end(span)
208-
verify_span(span)
209-
210-
# Left portion: exists if original starts before deleted span
211-
if original_start < del_start
212-
left_end = min(original_end, del_start - _span_one(del_start))
213-
if left_end >= original_start
214-
left_span = M(original_start, left_end - original_start + _span_one(left_end))
215-
if !isempty(left_span)
216-
replacement = insert_node!(replacement, left_span)
217-
end
218-
end
198+
# Update max_end bottom-up for the successor's original path
199+
update_max_end!(parent_of_succ)
200+
for i in length(succ_path)-1:-1:1
201+
update_max_end!(succ_path[i])
219202
end
220-
221-
# Right portion: exists if original extends beyond deleted span
222-
if original_end > del_end
223-
right_start = max(original_start, del_end + _span_one(del_end))
224-
if original_end >= right_start
225-
right_span = M(right_start, original_end - right_start + _span_one(original_end))
226-
if !isempty(right_span)
227-
replacement = insert_node!(replacement, right_span)
228-
end
229-
end
230-
end
231-
end
232-
233-
# Phase 4: Update parent's child pointer
234-
if isempty(path)
235-
root = replacement
236203
else
237204
# Zero or one child
238205
replacement = target.left !== nothing ? target.left : target.right
@@ -292,13 +259,15 @@ function find_overlapping!(node::IntervalNode{M,E}, query::M, result::Vector{M};
292259
end
293260
end
294261

295-
# Enqueue left subtree if it might contain overlapping intervals
262+
# Search left subtree if its max_end is at least query_start
296263
if current.left !== nothing && current.left.max_end >= span_start(query)
297264
push!(stack, current.left)
298265
end
299266

300-
# Enqueue right subtree if query extends beyond current node's start
301-
if current.right !== nothing && span_end(query) >= span_start(current.span)
267+
# Search right subtree if it could contain an overlap
268+
if current.right !== nothing &&
269+
span_start(current.span) <= span_end(query) &&
270+
current.right.max_end >= span_start(query)
302271
push!(stack, current.right)
303272
end
304273
end

0 commit comments

Comments
 (0)