Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid operator collisions: << and >>. #29

Merged
merged 1 commit into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions Sources/Ranges/AnyRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,12 @@ extension AnyRange {
}
}

infix operator <<: ComparisonPrecedence
infix operator >>: ComparisonPrecedence
extension AnyRange {
internal static func <<(lhs: AnyRange, rhs: AnyRange) -> Bool {
return lhs < rhs && !lhs.overlaps(rhs)
internal func _isLessThanAndApartFrom(_ other: AnyRange) -> Bool {
return self < other && !self.overlaps(other)
}
internal static func >>(lhs: AnyRange, rhs: AnyRange) -> Bool {
return rhs << lhs

internal func _isGreaterThanAndApartFrom(_ other: AnyRange) -> Bool {
return other._isLessThanAndApartFrom(self)
}
}
10 changes: 6 additions & 4 deletions Sources/Ranges/RangeDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public struct RangeDictionary<Bound, Value> where Bound: Comparable {
default:
for ii in 0..<(nn - 1) {
let (range0, range1) = self._twoRanges(from: ii)
guard !range0.isEmpty && !range1.isEmpty && range0 << range1 else { return false }
guard !range0.isEmpty && !range1.isEmpty && range0._isLessThanAndApartFrom(range1) else {
return false
}
}
return true
}
Expand Down Expand Up @@ -121,14 +123,14 @@ public struct RangeDictionary<Bound, Value> where Bound: Comparable {
if self._rangesAndValues.isEmpty {
return .insertable(0)
}
if range << self._rangesAndValues.first!.range {
if range._isLessThanAndApartFrom(self._rangesAndValues.first!.range) {
return .insertable(0)
}
if range.overlaps(self._rangesAndValues.first!.range) {
overlap_first = 0
break determineFirstIndexOfOverlap
}
if self._rangesAndValues.last!.range << range {
if self._rangesAndValues.last!.range._isLessThanAndApartFrom(range) {
return .insertable(numberOfPairs)
}
assert(numberOfPairs > 1, "Must be already handled if the number of pairs is less than 2.")
Expand All @@ -139,7 +141,7 @@ public struct RangeDictionary<Bound, Value> where Bound: Comparable {
overlap_first = ii + 1
break determineFirstIndexOfOverlap
}
if range0 << range && range << range1 {
if range0._isLessThanAndApartFrom(range) && range._isLessThanAndApartFrom(range1) {
return .insertable(ii + 1)
}
}
Expand Down