Skip to content

fix(overlaps): scan only query-range boundary points (#127) - #158

Open
IMGillusion wants to merge 1 commit into
chaimleib:masterfrom
IMGillusion:fix/127/overlaps-range-boundary-scan
Open

IMGillusion wants to merge 1 commit into
chaimleib:masterfrom
IMGillusion:fix/127/overlaps-range-boundary-scan

Conversation

@IMGillusion

Copy link
Copy Markdown

overlaps(begin, end) on a range tested every boundary point in the tree
(O(n) pure-python comparisons per query) instead of just the points
inside (begin, end). This is the 15-minutes-vs-12-seconds gap reported in
#127 (450k-interval tree, profile pointed at the overlaps_range genexpr).

The scan is now restricted to the bisect slice [begin, end), mirroring the
indexing overlap() already uses in the same file. Semantics are
unchanged: boundaries exactly at begin were already covered by the
preceding overlaps_point(begin) check, and the previous strict
begin < bound < end filter excluded exactly the points the bisect
bounds exclude.

Benchmark (300k disjoint intervals, 600k boundary points, 200 miss-case queries)

before after
200 x overlaps() ~4.0s ~0.01s

New regression test test/issues/issue127_test.py pins both the semantics
(gap -> False, touching interval -> True) and the scaling.

Full suite: 105 passed, no regressions.

overlaps_range() tested every boundary point in the tree (O(n)
pure-python comparisons per query) instead of just the points
inside (begin, end). Restrict the scan to the bisect slice, mirroring
the indexing overlap() already uses. Unfixed: ~4s for 200 queries on
a 300k-interval tree; fixed: ~0.01s.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant