<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: FIFO Data Structure in Python</title>
	<atom:link href="http://lemire.me/blog/archives/2006/04/26/fifo-data-structure-in-python/feed/" rel="self" type="application/rss+xml" />
	<link>http://lemire.me/blog/archives/2006/04/26/fifo-data-structure-in-python/</link>
	<description>Computer Scientist and Open Scholar: Databases, Information Retrieval, Business Intelligence.</description>
	<lastBuildDate>Tue, 07 Feb 2012 23:39:16 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: ade</title>
		<link>http://lemire.me/blog/archives/2006/04/26/fifo-data-structure-in-python/comment-page-1/#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&#039;t realised that. Come to think of it the list class has a pop method I could have used.

Anyway if you&#039;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://lemire.me/blog/archives/2006/04/26/fifo-data-structure-in-python/comment-page-1/#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 &quot;del self.items[0]&quot; 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://lemire.me/blog/archives/2006/04/26/fifo-data-structure-in-python/comment-page-1/#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(&#039;a&#039;)
		fifo.append(&#039;b&#039;)
		fifo.append(&#039;c&#039;)
		self.assertEquals(&#039;a&#039;, fifo.pop())
		self.assertEquals(&#039;b&#039;, fifo.pop())
		self.assertEquals(&#039;c&#039;, fifo.pop())
	
	def testFifoLengthChangesAsItemsAreRemoved(self):
		fifo = Fifo()
		fifo.append(&#039;a&#039;)
		fifo.append(&#039;b&#039;)
		fifo.append(&#039;c&#039;)
		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(&#039;a&#039;)
		fifo.append(&#039;b&#039;)
		fifo.append(&#039;c&#039;)
		self.assertEquals([&#039;a&#039;,&#039;b&#039;,&#039;c&#039;], fifo.tolist())
if __name__ == &#039;__main__&#039;:
	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(&#8216;a&#8217;)<br />
		fifo.append(&#8216;b&#8217;)<br />
		fifo.append(&#8216;c&#8217;)<br />
		self.assertEquals(&#8216;a&#8217;, fifo.pop())<br />
		self.assertEquals(&#8216;b&#8217;, fifo.pop())<br />
		self.assertEquals(&#8216;c&#8217;, fifo.pop())</p>
<p>	def testFifoLengthChangesAsItemsAreRemoved(self):<br />
		fifo = Fifo()<br />
		fifo.append(&#8216;a&#8217;)<br />
		fifo.append(&#8216;b&#8217;)<br />
		fifo.append(&#8216;c&#8217;)<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(&#8216;a&#8217;)<br />
		fifo.append(&#8216;b&#8217;)<br />
		fifo.append(&#8216;c&#8217;)<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>

