Fix fringe case (#130)

why:
 Merging [a,a] in to {[a+1,b]} caused assertion violation, doAssert
 condition was too strict.
This commit is contained in:
Jordan Hrycaj 2022-07-19 09:19:41 +01:00 committed by GitHub
parent 8a9816ac02
commit 598246620d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -347,9 +347,9 @@ proc new[P,S](T: type Interval[P,S]; kvp: DataRef[P,S]): T =
proc overlapOrLeftJoin[P,S](ds: Desc[P,S]; l, r: P): Rc[P,S] =
## Find and return
## * either the rightmost `[l,r)` overlapping interval `[a,b)`
## * either the rightmost interval `[a,b)` which overlaps `r`
## * or `[a,b)` with `b==l`
doAssert l < r
doAssert l <= r
let rc = ds.leftPos.le(r) # search for `max(a) <= r`
if rc.isOk:
# note that `b` is the first point outside right of `[a,b)`

View File

@ -195,6 +195,11 @@ suite "IntervalSet: Intervals of FancyPoint entries over FancyScalar":
(ivVal, ivSet) = (iv, true)
check ivVal == iv(uHigh,uHigh)
br.clear() # from blockchain sync crash
check br.total == 0 and br.chunks == 0
check br.merge(1477152,uHigh) == uHigh - 1477151
check br.merge(1477151,1477151) == 1
test "Merge disjunct intervals on 1st set":
br.clear()
check br.merge( 0, 99) == 100