Last active
October 16, 2015 19:40
-
-
Save svalleru/d90a73214e32ebb0d74a to your computer and use it in GitHub Desktop.
RingBuffer
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
| class RingBuffer: | |
| def __init__(self, size): | |
| self.data = [None for i in xrange(size)] | |
| def append(self, x): | |
| self.data.pop(0) | |
| self.data.append(x) | |
| def get(self): | |
| return self.data | |
| rb = RingBuffer(2) | |
| rb.append('one') | |
| rb.append('two') | |
| print rb.get() | |
| rb.append('three') | |
| print rb.get() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment