Description
It would be nice to have something like NSIndexSet. Essentially, you can think of it like the existing Range
, but instead of it being an optimized List<int>
, it is an optimized OrderedSet<int>
. I was attempting to use Range
this way earlier (so, for example, wanting Range(0,1000).concat(500,1500)
to generate Range(0,1500)
), but this is of course not the case.
IndexSets can be super useful in all sorts of different cases, from managing selection ranges (Cocoa's use) where a user is shift-clicking many items, to my current need where I have a set of overlapping time ranges and I am wanting to easily calculate the total time spent without double-counting overlaps.
Internally, IndexSet
s are implemented as a sorted array of Ranges. Removing a value can break an existing range into two ranges, while adding values could potentially unite previously disconnected ranges. I am not sure if there is a more efficient "persistent" strategy.