This file contains hidden or 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
| enum Color { case R, B } | |
| indirect enum Tree<Element: Comparable> { | |
| case Empty | |
| case Node(Color,Tree<Element>,Element,Tree<Element>) | |
| init() { self = .Empty } | |
| init(_ x: Element, color: Color = .B, | |
| left: Tree<Element> = .Empty, right: Tree<Element> = .Empty) |
This file contains hidden or 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
| private enum ListNode<Element> { | |
| case End | |
| indirect case Node(Element, tag: Int, next: ListNode<Element>) | |
| /// Computed property to fetch the tag. .End has an | |
| /// implicit tag of zero. | |
| var tag: Int { | |
| switch self { | |
| case .End: return 0 | |
| case let .Node(_, tag: n, _): |
This file contains hidden or 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
| extension Array where Element: Comparable | |
| { | |
| mutating func mergesortInPlace() { | |
| var tmp: [Generator.Element] = [] | |
| tmp.reserveCapacity(numericCast(self.count)) | |
| func merge(lo: Int, _ mi: Int, _ hi: Int) { | |
| tmp.removeAll(keepCapacity: true) | |
| tmp.extend(self[lo..<hi]) |
This file contains hidden or 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
| private enum ListNode<Element> { | |
| case End | |
| indirect case Node(Element, next: ListNode<Element>) | |
| func cons(x: Element) -> ListNode<Element> { | |
| return .Node(x, next: self) | |
| } | |
| } | |
| public struct ListIndex<Element> { |
This file contains hidden or 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
| // works for any index type | |
| extension CollectionType { | |
| var mid: Index { | |
| return advance(startIndex, | |
| distance(startIndex,endIndex) / 2 | |
| ) | |
| } | |
| } | |
| // and specialize for random-access index types |
This file contains hidden or 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 SubSliceView<C: CollectionType>: Sliceable { | |
| let collection: C | |
| let bounds: Range<C.Index> | |
| public var startIndex: C.Index { return bounds.startIndex } | |
| public var endIndex: C.Index { return bounds.endIndex } | |
| public subscript(idx: C.Index) -> C.Generator.Element |
This file contains hidden or 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
| struct Properties { | |
| // someday soon these can be private | |
| var _name: String, _nameModificationDate: Int | |
| var _shape: String, _shapeModificationDate: Int | |
| init(name: String, nameModificationDate: Int, | |
| shape: String, shapeModificationDate: Int) { | |
| self._name = name | |
| self._nameModificationDate = nameModificationDate | |
| self._shape = shape |
This file contains hidden or 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
| import Darwin | |
| import CoreFoundation.CFDate | |
| protocol NumberGeneratorType { | |
| mutating func generateNumber() -> Int | |
| } | |
| struct RandomGenerator: NumberGeneratorType { | |
| func generateNumber() -> Int { | |
| return Int(arc4random_uniform(10)) |
This file contains hidden or 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
| Removed NSFileProviderExtension | |
| Removed UIAccelerometerDelegate | |
| Removed UIActionSheet | |
| Removed UIActionSheetDelegate | |
| Removed UIActivity | |
| Removed UIActivityItemProvider | |
| Removed UIActivityViewController | |
| Removed UIAlertView | |
| Removed UIAlertViewDelegate | |
| Removed UIApplicationShortcutIcon |
This file contains hidden or 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 enum Error: ErrorType, CustomDebugStringConvertible { | |
| // Add error enumerations here | |
| case FirstError(source: String, reason: String) | |
| public var debugDescription: String { | |
| let mirror = Mirror(reflecting: self) | |
| guard let item = mirror.children.first else {fatalError("Missing error enumeration item")} | |
| guard let myEnumeration = item.label else {fatalError("Missing error enumeration label")} |