Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallel hashmap in haskell

There is an implementation of HashMap, in Haskell, but I can't find parallel version of it. It's necessary to solve problem below.

Say, I have two hashmaps HashMap a b, I want to union it with condition, Now I use unionWith function, but the problem is that equivalence of my a keys is very long procedure (it's a graphs). So I'd like to perform it in parallel. How can I do it?

like image 410
Sergey Sosnin Avatar asked Nov 12 '22 19:11

Sergey Sosnin


1 Answers

You could create a newtype around HashMap, then define a new Eq instance that is as parallel as you like using Control.Parallel. Unfortunately you'll have to write all that code yourself, I don't think there is any out of the box parallel implementations.

import Control.Parallel

newtype ParHashMap k v = ParHashMap { unPar :: HashMap k v }

instance (Eq k, Eq v) => Eq (ParHashMap k v) where
    ParHashMap hm1 == ParHashMap hm2 = ...

I'm not sure which HashMap you're using (I recommend unordered-containers), so I can't write the Eq instance, but it should be fairly simple to evaluate the equality of each node in parallel.

like image 165
cdk Avatar answered Nov 14 '22 08:11

cdk