mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 18:44:04 +01:00
Swapped implementation of MaxLengthQueue.
This commit is contained in:
parent
8fa7c95067
commit
fe2f2c1ac0
@ -234,28 +234,28 @@ class queue(object):
|
|||||||
self.back = []
|
self.back = []
|
||||||
|
|
||||||
|
|
||||||
class MaxLengthQueue(queue):
|
## class MaxLengthQueue(queue):
|
||||||
__slots__ = ('length',)
|
## __slots__ = ('length',)
|
||||||
def __init__(self, length, seq=()):
|
## def __init__(self, length, seq=()):
|
||||||
self.length = length
|
## self.length = length
|
||||||
queue.__init__(self, seq)
|
## queue.__init__(self, seq)
|
||||||
|
|
||||||
def __getstate__(self):
|
## def __getstate__(self):
|
||||||
return (self.length, queue.__getstate__(self))
|
## return (self.length, queue.__getstate__(self))
|
||||||
|
|
||||||
def __setstate__(self, (length, q)):
|
## def __setstate__(self, (length, q)):
|
||||||
self.length = length
|
## self.length = length
|
||||||
queue.__setstate__(self, q)
|
## queue.__setstate__(self, q)
|
||||||
|
|
||||||
def enqueue(self, elt):
|
## def enqueue(self, elt):
|
||||||
queue.enqueue(self, elt)
|
## queue.enqueue(self, elt)
|
||||||
if len(self) > self.length:
|
## if len(self) > self.length:
|
||||||
self.dequeue()
|
## self.dequeue()
|
||||||
|
|
||||||
## class MaxLengthQueue(RingBuffer):
|
class MaxLengthQueue(RingBuffer):
|
||||||
## enqueue = RingBuffer.append
|
enqueue = RingBuffer.append
|
||||||
## def peek(self):
|
def peek(self):
|
||||||
## return self[0]
|
return self[0]
|
||||||
|
|
||||||
|
|
||||||
def sliceIndices(slice, length):
|
def sliceIndices(slice, length):
|
||||||
|
Loading…
Reference in New Issue
Block a user