On Fri, Jul 5, 2019 at 10:45 AM David Fetter <da...@fetter.org> wrote: > If I understand the cases correctly, the combination of covering_range > and multi_range types covers all cases. To recap, covering_range_agg > assigns a weight, possibly 0, to each non-overlapping sub-range. A > cast from covering_range to multi_range would meld adjacent ranges > with non-zero weights into single ranges in O(N) (N sub-ranges) time > and some teensy amount of memory for tracking progress of adjacent > ranges of non-zero weight. Gaps would just be multi_range consisting > of the sub-ranges of the covering_range with weight 0, and wouldn't > require any tracking.
I take it that a multirange contains of *disjoint* ranges, so instead of {[1,2), [2,3), [6,7)} you'd have {[1,3), [6,7)}. Jeff does that match your expectation? I just realized that since weighted_range_agg and covering_range_agg return tuples of (anyrange, integer) (maybe other numeric types too?), their elements are *not ranges*, so they couldn't return a multirange. They would have to return an array of those tuples. I agree that if you had a pre-sorted list of weighted ranges (with or without zero-weight elements), you could convert it to a multirange in O(n) very easily. Paul