@@ -105,7 +105,7 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
105
105
return IndexingIterator ( _elements: self )
106
106
}
107
107
108
- public subscript( index : Index ) -> CountableRange < IndexSet . Element > {
108
+ public subscript( index : Index ) -> Range < IndexSet . Element > {
109
109
let indexSetRange = indexSet. _range ( at: index)
110
110
if let intersectingRange = intersectingRange {
111
111
return Swift . max ( intersectingRange. lowerBound, indexSetRange. lowerBound) ..< Swift . min ( intersectingRange. upperBound, indexSetRange. upperBound)
@@ -159,11 +159,9 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
159
159
}
160
160
161
161
/// Initialize an `IndexSet` with a range of integers.
162
- public init ( integersIn range: ClosedRange < Element > ) { self . init ( integersIn: Range ( range) ) }
163
- /// Initialize an `IndexSet` with a range of integers.
164
- public init ( integersIn range: CountableClosedRange < Element > ) { self . init ( integersIn: Range ( range) ) }
165
- /// Initialize an `IndexSet` with a range of integers.
166
- public init ( integersIn range: CountableRange < Element > ) { self . init ( integersIn: Range ( range) ) }
162
+ public init < R: RangeExpression > ( integersIn range: R ) where R. Bound == Element {
163
+ self . init ( integersIn: range. relative ( to: 0 ..< Int . max) )
164
+ }
167
165
168
166
/// Initialize an `IndexSet` with a single integer.
169
167
public init ( integer: Element ) {
@@ -205,16 +203,9 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
205
203
/// Returns a `Range`-based view of `self`.
206
204
///
207
205
/// - parameter range: A subrange of `self` to view.
208
- public func rangeView( of range : ClosedRange < Element > ) -> RangeView { return self . rangeView ( of: Range ( range) ) }
209
- /// Returns a `Range`-based view of `self`.
210
- ///
211
- /// - parameter range: A subrange of `self` to view.
212
- public func rangeView( of range : CountableClosedRange < Element > ) -> RangeView { return self . rangeView ( of: Range ( range) ) }
213
- /// Returns a `Range`-based view of `self`.
214
- ///
215
- /// - parameter range: A subrange of `self` to view.
216
- public func rangeView( of range : CountableRange < Element > ) -> RangeView { return self . rangeView ( of: Range ( range) ) }
217
-
206
+ public func rangeView< R: RangeExpression > ( of range : R ) -> RangeView where R. Bound == Element {
207
+ return self . rangeView ( of: range. relative ( to: 0 ..< Int . max) )
208
+ }
218
209
219
210
private func _indexOfRange( containing integer : Element ) -> RangeView . Index ? {
220
211
let result = _handle. map {
@@ -344,32 +335,19 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
344
335
/// The resulting range is the range of the intersection of the integers in `range` with the index set.
345
336
///
346
337
/// - parameter range: The range of integers to include.
347
- public func indexRange( in range: CountableRange < Element > ) -> Range < Index > { return self . indexRange ( in: Range ( range) ) }
348
- /// Return a `Range<IndexSet.Index>` which can be used to subscript the index set.
349
- ///
350
- /// The resulting range is the range of the intersection of the integers in `range` with the index set.
351
- ///
352
- /// - parameter range: The range of integers to include.
353
- public func indexRange( in range: ClosedRange < Element > ) -> Range < Index > { return self . indexRange ( in: Range ( range) ) }
354
- /// Return a `Range<IndexSet.Index>` which can be used to subscript the index set.
355
- ///
356
- /// The resulting range is the range of the intersection of the integers in `range` with the index set.
357
- ///
358
- /// - parameter range: The range of integers to include.
359
- public func indexRange( in range: CountableClosedRange < Element > ) -> Range < Index > { return self . indexRange ( in: Range ( range) ) }
360
-
338
+ public func indexRange< R: RangeExpression > ( in range: R ) -> Range < Index > where R. Bound == Element {
339
+ return self . indexRange ( in: range. relative ( to: 0 ..< Int . max) )
340
+ }
361
341
362
342
/// Returns the count of integers in `self` that intersect `range`.
363
343
public func count( in range: Range < Element > ) -> Int {
364
344
return _handle. map { $0. countOfIndexes ( in: _toNSRange ( range) ) }
365
345
}
366
346
367
347
/// Returns the count of integers in `self` that intersect `range`.
368
- public func count( in range: CountableRange < Element > ) -> Int { return self . count ( in: Range ( range) ) }
369
- /// Returns the count of integers in `self` that intersect `range`.
370
- public func count( in range: ClosedRange < Element > ) -> Int { return self . count ( in: Range ( range) ) }
371
- /// Returns the count of integers in `self` that intersect `range`.
372
- public func count( in range: CountableClosedRange < Element > ) -> Int { return self . count ( in: Range ( range) ) }
348
+ public func count< R: RangeExpression > ( in range: R ) -> Int where R. Bound == Element {
349
+ return self . count ( in: range. relative ( to: 0 ..< Int . max) )
350
+ }
373
351
374
352
/// Returns `true` if `self` contains `integer`.
375
353
public func contains( _ integer: Element ) -> Bool {
@@ -382,12 +360,9 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
382
360
}
383
361
384
362
/// Returns `true` if `self` contains all of the integers in `range`.
385
- public func contains( integersIn range: CountableRange < Element > ) -> Bool { return self . contains ( integersIn: Range ( range) ) }
386
- /// Returns `true` if `self` contains all of the integers in `range`.
387
- public func contains( integersIn range: ClosedRange < Element > ) -> Bool { return self . contains ( integersIn: Range ( range) ) }
388
- /// Returns `true` if `self` contains all of the integers in `range`.
389
- public func contains( integersIn range: CountableClosedRange < Element > ) -> Bool { return self . contains ( integersIn: Range ( range) ) }
390
-
363
+ public func contains< R: RangeExpression > ( integersIn range: R ) -> Bool where R. Bound == Element {
364
+ return self . contains ( integersIn: range. relative ( to: 0 ..< Int . max) )
365
+ }
391
366
392
367
/// Returns `true` if `self` contains all of the integers in `indexSet`.
393
368
public func contains( integersIn indexSet: IndexSet ) -> Bool {
@@ -400,11 +375,9 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
400
375
}
401
376
402
377
/// Returns `true` if `self` intersects any of the integers in `range`.
403
- public func intersects( integersIn range: CountableRange < Element > ) -> Bool { return self . intersects ( integersIn: Range ( range) ) }
404
- /// Returns `true` if `self` intersects any of the integers in `range`.
405
- public func intersects( integersIn range: ClosedRange < Element > ) -> Bool { return self . intersects ( integersIn: Range ( range) ) }
406
- /// Returns `true` if `self` intersects any of the integers in `range`.
407
- public func intersects( integersIn range: CountableClosedRange < Element > ) -> Bool { return self . intersects ( integersIn: Range ( range) ) }
378
+ public func intersects< R: RangeExpression > ( integersIn range: R ) -> Bool where R. Bound == Element {
379
+ return self . intersects ( integersIn: range. relative ( to: 0 ..< Int . max) )
380
+ }
408
381
409
382
// MARK: -
410
383
// Collection
@@ -490,7 +463,7 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
490
463
} else {
491
464
let extent = 0 ..< 0
492
465
let rangeIndex = 0
493
- return Index ( value: value, extent: Range ( extent) , rangeIndex: rangeIndex, rangeCount: rangeCount)
466
+ return Index ( value: value, extent: extent, rangeIndex: rangeIndex, rangeCount: rangeCount)
494
467
}
495
468
}
496
469
@@ -508,11 +481,11 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
508
481
509
482
var result = IndexSet ( )
510
483
for r in self . rangeView {
511
- result. insert ( integersIn: Range ( r ) )
484
+ result. insert ( integersIn: r )
512
485
}
513
486
514
487
for r in other. rangeView {
515
- result. insert ( integersIn: Range ( r ) )
488
+ result. insert ( integersIn: r )
516
489
}
517
490
return result
518
491
}
@@ -619,23 +592,19 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
619
592
}
620
593
621
594
/// Insert a range of integers into the `IndexSet`.
622
- public mutating func insert( integersIn range: CountableRange < Element > ) { self . insert ( integersIn: Range ( range) ) }
623
- /// Insert a range of integers into the `IndexSet`.
624
- public mutating func insert( integersIn range: ClosedRange < Element > ) { self . insert ( integersIn: Range ( range) ) }
625
- /// Insert a range of integers into the `IndexSet`.
626
- public mutating func insert( integersIn range: CountableClosedRange < Element > ) { self . insert ( integersIn: Range ( range) ) }
595
+ public mutating func insert< R: RangeExpression > ( integersIn range: R ) where R. Bound == Element {
596
+ self . insert ( integersIn: range. relative ( to: 0 ..< Int . max) )
597
+ }
627
598
628
599
/// Remove a range of integers from the `IndexSet`.
629
600
public mutating func remove( integersIn range: Range < Element > ) {
630
601
_applyMutation { $0. remove ( in: _toNSRange ( range) ) }
631
602
}
632
603
633
604
/// Remove a range of integers from the `IndexSet`.
634
- public mutating func remove( integersIn range: CountableRange < Element > ) { self . remove ( integersIn: Range ( range) ) }
635
- /// Remove a range of integers from the `IndexSet`.
636
- public mutating func remove( integersIn range: ClosedRange < Element > ) { self . remove ( integersIn: Range ( range) ) }
637
- /// Remove a range of integers from the `IndexSet`.
638
- public mutating func remove( integersIn range: CountableClosedRange < Element > ) { self . remove ( integersIn: Range ( range) ) }
605
+ public mutating func remove( integersIn range: ClosedRange < Element > ) {
606
+ self . remove ( integersIn: Range ( range) )
607
+ }
639
608
640
609
/// Returns `true` if self contains no values.
641
610
public var isEmpty : Bool {
@@ -672,17 +641,9 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
672
641
///
673
642
/// - parameter range: A range of integers. For each integer in the range that intersects the integers in the IndexSet, then the `includeInteger` predicate will be invoked.
674
643
/// - parameter includeInteger: The predicate which decides if an integer will be included in the result or not.
675
- public func filteredIndexSet( in range : CountableRange < Element > , includeInteger: ( Element ) throws -> Bool ) rethrows -> IndexSet { return try self . filteredIndexSet ( in: Range ( range) , includeInteger: includeInteger) }
676
- /// Returns an IndexSet filtered according to the result of `includeInteger`.
677
- ///
678
- /// - parameter range: A range of integers. For each integer in the range that intersects the integers in the IndexSet, then the `includeInteger` predicate will be invoked.
679
- /// - parameter includeInteger: The predicate which decides if an integer will be included in the result or not.
680
- public func filteredIndexSet( in range : ClosedRange < Element > , includeInteger: ( Element ) throws -> Bool ) rethrows -> IndexSet { return try self . filteredIndexSet ( in: Range ( range) , includeInteger: includeInteger) }
681
- /// Returns an IndexSet filtered according to the result of `includeInteger`.
682
- ///
683
- /// - parameter range: A range of integers. For each integer in the range that intersects the integers in the IndexSet, then the `includeInteger` predicate will be invoked.
684
- /// - parameter includeInteger: The predicate which decides if an integer will be included in the result or not.
685
- public func filteredIndexSet( in range : CountableClosedRange < Element > , includeInteger: ( Element ) throws -> Bool ) rethrows -> IndexSet { return try self . filteredIndexSet ( in: Range ( range) , includeInteger: includeInteger) }
644
+ public func filteredIndexSet( in range : ClosedRange < Element > , includeInteger: ( Element ) throws -> Bool ) rethrows -> IndexSet {
645
+ return try self . filteredIndexSet ( in: Range ( range) , includeInteger: includeInteger)
646
+ }
686
647
687
648
/// Returns an IndexSet filtered according to the result of `includeInteger`.
688
649
///
@@ -692,7 +653,7 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
692
653
}
693
654
694
655
/// For a positive delta, shifts the indexes in [index, INT_MAX] to the right, thereby inserting an "empty space" [index, delta], for a negative delta, shifts the indexes in [index, INT_MAX] to the left, thereby deleting the indexes in the range [index - delta, delta].
695
- public mutating func shift( startingAt integer: Element , by delta: IndexSet . IndexDistance ) {
656
+ public mutating func shift( startingAt integer: Element , by delta: Int ) {
696
657
_applyMutation { $0. shiftIndexesStarting ( at: integer, by: delta) }
697
658
}
698
659
@@ -762,8 +723,8 @@ private struct IndexSetBoundaryIterator : IteratorProtocol {
762
723
763
724
private var i1 : IndexSet . RangeView . Iterator
764
725
private var i2 : IndexSet . RangeView . Iterator
765
- private var i1Range : CountableRange < Element > ?
766
- private var i2Range : CountableRange < Element > ?
726
+ private var i1Range : Range < Element > ?
727
+ private var i2Range : Range < Element > ?
767
728
private var i1UsedLower : Bool
768
729
private var i2UsedLower : Bool
769
730
@@ -970,4 +931,3 @@ extension IndexSet : Codable {
970
931
}
971
932
}
972
933
}
973
-
0 commit comments