Are there Python code for a FIFO-like structure?
Aahz Maruch
aahz at panix.com
Fri Oct 6 13:30:23 EDT 2000
In article <slrn8ts14c.pu.hzhu at rocket.knowledgetrack.com>,
Huaiyu Zhu <hzhu at users.sourceforge.net> wrote:
>
>The fixed length requirement is meant to limit its growth and raise error
>when it's full, at that time several different actions might be taken. The
>rotation requirement is so that it's light weight even if it's large.
Unless large means >1000, I'd suggest you not waste time on it. One
option for simplicity might be to just use a dictionary with a unique
value for each item. Here's a sketch, not complete:
class dict_queue:
def __init__ (self, max_size):
self.max_size = max_size
self.min = None
self.max = None
self.queue = {}
def put(self, item):
if (self.max - self.min) >= self.max_size:
raise ValueError, "Too many items in queue"
self.max = self.max + 1
self.queue[self.max] = item
def get(self):
tmp = self.queue[self.min]
del queue[self.min]
self.min = self.min - 1
return tmp
--
--- Aahz (Copyright 2000 by aahz at pobox.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
There's a difference between a person who gets shit zie doesn't
deserve and a person who gets more shit than zie deserves. --Aahz
More information about the Python-list
mailing list