<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi Bulat,<br><br>I was just looking for a simple hashing function. I was going to use the length function but a constant int is even simpler. I'm supposing that had I used the length function "mike" and "fred" would end up in the same bucket.<br><br>This is the first time I've tried to do anything in Haskell with data structures other than lists, so I needed to see how things work.<br><br>Thanks, everyone, for the help.<br><br>Michael<br><br>--- On <b>Tue, 11/17/09, Bulat Ziganshin <i><firstname.lastname@example.org></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Bulat Ziganshin <email@example.com><br>Subject: Re: [Haskell-cafe] Simple hash table creation<br>To: "michael rice" <firstname.lastname@example.org><br>Cc: "Gregory Crosswhite"
<email@example.com>, firstname.lastname@example.org<br>Date: Tuesday, November 17, 2009, 4:38 PM<br><br><div class="plainMail">Hello michael,<br><br>Wednesday, November 18, 2009, 12:00:58 AM, you wrote:<br><br>*Main>> toList ht<br>> [("miguel",3),("michael",2),("mike",1)] <br>><br>> It seems my dummy function is being ignored.<br><br>i wonder why you think so?<br><br>your ht has all 3 pairs you ever inserted<br><br>inside, they all are inside the same bucket since hash function<br>returns the same value for them<br><br>... hmm, i guess that you expect something like low-level hashtable<br>from other languages - i.e. it should have just one slot for all<br>values hashed to 7 and save here last value<br><br>it works other way - it has just one slot for all your values but it<br>stores here LIST of your pairs. so nothing is lost. if you want to<br>save only the last value, replace (==) to (\a b -> dummy a==dummy b)<br><br>the
whole story is that hash function used to select slot, and then<br>key part of pair is compared using (==) with keys of all values in the<br>slot. it will replace existing pair if key1==key2, otherwise added to<br>list<br><br>so, hashing allows to quickly find pair by its key, but it still full<br>map as far as you pass a usual (==)<br><br>-- <br>Best regards,<br> Bulat mailto:<a ymailto="mailto:Bulat.Ziganshin@gmail.com" href="/mc/compose?to=Bulat.Ziganshin@gmail.com">Bulat.Ziganshin@gmail.com</a><br><br></div></blockquote></td></tr></table><br>