Skip to content

Commit 3947c6b

Browse files
committed
migrate ring buffer to swift 3
1 parent 3960cf5 commit 3947c6b

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

Ring Buffer/RingBuffer.playground/Contents.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//: Playground - noun: a place where people can play
22

33
public struct RingBuffer<T> {
4-
private var array: [T?]
5-
private var readIndex = 0
6-
private var writeIndex = 0
4+
fileprivate var array: [T?]
5+
fileprivate var readIndex = 0
6+
fileprivate var writeIndex = 0
77

88
public init(count: Int) {
9-
array = [T?](count: count, repeatedValue: nil)
9+
array = [T?](repeating: nil, count: count)
1010
}
1111

12-
public mutating func write(element: T) -> Bool {
12+
public mutating func write(_ element: T) -> Bool {
1313
if !isFull {
1414
array[writeIndex % array.count] = element
1515
writeIndex += 1
@@ -29,15 +29,15 @@ public struct RingBuffer<T> {
2929
}
3030
}
3131

32-
private var availableSpaceForReading: Int {
32+
fileprivate var availableSpaceForReading: Int {
3333
return writeIndex - readIndex
3434
}
3535

3636
public var isEmpty: Bool {
3737
return availableSpaceForReading == 0
3838
}
3939

40-
private var availableSpaceForWriting: Int {
40+
fileprivate var availableSpaceForWriting: Int {
4141
return array.count - availableSpaceForReading
4242
}
4343

Ring Buffer/RingBuffer.playground/timeline.xctimeline

-6
This file was deleted.

0 commit comments

Comments
 (0)