Created
July 8, 2015 13:36
-
-
Save oisdk/68c2c5fe751c8372418a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct StridingSliceView<C : CollectionType where C.Index : Strideable> : SequenceType { | |
private let col: C | |
private let str: StrideTo<C.Index> | |
public func generate() -> PermutationGenerator<C, StrideTo<C.Index>> { | |
return PermutationGenerator(elements: col, indices: str) | |
} | |
} | |
public extension CollectionType where Index: Strideable { | |
public subscript(range: Range<Index>, by: Index.Stride) -> StridingSliceView<Self> { | |
return StridingSliceView(col: self, str: stride(from: range.startIndex, to: range.endIndex, by: by)) | |
} | |
} | |
public extension MutableCollectionType where Index : Strideable { | |
public subscript(range: Range<Index>, by: Index.Stride) -> StridingSliceView<Self> { | |
get { | |
return StridingSliceView(col: self, str: stride(from: range.startIndex, to: range.endIndex, by: by)) | |
} set (values) { | |
for (index, value) in zip(stride(from: range.startIndex, to: range.endIndex, by: by), values) { | |
self[index] = value | |
} | |
} | |
} | |
} | |
public extension CollectionType { | |
public subscript(i1: Index, i2: Index, rest: Index...) -> PermutationGenerator<Self, [Index]> { | |
return PermutationGenerator(elements: self, indices: [i1, i2] + rest) | |
} | |
} | |
public extension MutableCollectionType { | |
public subscript(i1: Index, i2: Index, rest: Index...) -> PermutationGenerator<Self, [Index]> { | |
get { | |
return PermutationGenerator(elements: self, indices: [i1, i2] + rest) | |
} set(values) { | |
for (index, value) in zip([i1, i2] + rest, values) { | |
self[index] = value | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment