If I have a Range that spans from x to y, but let's say that those bounds can be included, excluded, or unbound (like std::ops::Bound) that can be ordered, how can/should I structure RangeSet?
RangeSet would be a way to store multiple ranges and allow requests such as
range_start(range)which would return an ordered collection of allRanges withinRangeSetthat have a range start within therangeargumentrange_end(range)you can guess
At first I thought I could structure it like
struct RangeSet {
ranges: HashSet<Rc<Range>>,
starts: BTreeMap<RangeStart, Weak<Range>>,
ends: BTreeMap<RangeEnd, Weak<Range>>,
}
But a problem arises with this approach: when removing a range from the set, how do we know which start/end to delete? We could check for any matching start/end and check if their Weak no longer returns a Some(T), but it seems a bit convoluted.
How could such a RangeSet be structured? What are your opinions on this?
Thank you for your future answers 😄