
Hi Bulat,
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.
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.
Thanks, everyone, for the help.
Michael
--- On Tue, 11/17/09, Bulat Ziganshin
[("miguel",3),("michael",2),("mike",1)]
It seems my dummy function is being ignored.
i wonder why you think so? your ht has all 3 pairs you ever inserted inside, they all are inside the same bucket since hash function returns the same value for them ... hmm, i guess that you expect something like low-level hashtable from other languages - i.e. it should have just one slot for all values hashed to 7 and save here last value it works other way - it has just one slot for all your values but it stores here LIST of your pairs. so nothing is lost. if you want to save only the last value, replace (==) to (\a b -> dummy a==dummy b) the whole story is that hash function used to select slot, and then key part of pair is compared using (==) with keys of all values in the slot. it will replace existing pair if key1==key2, otherwise added to list so, hashing allows to quickly find pair by its key, but it still full map as far as you pass a usual (==) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com