Add unsafeFromForeignPtr0 and unsafeToForeignPtr0 to Data.Vector.Storable.Mutable
[darcs-mirrors/vector.git] / benchmarks / Algo / Leaffix.hs
1 module Algo.Leaffix where
2
3 import Data.Vector.Unboxed as V
4
5 leaffix :: (Vector Int, Vector Int) -> Vector Int
6 {-# NOINLINE leaffix #-}
7 leaffix (ls,rs)
8 = leaffix (V.replicate (V.length ls) 1) ls rs
9 where
10 leaffix xs ls rs
11 = let zs = V.replicate (V.length ls * 2) 0
12 vs = V.update_ zs ls xs
13 sums = V.prescanl' (+) 0 vs
14 in
15 V.zipWith (-) (V.backpermute sums ls) (V.backpermute sums rs)
16