@@ -19,7 +19,7 @@ public struct SortedArray<Element> {
1919 }
2020
2121 /// Initializes the array with a sequence of unsorted elements and a comparison predicate.
22- public init < S: Sequence > ( unsorted: S , areInIncreasingOrder: @escaping Comparator < Element > ) where S. Iterator . Element == Element {
22+ public init < S: Sequence > ( unsorted: S , areInIncreasingOrder: @escaping Comparator < Element > ) where S. Element == Element {
2323 let sorted = unsorted. sorted ( by: areInIncreasingOrder)
2424 self . _elements = sorted
2525 self . areInIncreasingOrder = areInIncreasingOrder
@@ -30,7 +30,7 @@ public struct SortedArray<Element> {
3030 /// This is faster than `init(unsorted:areInIncreasingOrder:)` because the elements don't have to sorted again.
3131 ///
3232 /// - Precondition: `sorted` is sorted according to the given comparison predicate. If you violate this condition, the behavior is undefined.
33- public init < S: Sequence > ( sorted: S , areInIncreasingOrder: @escaping Comparator < Element > ) where S. Iterator . Element == Element {
33+ public init < S: Sequence > ( sorted: S , areInIncreasingOrder: @escaping Comparator < Element > ) where S. Element == Element {
3434 self . _elements = Array ( sorted)
3535 self . areInIncreasingOrder = areInIncreasingOrder
3636 }
@@ -55,7 +55,7 @@ public struct SortedArray<Element> {
5555 /// we only need to re-sort once.
5656 ///
5757 /// - Complexity: O(_n * log(n)_) where _n_ is the size of the resulting array.
58- public mutating func insert< S: Sequence > ( contentsOf newElements: S ) where S. Iterator . Element == Element {
58+ public mutating func insert< S: Sequence > ( contentsOf newElements: S ) where S. Element == Element {
5959 _elements. append ( contentsOf: newElements)
6060 _elements. sort ( by: areInIncreasingOrder)
6161 }
@@ -68,7 +68,7 @@ extension SortedArray where Element: Comparable {
6868 }
6969
7070 /// Initializes the array with a sequence of unsorted elements. Uses `<` as the comparison predicate.
71- public init < S: Sequence > ( unsorted: S ) where S. Iterator . Element == Element {
71+ public init < S: Sequence > ( unsorted: S ) where S. Element == Element {
7272 self . init ( unsorted: unsorted, areInIncreasingOrder: < )
7373 }
7474
@@ -77,7 +77,7 @@ extension SortedArray where Element: Comparable {
7777 /// This is faster than `init(unsorted:)` because the elements don't have to sorted again.
7878 ///
7979 /// - Precondition: `sorted` is sorted according to the `<` predicate. If you violate this condition, the behavior is undefined.
80- public init < S: Sequence > ( sorted: S ) where S. Iterator . Element == Element {
80+ public init < S: Sequence > ( sorted: S ) where S. Element == Element {
8181 self . init ( sorted: sorted, areInIncreasingOrder: < )
8282 }
8383}
@@ -164,25 +164,25 @@ extension SortedArray {
164164 // swift(4.1.50): Swift 4.2 compiler in Swift 4 mode
165165 // swift(4.2): Swift 4.2 compiler
166166 #if !swift(>=4.1.50)
167- /// Removes the elements in the specified subrange from the array.
168- ///
169- /// - Parameter bounds: The range of the array to be removed. The
170- /// bounds of the range must be valid indices of the array.
171- ///
172- /// - Complexity: O(_n_), where _n_ is the length of the array.
173- public mutating func removeSubrange( _ bounds: CountableRange < Int > ) {
174- _elements. removeSubrange ( bounds)
175- }
167+ /// Removes the elements in the specified subrange from the array.
168+ ///
169+ /// - Parameter bounds: The range of the array to be removed. The
170+ /// bounds of the range must be valid indices of the array.
171+ ///
172+ /// - Complexity: O(_n_), where _n_ is the length of the array.
173+ public mutating func removeSubrange( _ bounds: CountableRange < Int > ) {
174+ _elements. removeSubrange ( bounds)
175+ }
176176
177- /// Removes the elements in the specified subrange from the array.
178- ///
179- /// - Parameter bounds: The range of the array to be removed. The
180- /// bounds of the range must be valid indices of the array.
181- ///
182- /// - Complexity: O(_n_), where _n_ is the length of the array.
183- public mutating func removeSubrange( _ bounds: CountableClosedRange < Int > ) {
184- _elements. removeSubrange ( bounds)
185- }
177+ /// Removes the elements in the specified subrange from the array.
178+ ///
179+ /// - Parameter bounds: The range of the array to be removed. The
180+ /// bounds of the range must be valid indices of the array.
181+ ///
182+ /// - Complexity: O(_n_), where _n_ is the length of the array.
183+ public mutating func removeSubrange( _ bounds: CountableClosedRange < Int > ) {
184+ _elements. removeSubrange ( bounds)
185+ }
186186 #endif
187187
188188 /// Removes the specified number of elements from the beginning of the
@@ -416,10 +416,27 @@ extension SortedArray {
416416 }
417417}
418418
419- public func == < Element: Equatable > ( lhs: SortedArray < Element > , rhs: SortedArray < Element > ) -> Bool {
420- return lhs. _elements == rhs. _elements
421- }
419+ #if swift(>=4.1)
420+ extension SortedArray : Equatable where Element: Equatable {
421+ public static func == ( lhs: SortedArray < Element > , rhs: SortedArray < Element > ) -> Bool {
422+ // Ignore the comparator function for Equatable
423+ return lhs. _elements == rhs. _elements
424+ }
425+ }
426+ #else
427+ public func == < Element: Equatable > ( lhs: SortedArray < Element > , rhs: SortedArray < Element > ) -> Bool {
428+ return lhs. _elements == rhs. _elements
429+ }
422430
423- public func != < Element: Equatable > ( lhs: SortedArray < Element > , rhs: SortedArray < Element > ) -> Bool {
424- return lhs. _elements != rhs. _elements
425- }
431+ public func != < Element: Equatable > ( lhs: SortedArray < Element > , rhs: SortedArray < Element > ) -> Bool {
432+ return lhs. _elements != rhs. _elements
433+ }
434+ #endif
435+
436+ #if swift(>=4.1.50)
437+ extension SortedArray : Hashable where Element: Hashable {
438+ public func hash( into hasher: inout Hasher ) {
439+ hasher. combine ( _elements)
440+ }
441+ }
442+ #endif
0 commit comments