File tree Expand file tree Collapse file tree 2 files changed +7
-13
lines changed
Ring Buffer/RingBuffer.playground Expand file tree Collapse file tree 2 files changed +7
-13
lines changed Original file line number Diff line number Diff line change 11//: Playground - noun: a place where people can play
22
33public 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
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments