Added a reset method to RingBuffer and queue.

This commit is contained in:
Jeremy Fincher 2003-08-26 16:38:28 +00:00
parent ed92fcad2b
commit b1e6cc53ac

View File

@ -47,11 +47,14 @@ class RingBuffer(object):
if maxSize <= 0: if maxSize <= 0:
raise ValueError, 'maxSize must be > 0.' raise ValueError, 'maxSize must be > 0.'
self.maxSize = maxSize self.maxSize = maxSize
self.reset()
for elt in seq:
self.append(elt)
def reset(self):
self.full = False self.full = False
self.L = [] self.L = []
self.i = 0 self.i = 0
for elt in seq:
self.append(elt)
def __len__(self): def __len__(self):
return len(self.L) return len(self.L)
@ -163,6 +166,10 @@ class queue(object):
for elt in seq: for elt in seq:
self.enqueue(elt) self.enqueue(elt)
def reset(self):
self.back[:] = []
self.front[:] = []
def enqueue(self, elt): def enqueue(self, elt):
self.back.append(elt) self.back.append(elt)