Library for sets of integer ranges

I’m trying to remember a library I’d seen some time back. I didn’t have a use for it then, but I do now. And of course I now can’t remember what it was called :slightly_frowning_face:

Basically, I want to manage sets of integer ranges (the classic use case was sets of read articles in NNTP newsreaders). So I might have a set “1-7,9-13,21-27” and a set “6-12,31-33”, and their union would be “1-13,21-27,31-33”. So overlapping ranges are combined, and there should be a method to iterate over the start,end pairs for each range in the set. The highest values in the ranges can be in the billions (my need is to represent “chunks” of files in the gigabyte size range) so a compact representation is needed.

I can easily enough write my own implementation, but re-using something that exists and is well-tested seems like a better strategy.

Can anyone think of a library that implements this type of data structure?

… and of course, seconds after posting this message, I hit on the correct search terms. The library intspan is exactly what I need.

Sorry for the noise.

Edit: There’s also spans, which looks useful.

5 Likes