<?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:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"
>

<channel>
	<title>Developer with some grey hairs &#187; english</title>
	<atom:link href="http://kai.system7.de/category/english/feed/" rel="self" type="application/rss+xml" />
	<link>http://kai.system7.de</link>
	<description></description>
	<pubDate>Fri, 21 Jan 2011 12:24:35 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ubuntu 9.10 and the Google Go Emacs Mode</title>
		<link>http://kai.system7.de/2009/11/24/ubuntu-910-and-the-google-go-emacs-mode/</link>
		<comments>http://kai.system7.de/2009/11/24/ubuntu-910-and-the-google-go-emacs-mode/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 11:00:13 +0000</pubDate>
		<dc:creator>kai</dc:creator>
		
		<category><![CDATA[english]]></category>

		<category><![CDATA[hacking]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[open source]]></category>

		<category><![CDATA[technic]]></category>

		<guid isPermaLink="false">http://kai.system7.de/?p=645</guid>
		<description><![CDATA[After some hours with google go I recognize the emacs mode in the source directory of the current distribution.
It is easy to install the mode for ubuntu 9.10 (karmic). First install the emacs with
sudo apt-get install emacs23
After that copy the the two .el files from you google ~/go/misc/emacs directory to
/usr/share/emacs/23.1/lisp
Now create a .emacs file in [...]]]></description>
			<content:encoded><![CDATA[<p>After some hours with google go I recognize the emacs mode in the source directory of the current distribution.</p>
<p>It is easy to install the mode for ubuntu 9.10 (karmic). First install the emacs with</p>
<p><strong>sudo apt-get install emacs23</strong></p>
<p>After that copy the the two .el files from you google ~/go/misc/emacs directory to</p>
<p><strong>/usr/share/emacs/23.1/lisp</strong></p>
<p>Now create a .emacs file in you home directory and add the following to lines.</p>
<p><code>(add-to-list ‘load-path “/usr/share/emacs/23.1/lisp” t)<br />
(require ‘go-mode-load)</code></p>
<p>Now the google mode is activated after loading a .go file.</p>
<p><center><br />
<img src="http://kai.system7.de/images/emacs-go.jpg" alt="Emacs with go mode"/><br />
</center></p>
<p><script type="text/javascript">var dzone_url = 'http://kai.system7.de/2009/11/24/ubuntu-910-and-the-google-go-emacs-mode/';</script><br />
<script type="text/javascript">var dzone_title = 'Ubuntu 9.10 and the Google Go Emacs Mode';</script><br />
<script type="text/javascript">var dzone_blurb = 'Installing go emacs mode in ubuntu';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://kai.system7.de/2009/11/24/ubuntu-910-and-the-google-go-emacs-mode/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Splintering of Empires</title>
		<link>http://kai.system7.de/2009/11/18/splintering-of-empires/</link>
		<comments>http://kai.system7.de/2009/11/18/splintering-of-empires/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 09:58:11 +0000</pubDate>
		<dc:creator>kai</dc:creator>
		
		<category><![CDATA[art]]></category>

		<category><![CDATA[english]]></category>

		<category><![CDATA[politics]]></category>

		<guid isPermaLink="false">http://kai.system7.de/?p=648</guid>
		<description><![CDATA[


More about this nice project Link
]]></description>
			<content:encoded><![CDATA[<p><center><br />
<object width="500" height="281"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=6437816&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=6437816&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="500" height="281"></embed></object><br />
</center></p>
<p>More about this nice project <a href="http://mondeguinho.com/master/visual-experimentations/visualizing-empires">Link</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kai.system7.de/2009/11/18/splintering-of-empires/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google Go and the Mandelbrot Set Part II</title>
		<link>http://kai.system7.de/2009/11/17/google-go-and-the-mandelbrot-set-part-ii/</link>
		<comments>http://kai.system7.de/2009/11/17/google-go-and-the-mandelbrot-set-part-ii/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 10:22:33 +0000</pubDate>
		<dc:creator>kai</dc:creator>
		
		<category><![CDATA[english]]></category>

		<category><![CDATA[hacking]]></category>

		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://kai.system7.de/?p=620</guid>
		<description><![CDATA[The following code is my solution for parallel calculation of a mandelbrot set with google go.

package main

import ( "image";
        "image/png";
	"bufio";
	"fmt";
	"os";
	"math";
	"time"; )

type PixelCalc struct {  x int;
     	                 [...]]]></description>
			<content:encoded><![CDATA[<p>The following code is my solution for parallel calculation of a mandelbrot set with <a href="http://golang.org/">google go</a>.</p>
<pre class="code">
package main

import ( "image";
        "image/png";
	"bufio";
	"fmt";
	"os";
	"math";
	"time"; )

type PixelCalc struct {  x int;
     	                 y int;
                         cx float64;
	                 cy float64; }

func PointIteration(in chan *PixelCalc,ready chan int,img *image.RGBA){

	for {
		pixelCalc :=  &lt;- in; 

		xt := float64(0);
		yt := float64(0);
		x := float64(0);
		y := float64(0);
		quadValue := float64(0);
		iter := 0;

		for quadValue &lt;= 255.0 &#038;&#038; iter < 255 {
			xt= ( x * x ) - ( y * y) + pixelCalc.cx;
			yt= ( float64(2.0) * x * y ) + pixelCalc.cy;
			x = xt;
			y = yt;
			iter++;

			quadValue = ( x * x ) + ( y * y );
		}

		color := new(image.NRGBAColor);
		color.A = 255;
		iter8 := uint8(iter);
		color.R = iter8;
		color.G = iter8;
		color.B = iter8;
		img.Set(pixelCalc.x,pixelCalc.y,color);

		ready &lt;- 1;
	}
}

func main(){
	start := time.Seconds();

	const pictureSize = 1000;

	img := image.NewRGBA(pictureSize,pictureSize);

	f, err := os.Open("mandel.png", os.O_WRONLY|os.O_CREAT, 0666);
	if err != nil {
		fmt.Printf("Can't create picture file\n");
	}

	calc := make(chan *PixelCalc,pictureSize*pictureSize);
	out := make(chan int,pictureSize*pictureSize);

	for i:=0;i&lt;4;i++{
		go PointIteration(calc,out,img);
	}

	deltaX := math.Fabs(float64(-2.0 - 1.0)) / float64(pictureSize);
        deltaY := math.Fabs(float64(-1.0 - 1.0)) / float64(pictureSize);

	cx := float64(-2.0);

	for x:=0;x&lt;pictureSize;x++{
		cx+=deltaX;
		cy := float64(-1.0);

		for y:=0;y&lt;pictureSize;y++{
	    		cy+=deltaY;
			pixelCalc := new(PixelCalc);
			pixelCalc.cx = cx;
			pixelCalc.cy = cy;
			pixelCalc.x  = x;
			pixelCalc.y  = y;

			calc &lt;- pixelCalc;
		}
	}	

	for i:=0;i&lt;pictureSize*pictureSize;i++{
		&lt;- out;
	}

  	w := bufio.NewWriter(f);
	png.Encode(w,img);
	w.Flush();

	fmt.Printf("Seconds needed %d\n",time.Seconds() - start);
}
</pre>
<p>At this time the go compiler has some bugs regarding the multiprocessor support. But sometimes I can see the use of my two processors.</p>
<p><img src="http://kai.system7.de/images/processor-load.jpg" alt="processor load" /></p>
<p>I hope there will fix that bug fast. The first workaround for that bug is the GOMAXPROCS environment variable. I set this to 2. But this did&#8217;nt help everytime. </p>
<p><a href="http://kai.system7.de/2009/11/13/google-go-and-the-mandelbrot-set/">Link to part 1</a></p>
<p><script type="text/javascript">var dzone_url = 'http://kai.system7.de/2009/11/17/google-go-and-the-mandelbrot-set-part-ii/';</script><br />
<script type="text/javascript">var dzone_title = 'Google Go and the Mandelbrot Set Part II';</script><br />
<script type="text/javascript">var dzone_blurb = '';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://kai.system7.de/2009/11/17/google-go-and-the-mandelbrot-set-part-ii/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google Go and the Mandelbrot Set</title>
		<link>http://kai.system7.de/2009/11/13/google-go-and-the-mandelbrot-set/</link>
		<comments>http://kai.system7.de/2009/11/13/google-go-and-the-mandelbrot-set/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 10:30:08 +0000</pubDate>
		<dc:creator>kai</dc:creator>
		
		<category><![CDATA[english]]></category>

		<category><![CDATA[hacking]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[go]]></category>

		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://kai.system7.de/?p=591</guid>
		<description><![CDATA[Learning a new programming language is fun. Here is my version of calculating the mandelbrot set and save the result as a PNG picture with Google Go. 

package main

import (   "image";
           "image/png";
           "bufio";
	 [...]]]></description>
			<content:encoded><![CDATA[<p>Learning a new programming language is fun. Here is my version of calculating the mandelbrot set and save the result as a PNG picture with <a href="http://golang.org">Google Go</a>. </p>
<pre class="code">
package main

import (   "image";
           "image/png";
           "bufio";
	   "fmt";
	   "os";
           "math";
           "time"; )

func PointIteration( cx, cy, maxValue float64, maxIter uint8) uint8{
     quadValue := float64(0.0);
     iter := uint8(0);
     x := float64(0.0);
     y := float64(0.0);

    for quadValue &lt;= maxValue &#038;&#038; iter &lt; maxIter {
        xt:= ( x * x ) - ( y * y) + cx;
        yt:= ( float64(2.0) * x * y ) + cy;
        x = xt;
        y = yt;
        iter++;
        quadValue = ( x * x ) + ( y * y );
    }
    return iter;
}

func main(){
    start := time.Seconds();     

    const pictureSize = 500;
    img := image.NewRGBA(pictureSize,pictureSize);

    f, err := os.Open("mandel.png", os.O_WRONLY|os.O_CREAT, 0666);
    if err != nil {
       fmt.Printf("Can't create picture file\n");
    }

    deltaX := math.Fabs(float64(-2.0 - 1.0)) / float64(pictureSize);
    deltaY := math.Fabs(float64(-1.0 - 1.0)) / float64(pictureSize);

    cx := float64(-2.0);
    for x:=0;x&lt;pictureSize;x++{
        cx+=deltaX;
        cy := float64(-1.0);
        for y:=0;y&lt;pictureSize;y++{
           cy+=deltaY;
           iter := PointIteration(cx,cy,255.0,255);

           color := new(image.NRGBAColor);
           color.A = 255;
           color.R = iter;
           color.G = iter;
           color.B = iter;
           img.Set(x,y,color);
	}
     }

     w := bufio.NewWriter(f);
     png.Encode(w,img);
     w.Flush();

     fmt.Printf("Seconds needed %d\n",time.Seconds() - start);
}
</pre>
<p>And here the result. <img src='http://kai.system7.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><img src="http://kai.system7.de/images/mandel.png" alt="Mandelbrot Set - calculated with google go" /></p>
<p>Next step is trying to improve the speed by using <a href="http://golang.org/doc/effective_go.html#goroutines">goroutines</a> and <a href="http://golang.org/doc/effective_go.html#channels">channels</a>. </p>
<p><script type="text/javascript">var dzone_url = 'http://kai.system7.de/2009/11/13/google-go-and-the-mandelbrot-set/';</script><br />
<script type="text/javascript">var dzone_title = 'Google Go and the Mandelbrot Set Part I';</script><br />
<script type="text/javascript">var dzone_blurb = '';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://kai.system7.de/2009/11/13/google-go-and-the-mandelbrot-set/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Crisis of Credit Visualized</title>
		<link>http://kai.system7.de/2009/02/24/the-crisis-of-credit-visualized/</link>
		<comments>http://kai.system7.de/2009/02/24/the-crisis-of-credit-visualized/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 09:09:27 +0000</pubDate>
		<dc:creator>kai</dc:creator>
		
		<category><![CDATA[english]]></category>

		<category><![CDATA[life]]></category>

		<category><![CDATA[politics]]></category>

		<guid isPermaLink="false">http://kai.system7.de/?p=326</guid>
		<description><![CDATA[The best explanation of the current finance crisis that I have seen so far.



More movies from Jonathan Jarvis.
]]></description>
			<content:encoded><![CDATA[<p>The best explanation of the current finance crisis that I have seen so far.<br />
<center><br />
<object width="500" height="281"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=3261363&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=3261363&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="500" height="281"></embed></object><br />
</center><br />
More movies from <a href="http://www.vimeo.com/jonathanjarvis">Jonathan Jarvis</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://kai.system7.de/2009/02/24/the-crisis-of-credit-visualized/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Iran, a Nation of Bloggers</title>
		<link>http://kai.system7.de/2008/11/26/iran-a-nation-of-bloggers/</link>
		<comments>http://kai.system7.de/2008/11/26/iran-a-nation-of-bloggers/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 08:29:52 +0000</pubDate>
		<dc:creator>kai</dc:creator>
		
		<category><![CDATA[english]]></category>

		<category><![CDATA[politics]]></category>

		<guid isPermaLink="false">http://kai.system7.de/?p=168</guid>
		<description><![CDATA[


No Comments needed Link
]]></description>
			<content:encoded><![CDATA[<p><center><br />
<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=2232226&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=2232226&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object><br />
</center></p>
<p>No Comments needed <a href="http://motionographer.com/2008/11/19/iran-a-nation-of-bloggers/">Link</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kai.system7.de/2008/11/26/iran-a-nation-of-bloggers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>&#8220;Where the Hell is Matt&#8221; the Presentation</title>
		<link>http://kai.system7.de/2008/09/24/where-the-hell-is-matt-the-presentation/</link>
		<comments>http://kai.system7.de/2008/09/24/where-the-hell-is-matt-the-presentation/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 09:25:29 +0000</pubDate>
		<dc:creator>kai</dc:creator>
		
		<category><![CDATA[english]]></category>

		<category><![CDATA[travel]]></category>

		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://kai.system7.de/?p=154</guid>
		<description><![CDATA[


A short presentation from Matt at a the Oreilly Ignite. Funny and cool&#8230;   
]]></description>
			<content:encoded><![CDATA[<p><center><br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/ue1GZ4IUFiU&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/ue1GZ4IUFiU&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object><br />
</center></p>
<p>A short presentation from <a href="http://www.wherethehellismatt.com/?fbid=2y4jMfjy9o9">Matt</a> at a the <a href="http://ignite.oreilly.com/">Oreilly Ignite</a>. Funny and cool&#8230; <img src='http://kai.system7.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://kai.system7.de/2008/09/24/where-the-hell-is-matt-the-presentation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hug a developer today</title>
		<link>http://kai.system7.de/2008/09/10/hug-a-developer-today/</link>
		<comments>http://kai.system7.de/2008/09/10/hug-a-developer-today/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 11:56:44 +0000</pubDate>
		<dc:creator>kai</dc:creator>
		
		<category><![CDATA[english]]></category>

		<category><![CDATA[hacking]]></category>

		<category><![CDATA[life]]></category>

		<category><![CDATA[technic]]></category>

		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://kai.system7.de/?p=151</guid>
		<description><![CDATA[																											
																		Click to play						
												       play_blip_movie_1067270();																						
I need a hug..  
]]></description>
			<content:encoded><![CDATA[<p><center>																					<script type="text/javascript" src="http://blip.tv/scripts/pokkariPlayer.js?ver=2008010901"></script>						<script type="text/javascript" src="http://blip.tv/syndication/write_player?skin=js&#038;posts_id=1067270&#038;source=3&#038;autoplay=false&#038;file_type=flv&#038;player_width=640&#038;player_height=360"></script>
<div id="blip_movie_content_1067270">						<a rel="enclosure" href="http://blip.tv/file/get/Cfitzpatrick-HugADeveloperToday681.flv" onclick="play_blip_movie_1067270(); return false;"><img title="Click to play" alt="Video thumbnail. Click to play." src="http://blip.tv/file/get/Cfitzpatrick-HugADeveloperToday681.flv.jpg" border="0" title="Click to play" /></a>						<br />						<a rel="enclosure" href="http://blip.tv/file/get/Cfitzpatrick-HugADeveloperToday681.flv" onclick="play_blip_movie_1067270(); return false;">Click to play</a>						</div>
<p>						<script type="text/javascript">						       play_blip_movie_1067270();							</script>															</center></p>
<p>I need a hug.. <img src='http://kai.system7.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kai.system7.de/2008/09/10/hug-a-developer-today/feed/</wfw:commentRss>
<enclosure url="http://blip.tv/file/get/Cfitzpatrick-HugADeveloperToday681.flv" length="6609886" type="video/x-flv" />
		</item>
		<item>
		<title>Mormons</title>
		<link>http://kai.system7.de/2008/09/06/mormonen/</link>
		<comments>http://kai.system7.de/2008/09/06/mormonen/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 10:56:43 +0000</pubDate>
		<dc:creator>kai</dc:creator>
		
		<category><![CDATA[english]]></category>

		<category><![CDATA[ethic]]></category>

		<guid isPermaLink="false">http://kai.system7.de/?p=148</guid>
		<description><![CDATA[


Ohh yeah. Mormons driving me crazy. Watch the stupid story of the formation. 
]]></description>
			<content:encoded><![CDATA[<p><center><br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/zy0d1HbItOo&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/zy0d1HbItOo&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object><br />
</center></p>
<p>Ohh yeah. Mormons driving me crazy. Watch the stupid story of the formation. </p>
]]></content:encoded>
			<wfw:commentRss>http://kai.system7.de/2008/09/06/mormonen/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hashtable vs. List</title>
		<link>http://kai.system7.de/2008/01/25/hashtable-vs-list/</link>
		<comments>http://kai.system7.de/2008/01/25/hashtable-vs-list/#comments</comments>
		<pubDate>Fri, 25 Jan 2008 16:47:53 +0000</pubDate>
		<dc:creator>kai</dc:creator>
		
		<category><![CDATA[english]]></category>

		<category><![CDATA[hacking]]></category>

		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://kai.system7.de/2008/01/25/hashtable-vs-list/</guid>
		<description><![CDATA[Like every student of computer science, I had a course with the title „algorithm and data structures“. That is one of the classic subjects in informatics. You are learn things like linked list, tree&#8217;s and so on. Also different algorithm for searching. Sequential search, binary search and top-down 2-3-4 trees. It is a nice and [...]]]></description>
			<content:encoded><![CDATA[<p>Like every student of computer science, I had a course with the title „algorithm and data structures“. That is one of the classic subjects in informatics. You are learn things like linked list, tree&#8217;s and so on. Also different algorithm for searching. Sequential search, binary search and top-down 2-3-4 trees. It is a nice and important subject. Today we have frameworks like Java,.NET,Python and they all have build in data structures like lists and hashtables. With these technics it is quite easy to use a list. Here is a small and nice example in Python:</p>
<div class="hlcode">
<div class="syntax">
<pre><span class="nb">list</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mf">10000</span><span class="p">):</span>
   <span class="n">rand</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mf">0</span><span class="p">,</span><span class="mf">50000</span><span class="p">)</span>
   <span class="k">if</span> <span class="ow">not</span> <span class="n">rand</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">:</span>
      <span class="nb">list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">rand</span><span class="p">)</span>
</pre>
</div>
</div>
<p>Now we have a list with up to 10000 random and unique entries. Very easy to program, but you also see the performance problem. In line 4 is a check for the uniqueness of the possible new entry. To check for existence of an element in a list, the framework runs through all elements of the list.  That is a sequential search, the slowest searching algorithm in this universe. This small example needs 365360 microseconds on my machine. </p>
<p>Now lets try a different version with a dictionary. </p>
<div class="hlcode">
<div class="syntax">
<pre><span class="nb">dict</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mf">10000</span><span class="p">):</span>
   <span class="n">rand</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mf">0</span><span class="p">,</span><span class="mf">50000</span><span class="p">)</span>
   <span class="k">if</span> <span class="ow">not</span> <span class="nb">dict</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">rand</span><span class="p">):</span>
      <span class="nb">dict</span><span class="p">[</span><span class="n">rand</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0</span>
</pre>
</div>
</div>
<p>This example needs only 34908 microseconds. That is 10 times faster than the version with the list. It looks very stupid to program a line like “dict[rand] = 0?, but this solution now uses a different search algorithm. If you increment the loop up to 20000 entries the different is 83times.  But in the near of 30000 it comes to a point where the insort algorithm of the dict structure needs so long that the speed benefit is over. </p>
<p>I wrote another small program to visualize the effect.<br />
<a href="http://kai.system7.de/hashagainstlist/speedtest.py">See the code</a></p>
<p><img src="http://kai.system7.de/images/hashagainstlist.jpg" alt="Hash Against List" /></p>
<p>I found this problem in a small textminig project. Using dictionarys to search for existence of a word in an document was extremely faster than a list. So sometimes you should think about, when to use a list and when use a dictionary like an list. </p>
]]></content:encoded>
			<wfw:commentRss>http://kai.system7.de/2008/01/25/hashtable-vs-list/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

