Skip to content

Gap between two ranges, and the gaps of a RangeSet (inner complement, within a window) #98

Closed

Description

@CaffeinatedCoder

Guava has Range.gap(other) ("the maximal range lying between this range and other") and RangeSet.complement(); rangemap has RangeSet::gaps(outer) ("the gaps in this set within the given outer range"); Boost.ICL has inner_complement. (Guava: https://guava.dev/releases/snapshot-jre/api/docs/com/google/common/collect/Range.html ; rangemap: https://docs.rs/rangemap/latest/rangemap/set/struct.RangeSet.html .) The library has Complement() on a set and Merge (the hull) on ranges, so both answers are derivable but neither is named: a gap between two bookings is a.Merge(b).Except(a).Except(b) today, and the free slots inside a window are set.Complement().Intersect(window).

Proposed API:

  • range.Gap(IRange<T> other) → TRange — the range strictly between the two, Empty when they overlap or are adjacent, and when either is empty.
  • set.Gaps() → RangeSet<TRange, T> — the inner complement, every uncovered range between the first and last element (unbounded ends excluded, which is what makes it differ from Complement()).
  • set.Gaps(IRange<T> window) → RangeSet<TRange, T> — the uncovered parts of window.

Translation: Gap → range_merge(a, b) - a - b lifted to multirange and read back as one range (range_merge(datemultirange(range_merge(a,b)) - datemultirange(a) - datemultirange(b))); Gaps(window) → datemultirange(window) - set, which is what Complement().Intersect(window) already becomes; Gaps() → datemultirange(range_merge(set)) - set.

Done when: all three are in docs/ranges.md, held by claims, swept by the small-model oracle (gap is set-theoretic: a ∪ gap ∪ b = merge(a,b) and gap ∩ a = ∅), and the translations are asserted against PostgreSQL in the shape-matrix test.

Found by the comparable-library survey (Guava, rangemap, Boost.ICL), 2026-10-17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/range-setRangeSet and multirange algebraarea/rangesRange unions, variants and the shape enginesenhancementNew feature or requestpackage/coreAffects CodoMetis.ValueRangespackage/efcoreAffects CodoMetis.ValueRanges.EFCore.PostgreSQL

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions