4 ms·
Throwing a runtime error seems like an absurd solution compared to changing the comparison operator or using an unordered_map What's wrong with x.min < y.min |
by z_open 1y ago
Throwing a runtime error seems like an absurd solution compared to changing the comparison operator or using an unordered_map
What's wrong with x.min < y.min || (x. min == y.min && x.max < y. max)
- gsliepen 1y agoThat would indeed satisfy std::map, but then the question is, is that a useful ordering for intervals? To answer that, you need to define what you want to use the interval map for. If you want to be able to lookup in which unique interval a given value is, then you shouldn't have overlapping intervals to begin with. If you do allow overlapping intervals, a query could result in multiple intervals. Are lookups by value (not by interval) still O(log N) with that ordering?
- monkeyelite 1y agoHe’s just asserting he’s using the data structure in the way he wants to.