Created
May 7, 2019 17:48
-
-
Save edwintcloud/30329bc644d005523622bf3faf14278b to your computer and use it in GitHub Desktop.
Circular Buffer in Python Part 1
This file contains 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
class CircularBuffer(object): | |
def __init__(self, max_size=10): | |
"""Initialize the CircularBuffer with a max_size if set, otherwise | |
max_size will default to 10""" | |
self.buffer = [None] * max_size | |
self.head = 0 | |
self.tail = 0 | |
self.max_size = max_size | |
def __str__(self): | |
"""Return a formatted string representation of this CircularBuffer.""" | |
items = ['{!r}'.format(item) for item in self.buffer] | |
return '[' + ', '.join(items) + ']' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment