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

update Array2D, Deque to swift3.0 #303

Merged
merged 1 commit into from Dec 17, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Array2D/README.markdown
Expand Up @@ -30,14 +30,14 @@ let myCookie = cookies[3][6]
Actually, you could create the array in a single line of code, like so:

```swift
var cookies = [[Int]](count: 9, repeatedValue: [Int](count: 7, repeatedValue: 0))
var cookies = [[Int]](repeating: [Int](repeating: 0, count: 7), count: 9)
```

but that's just ugly. To be fair, you can hide the ugliness in a helper function:

```swift
func dim<T>(count: Int, _ value: T) -> [T] {
return [T](count: count, repeatedValue: value)
return [T](repeating: value, count: count)
}
```

Expand Down Expand Up @@ -72,7 +72,7 @@ public struct Array2D<T> {
public init(columns: Int, rows: Int, initialValue: T) {
self.columns = columns
self.rows = rows
array = .init(count: rows*columns, repeatedValue: initialValue)
array = .init(repeating: initialValue, count: rows*columns)
}

public subscript(column: Int, row: Int) -> T {
Expand Down
4 changes: 2 additions & 2 deletions Deque/Deque-Optimized.swift
Expand Up @@ -10,7 +10,7 @@ public struct Deque<T> {

public init(_ capacity: Int = 10) {
self.capacity = max(capacity, 1)
array = .init(count: capacity, repeatedValue: nil)
array = [T?](repeating: nil, count: capacity)
head = capacity
}

Expand All @@ -29,7 +29,7 @@ public struct Deque<T> {
public mutating func enqueueFront(_ element: T) {
if head == 0 {
capacity *= 2
let emptySpace = [T?](count: capacity, repeatedValue: nil)
let emptySpace = [T?](repeating: nil, count: capacity)
array.insertContentsOf(emptySpace, at: 0)
head = capacity
}
Expand Down
6 changes: 3 additions & 3 deletions Deque/README.markdown
Expand Up @@ -122,7 +122,7 @@ public struct Deque<T> {

public init(_ capacity: Int = 10) {
self.capacity = max(capacity, 1)
array = .init(count: capacity, repeatedValue: nil)
array = [T?](repeating: nil, count: capacity)
head = capacity
}

Expand Down Expand Up @@ -238,8 +238,8 @@ There is one tiny problem... If you enqueue a lot of objects at the front, you'r
public mutating func enqueueFront(element: T) {
if head == 0 {
capacity *= 2
let emptySpace = [T?](count: capacity, repeatedValue: nil)
array.insertContentsOf(emptySpace, at: 0)
let emptySpace = [T?](repeating: nil, count: capacity)
array.insert(contentsOf: emptySpace, at: 0)
head = capacity
}

Expand Down