a Range class implementing compact integer ranges with a set-like API, and associated functions
A Range is an object resembling a set but optimised for contiguous ranges of int members.
Return a list
[start,end] denoting the overlap of two spans.
>>> overlap([1,9], [5,13]) [5, 9]
A collection of ints that collates adjacent ints.
The interface is as for a
set with additional methods:
spans(): return an iterable of
.startincluded in each
Additionally, the update/remove/etc methods have a secondary
(start,end), which is the same as passing
Range(start,end) but much more efficient.
A namedtuple with
Return an iterable of
Spans for all contiguous sequences in
>>> list(spans([1,2,3,7,8,11,5])) [1:4, 7:9, 11:12, 5:6]