module Data.Array.BitArray.ST
( STBitArray()
, getBounds
, newArray
, newArray_
, newListArray
, readArray
, writeArray
, mapArray
, mapIndices
, getElems
, getAssocs
, freeze
, thaw
, copy
, fill
, or
, and
, isUniform
, elemIndex
, fold
, map
, zipWith
, popCount
, unsafeReadArray
, unsafeGetElems
, unsafeFreeze
, unsafeThaw
) where
import Prelude hiding (and, or, map, zipWith)
import Control.Monad.ST (ST)
import Data.Ix (Ix)
import Control.Monad.ST.Unsafe (unsafeIOToST)
import Data.Array.BitArray.Internal (BitArray)
import Data.Array.BitArray.IO (IOBitArray)
import qualified Data.Array.BitArray.IO as IO
newtype STBitArray s i = STB (IOBitArray i)
{-# INLINE getBounds #-}
getBounds :: Ix i => STBitArray s i -> ST s (i, i)
getBounds (STB a) = unsafeIOToST (IO.getBounds a)
{-# INLINE newArray #-}
newArray :: Ix i => (i, i) -> Bool -> ST s (STBitArray s i)
newArray bs b = STB `fmap` unsafeIOToST (IO.newArray bs b)
{-# INLINE newArray_ #-}
newArray_ :: Ix i => (i, i) -> ST s (STBitArray s i)
newArray_ bs = STB `fmap` unsafeIOToST (IO.newArray bs False)
{-# INLINE newListArray #-}
newListArray :: Ix i => (i, i) -> [Bool] -> ST s (STBitArray s i)
newListArray bs es = STB `fmap` unsafeIOToST (IO.newListArray bs es)
{-# INLINE readArray #-}
readArray :: Ix i => STBitArray s i -> i -> ST s Bool
readArray (STB a) i = unsafeIOToST (IO.readArray a i)
{-# INLINE unsafeReadArray #-}
unsafeReadArray :: Ix i => STBitArray s i -> i -> ST s Bool
unsafeReadArray (STB a) i = unsafeIOToST (IO.unsafeReadArray a i)
{-# INLINE writeArray #-}
writeArray :: Ix i => STBitArray s i -> i -> Bool -> ST s ()
writeArray (STB a) i b = unsafeIOToST (IO.writeArray a i b)
{-# INLINE mapArray #-}
mapArray :: Ix i => (Bool -> Bool) -> STBitArray s i -> ST s (STBitArray s i)
mapArray = map
{-# INLINE mapIndices #-}
mapIndices :: (Ix i, Ix j) => (i, i) -> (i -> j) -> STBitArray s j -> ST s (STBitArray s i)
mapIndices bs h (STB a) = STB `fmap` unsafeIOToST (IO.mapIndices bs h a)
{-# INLINE getElems #-}
getElems :: Ix i => STBitArray s i -> ST s [Bool]
getElems (STB a) = unsafeIOToST (IO.getElems a)
{-# INLINE unsafeGetElems #-}
unsafeGetElems :: Ix i => STBitArray s i -> ST s [Bool]
unsafeGetElems (STB a) = unsafeIOToST (IO.unsafeGetElems a)
{-# INLINE getAssocs #-}
getAssocs :: Ix i => STBitArray s i -> ST s [(i, Bool)]
getAssocs (STB a) = unsafeIOToST (IO.getAssocs a)
{-# INLINE freeze #-}
freeze :: Ix i => STBitArray s i -> ST s (BitArray i)
freeze (STB a) = unsafeIOToST (IO.freeze a)
{-# INLINE unsafeFreeze #-}
unsafeFreeze :: Ix i => STBitArray s i -> ST s (BitArray i)
unsafeFreeze (STB a) = unsafeIOToST (IO.unsafeFreeze a)
{-# INLINE thaw #-}
thaw :: Ix i => BitArray i -> ST s (STBitArray s i)
thaw a = STB `fmap` unsafeIOToST (IO.thaw a)
{-# INLINE unsafeThaw #-}
unsafeThaw :: Ix i => BitArray i -> ST s (STBitArray s i)
unsafeThaw a = STB `fmap` unsafeIOToST (IO.unsafeThaw a)
{-# INLINE copy #-}
copy :: Ix i => STBitArray s i -> ST s (STBitArray s i)
copy (STB a) = STB `fmap` unsafeIOToST (IO.copy a)
{-# INLINE fill #-}
fill :: Ix i => STBitArray s i -> Bool -> ST s ()
fill (STB a) b = unsafeIOToST (IO.fill a b)
{-# INLINE or #-}
or :: Ix i => STBitArray s i -> ST s Bool
or (STB a) = unsafeIOToST (IO.or a)
{-# INLINE and #-}
and :: Ix i => STBitArray s i -> ST s Bool
and (STB a) = unsafeIOToST (IO.and a)
{-# INLINE isUniform #-}
isUniform :: Ix i => STBitArray s i -> ST s (Maybe Bool)
isUniform (STB a) = unsafeIOToST (IO.isUniform a)
{-# INLINE elemIndex #-}
elemIndex :: Bool -> STBitArray s Int -> ST s (Maybe Int)
elemIndex b (STB a) = unsafeIOToST (IO.elemIndex b a)
{-# INLINE fold #-}
fold :: Ix i => (Bool -> Bool -> Bool) -> STBitArray s i -> ST s (Maybe Bool)
fold f (STB a) = unsafeIOToST (IO.fold f a)
{-# INLINE map #-}
map :: Ix i => (Bool -> Bool) -> STBitArray s i -> ST s (STBitArray s i)
map f (STB a) = STB `fmap` unsafeIOToST (IO.map f a)
{-# INLINE zipWith #-}
zipWith :: Ix i => (Bool -> Bool -> Bool) -> STBitArray s i -> STBitArray s i -> ST s (STBitArray s i)
zipWith f (STB a) (STB b) = STB `fmap` unsafeIOToST (IO.zipWith f a b)
{-# INLINE popCount #-}
popCount :: Ix i => STBitArray s i -> ST s Int
popCount (STB a) = unsafeIOToST (IO.popCount a)