Andrew Coppin wrote:
copy :: Word32 -> IOUArray Word32 Bool -> Word32 -> IO (IOUArray
Word32 Bool)
copy p grid size = do
let size' = size * p
grid' <- newArray (1,size') False
mapM_
(\n -> do
b <- readArray grid n
if b
then mapM_ (\x -> writeArray grid' (n + size*x) True) [0..p-1]
else return ()
)
[1..size]
return grid'
Actually, thinking about this... for most kinds of arrays (whether boxed
or unboxed, mutable or immutable) there's probably a more efficient way
to copy the data then this. Maybe we should add something to the various
array APIs to allow efficient copying of arrays / large chunks of arrays?
(In the case of an unboxed array of bits, you can probably copy whole
32-bit or 64-bit words with a few machine instructions, for example.)
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe