pkg/adt.Int64Comparable.Compare computes cmp := v - vc and takes the sign. The subtraction overflows for extreme values, breaking the trichotomy contract:
Int64Comparable(math.MaxInt64).Compare(Int64Comparable(math.MinInt64)) // returns -1, expected 1
Int64Comparable(math.MaxInt64).Compare(Int64Comparable(-1)) // returns -1, expected 1
On top of that, NewInt64Point(math.MaxInt64) builds [MaxInt64, MaxInt64+1) where a+1 wraps to MinInt64, producing an interval with Begin > End and violating the tree's Begin <= End invariant.
There are no in-tree production callers of the int64 interval constructors, but pkg/adt is an exported package used by downstream consumers, so the API should not return wrong orderings or invalid intervals for extreme input.
Proposed fix: compare v and vc directly without subtracting, and return a degenerate (empty) [a, a) interval for NewInt64Point(math.MaxInt64), preserving the invariant. A regression test will assert the comparator trichotomy at extremes and the point invariant.
pkg/adt.Int64Comparable.Comparecomputescmp := v - vcand takes the sign. The subtraction overflows for extreme values, breaking the trichotomy contract:On top of that,
NewInt64Point(math.MaxInt64)builds[MaxInt64, MaxInt64+1)wherea+1wraps toMinInt64, producing an interval withBegin > Endand violating the tree'sBegin <= Endinvariant.There are no in-tree production callers of the int64 interval constructors, but
pkg/adtis an exported package used by downstream consumers, so the API should not return wrong orderings or invalid intervals for extreme input.Proposed fix: compare
vandvcdirectly without subtracting, and return a degenerate (empty)[a, a)interval forNewInt64Point(math.MaxInt64), preserving the invariant. A regression test will assert the comparator trichotomy at extremes and the point invariant.