Last active
May 7, 2019 23:38
-
-
Save RinniSwift/541ffc4f1bf02e0c7a543f7550b9a56b to your computer and use it in GitHub Desktop.
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
// 1. | |
class CircularBuffer<T> { | |
var bufferMaxSize: Int | |
var size = 0 | |
// 2. | |
var elements = Array<T?>(repeating: nil, count: 8) | |
// 3. | |
init(maxSize: Int) { | |
self.bufferMaxSize = maxSize | |
self.elements = Array(repeating: nil, count: self.bufferMaxSize) | |
} | |
// 4. | |
convenience init() { | |
self.init(maxSize: 8) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment