This function checks whether the interval map contains any mapping in
the range [a;b]. The motivation is to enable checking for overlap before
inserting a new interval into the map.
Details
Diff Detail
- Repository
- rL LLVM
- Build Status
Buildable 26058 Build 26057: arc lint + arc unit
Event Timeline
See D55761 for an example of usage. The reason I am sinking this functionality here is because I am about to add a second piece of code with similar logic (and it also seems like a logical extension of the current API).
include/llvm/ADT/IntervalMap.h | ||
---|---|---|
1140 | Good question. I chose contains because this is similar in functionality to std::map::contains, but it is true that this whole class is not very STL-like, so maybe it's not good to try to appear like it is. If we're going to go with a custom name, then maybe overlaps could do the trick (there is a IntervalMapOverlaps class at the bottom of this file, which is doing something similar, but for two maps)? |
I think it'll be really useful to have this helper around. Thanks, lgtm with the name change!
include/llvm/ADT/IntervalMap.h | ||
---|---|---|
1140 | 'overlaps' sgtm. |
include/llvm/ADT/IntervalMap.h | ||
---|---|---|
1140 | 'intersects'? (the word is in the comment below, which seems telling) |
include/llvm/ADT/IntervalMap.h | ||
---|---|---|
1140 | "overlap" seems to be more consistent with other usages in this file (e.g. "(...) stopLess(a, b) can be used to determine if two |
unittests/ADT/IntervalMapTest.cpp | ||
---|---|---|
622 | I’m surprised this one returns true. Are these half-open intervals? If so I think you shouldn’t get overlap until you stop at 11. |
unittests/ADT/IntervalMapTest.cpp | ||
---|---|---|
622 | These are closed on both sides. Half-open intervals are tested below (where this indeed returns false). The half-openedness of an IntervalMap is controlled via template arguments (see line 17 and 18 in this file). |
include/llvm/ADT/IntervalMap.h | ||
---|---|---|
1140 | Fair enough - I don't feel too strongly (: |
unittests/ADT/IntervalMapTest.cpp | ||
---|---|---|
622 | Got it; thanks for explaining! |
When I read ‘contains’, I tend to assume ‘contains entire subset/subrange’. Would ‘containsSubrangeOf’ or some variant help readability?