Skip to content

Instantly share code, notes, and snippets.

@RinniSwift
Last active May 7, 2019 23:38
Show Gist options
  • Save RinniSwift/541ffc4f1bf02e0c7a543f7550b9a56b to your computer and use it in GitHub Desktop.
Save RinniSwift/541ffc4f1bf02e0c7a543f7550b9a56b to your computer and use it in GitHub Desktop.
// 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