<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: FIFO Data Structure in Python</title>
	<atom:link href="http://www.daniel-lemire.com/blog/archives/2006/04/26/fifo-data-structure-in-python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daniel-lemire.com/blog/archives/2006/04/26/fifo-data-structure-in-python/</link>
	<description>Daniel Lemire's blog is about life in academia, research in Computer Science, wondering how we can reconcile fast databases and algorithms with the informal and asemantic nature of the world around us. It is broadcasted from Montreal (Canada).</description>
	<pubDate>Mon, 01 Dec 2008 19:23:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
		<item>
		<title>By: ade</title>
		<link>http://www.daniel-lemire.com/blog/archives/2006/04/26/fifo-data-structure-in-python/#comment-4174</link>
		<dc:creator>ade</dc:creator>
		<pubDate>Mon, 01 May 2006 10:27:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.daniel-lemire.com/blog/archives/2006/04/26/fifo-data-structure-in-python/#comment-4174</guid>
		<description>Thanks I hadn't realised that. Come to think of it the list class has a pop method I could have used.

Anyway if you're interested in a highly-performant Fifo class then take a look at the bottom of this Python Cookbook entry: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68436</description>
		<content:encoded><![CDATA[<p>Thanks I hadn&#8217;t realised that. Come to think of it the list class has a pop method I could have used.</p>
<p>Anyway if you&#8217;re interested in a highly-performant Fifo class then take a look at the bottom of this Python Cookbook entry: <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68436" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68436</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Lemire</title>
		<link>http://www.daniel-lemire.com/blog/archives/2006/04/26/fifo-data-structure-in-python/#comment-4159</link>
		<dc:creator>Daniel Lemire</dc:creator>
		<pubDate>Mon, 01 May 2006 00:49:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.daniel-lemire.com/blog/archives/2006/04/26/fifo-data-structure-in-python/#comment-4159</guid>
		<description>Because the expected popping time of your solution is linear with respect to the size of the list. Specifically, doing "del self.items[0]" can be tremendously expensive since Python needs to copy the entire array to a new location in memory. Doing so thousands of times is highly inefficient.</description>
		<content:encoded><![CDATA[<p>Because the expected popping time of your solution is linear with respect to the size of the list. Specifically, doing &#8220;del self.items[0]&#8221; can be tremendously expensive since Python needs to copy the entire array to a new location in memory. Doing so thousands of times is highly inefficient.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ade</title>
		<link>http://www.daniel-lemire.com/blog/archives/2006/04/26/fifo-data-structure-in-python/#comment-4155</link>
		<dc:creator>ade</dc:creator>
		<pubDate>Sun, 30 Apr 2006 22:16:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.daniel-lemire.com/blog/archives/2006/04/26/fifo-data-structure-in-python/#comment-4155</guid>
		<description>Why not try something simpler like this:

class Fifo:
	def __init__(self):
		self.items = []

	def append(self, item):
		self.items.append(item)

	def pop(self):
		item = self.items[0]
		del self.items[0]
		return item

	def __len__(self):
		return len(self.items)
		
	def tolist(self):
		#defensive copy
		return self.items[:]

import unittest
class FifoTest(unittest.TestCase):
	def testItemsArePoppedInSameOrderTheyWereRemoved(self):
		fifo = Fifo()
		fifo.append('a')
		fifo.append('b')
		fifo.append('c')
		self.assertEquals('a', fifo.pop())
		self.assertEquals('b', fifo.pop())
		self.assertEquals('c', fifo.pop())
	
	def testFifoLengthChangesAsItemsAreRemoved(self):
		fifo = Fifo()
		fifo.append('a')
		fifo.append('b')
		fifo.append('c')
		self.assertEquals(3, len(fifo))
		fifo.pop()
		self.assertEquals(2, len(fifo))
		fifo.pop()
		self.assertEquals(1, len(fifo))
		fifo.pop()
		self.assertEquals(0, len(fifo))
	
	def testFifoCanBeConvertedToList(self):
		fifo = Fifo()
		fifo.append('a')
		fifo.append('b')
		fifo.append('c')
		self.assertEquals(['a','b','c'], fifo.tolist())
if __name__ == '__main__':
	suite = unittest.TestSuite()
	suite.addTest(unittest.makeSuite(FifoTest))
	unittest.TextTestRunner(verbosity=3).run(suite)</description>
		<content:encoded><![CDATA[<p>Why not try something simpler like this:</p>
<p>class Fifo:<br />
	def __init__(self):<br />
		self.items = []</p>
<p>	def append(self, item):<br />
		self.items.append(item)</p>
<p>	def pop(self):<br />
		item = self.items[0]<br />
		del self.items[0]<br />
		return item</p>
<p>	def __len__(self):<br />
		return len(self.items)</p>
<p>	def tolist(self):<br />
		#defensive copy<br />
		return self.items[:]</p>
<p>import unittest<br />
class FifoTest(unittest.TestCase):<br />
	def testItemsArePoppedInSameOrderTheyWereRemoved(self):<br />
		fifo = Fifo()<br />
		fifo.append(&#8217;a')<br />
		fifo.append(&#8217;b')<br />
		fifo.append(&#8217;c')<br />
		self.assertEquals(&#8217;a', fifo.pop())<br />
		self.assertEquals(&#8217;b', fifo.pop())<br />
		self.assertEquals(&#8217;c', fifo.pop())</p>
<p>	def testFifoLengthChangesAsItemsAreRemoved(self):<br />
		fifo = Fifo()<br />
		fifo.append(&#8217;a')<br />
		fifo.append(&#8217;b')<br />
		fifo.append(&#8217;c')<br />
		self.assertEquals(3, len(fifo))<br />
		fifo.pop()<br />
		self.assertEquals(2, len(fifo))<br />
		fifo.pop()<br />
		self.assertEquals(1, len(fifo))<br />
		fifo.pop()<br />
		self.assertEquals(0, len(fifo))</p>
<p>	def testFifoCanBeConvertedToList(self):<br />
		fifo = Fifo()<br />
		fifo.append(&#8217;a')<br />
		fifo.append(&#8217;b')<br />
		fifo.append(&#8217;c')<br />
		self.assertEquals(['a','b','c'], fifo.tolist())<br />
if __name__ == &#8216;__main__&#8217;:<br />
	suite = unittest.TestSuite()<br />
	suite.addTest(unittest.makeSuite(FifoTest))<br />
	unittest.TextTestRunner(verbosity=3).run(suite)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
