Fixed calculation of overlapping (used to check for subset instead)

master
Aadhavan Srinivasan 2 months ago
parent d8f52b8ccc
commit 1d9d1a5b81

@ -6,11 +6,11 @@ type matchIndex struct {
endIdx int endIdx int
} }
// Returns true if the given matchIndex is an improper subset of any of the indices in the slice. // Returns true if the given matchIndex has ovelrap with any of the indices in the slice.
// When we add an index to our slice, we want to make sure a larger match isn't already present. // When we add an index to our slice, we want to make sure a larger match isn't already present.
func overlaps(idx matchIndex, idxes []matchIndex) bool { func overlaps(idx matchIndex, idxes []matchIndex) bool {
for _, val := range idxes { for _, val := range idxes {
if idx.startIdx >= val.startIdx && idx.endIdx <= val.endIdx { if (idx.startIdx > val.startIdx && idx.startIdx < val.endIdx) || (idx.endIdx > val.startIdx && idx.endIdx < val.endIdx) {
// A zero-length match doesn't overlap if it is located at the start or end // A zero-length match doesn't overlap if it is located at the start or end
// of the other match // of the other match
if !(idx.startIdx == idx.endIdx && (idx.startIdx == val.startIdx || idx.startIdx == val.endIdx)) { if !(idx.startIdx == idx.endIdx && (idx.startIdx == val.startIdx || idx.startIdx == val.endIdx)) {

Loading…
Cancel
Save