Add unsafeFromForeignPtr0 and unsafeToForeignPtr0 to Data.Vector.Storable.Mutable
[darcs-mirrors/vector.git] / benchmarks / Algo / AwShCC.hs
1 {-# OPTIONS -fno-spec-constr-count #-}
2 module Algo.AwShCC (awshcc) where
3
4 import Data.Vector.Unboxed as V
5
6 awshcc :: (Int, Vector Int, Vector Int) -> Vector Int
7 {-# NOINLINE awshcc #-}
8 awshcc (n, es1, es2) = concomp ds es1' es2'
9 where
10 ds = V.enumFromTo 0 (n-1) V.++ V.enumFromTo 0 (n-1)
11 es1' = es1 V.++ es2
12 es2' = es2 V.++ es1
13
14 starCheck ds = V.backpermute st' gs
15 where
16 gs = V.backpermute ds ds
17 st = V.zipWith (==) ds gs
18 st' = V.update st . V.filter (not . snd)
19 $ V.zip gs st
20
21 concomp ds es1 es2
22 | V.and (starCheck ds'') = ds''
23 | otherwise = concomp (V.backpermute ds'' ds'') es1 es2
24 where
25 ds' = V.update ds
26 . V.map (\(di, dj, gi) -> (di, dj))
27 . V.filter (\(di, dj, gi) -> gi == di && di > dj)
28 $ V.zip3 (V.backpermute ds es1)
29 (V.backpermute ds es2)
30 (V.backpermute ds (V.backpermute ds es1))
31
32 ds'' = V.update ds'
33 . V.map (\(di, dj, st) -> (di, dj))
34 . V.filter (\(di, dj, st) -> st && di /= dj)
35 $ V.zip3 (V.backpermute ds' es1)
36 (V.backpermute ds' es2)
37 (V.backpermute (starCheck ds') es1)
38