Re[2]: [Haskell-cafe] mapping unfreeze over an IntMap of IOUArrays

Hello Max, Tuesday, November 11, 2008, 11:50:28 PM, you wrote: btw, i made here some time ago proposal about pure hashtables implented over a pure arrays (via accumArray operaion). may be it is somewhat helpful for you
using unsafeFreeze. I'm getting stuck here, since the IntMap library is not so monad-friendly.
Data.Hashtable is
Well, I need mutable update for a while... after that, I prefer a pure interface, which is why I'm trying to freeze all the values.
Is there any reason why an immutable Hashtable shouldn't be implemented, with a pure interface, such that hashtables can be (unsafe)Freezed into immutable hashtables? Would this be useful?
--Max
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

bulat.ziganshin:
Hello Max,
Tuesday, November 11, 2008, 11:50:28 PM, you wrote:
btw, i made here some time ago proposal about pure hashtables implented over a pure arrays (via accumArray operaion). may be it is somewhat helpful for you
Did you end up implementing this? -- Don

Hello Don, Wednesday, November 12, 2008, 12:51:33 AM, you wrote:
btw, i made here some time ago proposal about pure hashtables
Did you end up implementing this?
yes, i have published here all the 10 lines of implementation :))) citing letter to you: actually, writing HT module from scratch is very easy - all we need is a prime searching function (in order to establish array size). everything else: data HT a b = HT (a->Int) (Array Int [(a,b)]) -- size is the size of array (we implent closed hash) -- hash is the hash function (a->Int) -- list is assoclist of items to put in hash create size hash list = HT hashfunc (accumArray (flip (:)) [] (0, arrsize-1) (map (\(a,b) -> (hashfunc a,b)) list) ) where arrsize = head$ filter (>size)$ iterate (\x->3*x+1) 1 hashfunc a = hash a `mod` arrsize lookup a (HT hash arr) = List.lookup a (arr!hash a) example: main = do let assoclist = [("one", 1), ("two", 2), ("three", 3)] hash = HT.create 10 Data.HashTable.hashString assoclist print (HT.lookup "one" hash) print (HT.lookup "zero" hash) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

bulat.ziganshin:
Hello Don,
Wednesday, November 12, 2008, 12:51:33 AM, you wrote:
btw, i made here some time ago proposal about pure hashtables
Did you end up implementing this?
yes, i have published here all the 10 lines of implementation :)))
citing letter to you:
actually, writing HT module from scratch is very easy - all we need is a prime searching function (in order to establish array size). everything else:
data HT a b = HT (a->Int) (Array Int [(a,b)])
-- size is the size of array (we implent closed hash) -- hash is the hash function (a->Int) -- list is assoclist of items to put in hash create size hash list = HT hashfunc (accumArray (flip (:)) [] (0, arrsize-1) (map (\(a,b) -> (hashfunc a,b)) list) )
where arrsize = head$ filter (>size)$ iterate (\x->3*x+1) 1 hashfunc a = hash a `mod` arrsize
lookup a (HT hash arr) = List.lookup a (arr!hash a)
example:
main = do let assoclist = [("one", 1), ("two", 2), ("three", 3)] hash = HT.create 10 Data.HashTable.hashString assoclist print (HT.lookup "one" hash) print (HT.lookup "zero" hash)
If this structure is useful, you should release it on Hackage. You've not tested the performance though, I imagine, versus say, hasing into an IntMap? -- Don

Hello Don, Wednesday, November 12, 2008, 1:21:18 AM, you wrote:
If this structure is useful, you should release it on Hackage. You've not tested the performance though, I imagine, versus say, hasing into an IntMap?
you know that making all these things need a time. sorry, ATM i think that my compression projects makes more sense, so to the Haskell i'm just user -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (2)
-
Bulat Ziganshin
-
Don Stewart