Add unsafeFromForeignPtr0 and unsafeToForeignPtr0 to Data.Vector.Storable.Mutable
[darcs-mirrors/vector.git] / benchmarks / Algo / ListRank.hs
1 module Algo.ListRank
2 where
3
4 import Data.Vector.Unboxed as V
5
6 listRank :: Int -> Vector Int
7 {-# NOINLINE listRank #-}
8 listRank n = pointer_jump xs val
9 where
10 xs = 0 `V.cons` V.enumFromTo 0 (n-2)
11
12 val = V.zipWith (\i j -> if i == j then 0 else 1)
13 xs (V.enumFromTo 0 (n-1))
14
15 pointer_jump pt val
16 | npt == pt = val
17 | otherwise = pointer_jump npt nval
18 where
19 npt = V.backpermute pt pt
20 nval = V.zipWith (+) val (V.backpermute val pt)
21