<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Renaud Bourassa &#187; Stack</title>
	<atom:link href="http://renaudbourassa.com/blog/tag/stack/feed/" rel="self" type="application/rss+xml" />
	<link>http://renaudbourassa.com/blog</link>
	<description>Welcome to my World. Here, I am the Architect.</description>
	<lastBuildDate>Tue, 01 Jun 2010 04:18:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Basic Data Structure Addition to Batfish</title>
		<link>http://renaudbourassa.com/blog/2009/09/24/basic-data-structure-addition-to-batfish/</link>
		<comments>http://renaudbourassa.com/blog/2009/09/24/basic-data-structure-addition-to-batfish/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 02:18:36 +0000</pubDate>
		<dc:creator>Rhino</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Batfish]]></category>
		<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Linked List]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Stack]]></category>

		<guid isPermaLink="false">http://renaudbourassa.com/blog/?p=470</guid>
		<description><![CDATA[Batfish is collection of data structures and algorithms written in Ruby that I started about a month ago. While trying to implement graphs in the library, I quickly realised that a number of basic data structure were missing to implement certain graph algorithms. Stacks and queues were needed to respectively implement the depth-first search and [...]]]></description>
			<content:encoded><![CDATA[<p>Batfish is collection of data structures and algorithms written in Ruby that I started about a month ago. While trying to implement graphs in the library, I quickly realised that a number of basic data structure were missing to implement certain graph algorithms. Stacks and queues were needed to respectively implement the depth-first search and breadth-first search algorithm and a linked list is a good way to represent the adjency lists of vertices. </p>
<p>I thus decided to implement these simple, but oh so useful data structures. Sure, you could reply that ruby arrays already implement all the functionalities provided by theses data structures. True, but when you are dealing with linked lists of millions of elements, having to relocate the whole array in memory to add an element can prove to be a lenghty task. Also, finding a memory chunk big enough to hold the whole array may prove challenging. Ruby arrays grow pretty fast (~1.5x) as can be seen from the following code snippet from array.c (ruby 1.9.1p243) and can rapidly become hard to store in memory.</p>
<pre class="brush: ruby;">
if (idx &gt;= ARY_CAPA(ary)) {
    long new_capa = ARY_CAPA(ary) / 2;

    if (new_capa &lt; ARY_DEFAULT_SIZE) {
        new_capa = ARY_DEFAULT_SIZE;
    }
    if (new_capa &gt;= ARY_MAX_SIZE - idx) {
        new_capa = (ARY_MAX_SIZE - idx) / 2;
    }
    new_capa += idx;
    ary_resize_capa(ary, new_capa);
}
</pre>
<p>And finally, theses data structures implement functionalities that are badly supported by arrays such as deleting or adding an element in the middle of a list.</p>
<p>The stack and queue implementation are separated from the linked list implementation to keep them as simple as possible. The linked list implementation is more extensive and is also used to implement the sorted linked list data structure. The next data structure to be added to Batfish will probably be graphs and it should include a number of basic graph algorithms.</p>
]]></content:encoded>
			<wfw:commentRss>http://renaudbourassa.com/blog/2009/09/24/basic-data-structure-addition-to-batfish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
