Skip to content

Commit 1e7975a

Browse files
committed
Completed ring_buffer class
1 parent 5cd7590 commit 1e7975a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ring_buffer/ring_buffer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ def __init__(self, capacity):
44
self.current = 0
55
self.storage = [None]*capacity
66

7+
# when full always append by replacing the oldest information - not full replace the first preset None seen
78
def append(self, item):
8-
pass
9+
self.storage[self.current % self.capacity] = item
10+
self.current = (self.current + 1) % self.capacity
911

12+
# return everything from buffer, in order, ignoring None values
1013
def get(self):
11-
pass
14+
return [item for item in self.storage if item is not None]

0 commit comments

Comments
 (0)