[Haskell-cafe] Maximum bipartite matching: 24 lines

2012-10-22 Thread Stefan Klinger
Hello. I have written a function that calculates maximum cardinality matchings on bipartite graphs. It's only 24 lines of code. It seems (tested, not proven) to run faster, use less memory, and scale better than using MaxFlow from FGL with constant weight and additional source and sink nodes. B

Re: [Haskell-cafe] Maximum bipartite matching: 24 lines

2012-10-22 Thread Eugene Kirpichov
Hi, fwd = foldr (\(x,y) -> M.insertWith (++) x [y]) M.empty $ S.toList g Use foldl' here, foldr is absolutely useless here and it only consumes the stack space as your operation is strict. As for the actual code: I'd prefer the code itself to be more readable, rather than have a lot of liter

Re: [Haskell-cafe] Maximum bipartite matching: 24 lines

2012-10-24 Thread Stefan Klinger
On 2012-Oct-22 14:23 (-0700), Eugene Kirpichov wrote with possible deletions: > > fwd = foldr (\(x,y) -> M.insertWith (++) x [y]) M.empty $ S.toList g > > Use foldl' here, foldr is absolutely useless here and it only consumes > the stack space as your operation is strict. Thank you very much

Re: [Haskell-cafe] Maximum bipartite matching: 24 lines

2012-10-29 Thread Dmitry Olshansky
I didn't analyze it but anytime I see "M.insertWith" I am just in doubt - do you know about a strict version M.insertWith' ? 2012/10/24 Stefan Klinger > On 2012-Oct-22 14:23 (-0700), Eugene Kirpichov wrote with possible > deletions: > > > > fwd = foldr (\(x,y) -> M.insertWith (++) x [y]) M.e