File tree 2 files changed +7
-13
lines changed
Ring Buffer/RingBuffer.playground
2 files changed +7
-13
lines changed Original file line number Diff line number Diff line change 1
1
//: Playground - noun: a place where people can play
2
2
3
3
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
7
7
8
8
public init ( count: Int ) {
9
- array = [ T? ] ( count : count , repeatedValue : nil )
9
+ array = [ T? ] ( repeating : nil , count : count )
10
10
}
11
11
12
- public mutating func write( element: T ) -> Bool {
12
+ public mutating func write( _ element: T ) -> Bool {
13
13
if !isFull {
14
14
array [ writeIndex % array. count] = element
15
15
writeIndex += 1
@@ -29,15 +29,15 @@ public struct RingBuffer<T> {
29
29
}
30
30
}
31
31
32
- private var availableSpaceForReading : Int {
32
+ fileprivate var availableSpaceForReading : Int {
33
33
return writeIndex - readIndex
34
34
}
35
35
36
36
public var isEmpty : Bool {
37
37
return availableSpaceForReading == 0
38
38
}
39
39
40
- private var availableSpaceForWriting : Int {
40
+ fileprivate var availableSpaceForWriting : Int {
41
41
return array. count - availableSpaceForReading
42
42
}
43
43
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments