Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data ByteArray = ByteArray ByteArray#
- data MutableByteArray s = MutableByteArray (MutableByteArray# s)
- data ByteArray# :: TYPE 'UnliftedRep
- data MutableByteArray# a :: TYPE 'UnliftedRep
- newByteArray :: (HasCallStack, PrimMonad m) => Int -> m (MutableByteArray (PrimState m))
- newPinnedByteArray :: (HasCallStack, PrimMonad m) => Int -> m (MutableByteArray (PrimState m))
- newAlignedPinnedByteArray :: (HasCallStack, PrimMonad m) => Int -> Int -> m (MutableByteArray (PrimState m))
- resizeMutableByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> m (MutableByteArray (PrimState m))
- shrinkMutableByteArray :: (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> m ()
- readByteArray :: forall m a. (HasCallStack, Prim a, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> m a
- writeByteArray :: forall m a. (HasCallStack, Prim a, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> a -> m ()
- indexByteArray :: forall a. (HasCallStack, Prim a) => ByteArray -> Int -> a
- emptyByteArray :: ByteArray
- byteArrayFromList :: Prim a => [a] -> ByteArray
- byteArrayFromListN :: Prim a => Int -> [a] -> ByteArray
- foldrByteArray :: Prim a => (a -> b -> b) -> b -> ByteArray -> b
- compareByteArrays :: ByteArray -> Int -> ByteArray -> Int -> Int -> Ordering
- freezeByteArray :: (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> Int -> m ByteArray
- thawByteArray :: (HasCallStack, PrimMonad m) => ByteArray -> Int -> Int -> m (MutableByteArray (PrimState m))
- runByteArray :: (forall s. ST s (MutableByteArray s)) -> ByteArray
- unsafeFreezeByteArray :: (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> m ByteArray
- unsafeThawByteArray :: PrimMonad m => ByteArray -> m (MutableByteArray (PrimState m))
- copyByteArray :: forall m. (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> ByteArray -> Int -> Int -> m ()
- copyMutableByteArray :: forall m. (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> MutableByteArray (PrimState m) -> Int -> Int -> m ()
- copyByteArrayToPtr :: forall m a. (HasCallStack, PrimMonad m, Prim a) => Ptr a -> ByteArray -> Int -> Int -> m ()
- copyMutableByteArrayToPtr :: forall m a. (HasCallStack, PrimMonad m, Prim a) => Ptr a -> MutableByteArray (PrimState m) -> Int -> Int -> m ()
- copyByteArrayToAddr :: (HasCallStack, PrimMonad m) => Ptr Word8 -> ByteArray -> Int -> Int -> m ()
- copyMutableByteArrayToAddr :: (HasCallStack, PrimMonad m) => Ptr Word8 -> MutableByteArray (PrimState m) -> Int -> Int -> m ()
- moveByteArray :: forall m. (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> MutableByteArray (PrimState m) -> Int -> Int -> m ()
- setByteArray :: forall m a. (HasCallStack, Prim a, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> Int -> a -> m ()
- fillByteArray :: (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> Int -> Word8 -> m ()
- cloneByteArray :: HasCallStack => ByteArray -> Int -> Int -> ByteArray
- cloneMutableByteArray :: (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> Int -> m (MutableByteArray (PrimState m))
- sizeofByteArray :: ByteArray -> Int
- sizeofMutableByteArray :: MutableByteArray s -> Int
- getSizeofMutableByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> m Int
- sameMutableByteArray :: MutableByteArray s -> MutableByteArray s -> Bool
- isByteArrayPinned :: ByteArray -> Bool
- isMutableByteArrayPinned :: MutableByteArray s -> Bool
- byteArrayContents :: ByteArray -> Ptr Word8
- mutableByteArrayContents :: MutableByteArray s -> Ptr Word8
Types
Byte arrays.
Instances
IsList ByteArray | Since: primitive-0.6.3.0 |
Eq ByteArray | Since: primitive-0.6.3.0 |
Data ByteArray | |
Defined in Data.Primitive.ByteArray gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ByteArray -> c ByteArray # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ByteArray # toConstr :: ByteArray -> Constr # dataTypeOf :: ByteArray -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ByteArray) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ByteArray) # gmapT :: (forall b. Data b => b -> b) -> ByteArray -> ByteArray # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ByteArray -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ByteArray -> r # gmapQ :: (forall d. Data d => d -> u) -> ByteArray -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ByteArray -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ByteArray -> m ByteArray # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteArray -> m ByteArray # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteArray -> m ByteArray # | |
Ord ByteArray | Non-lexicographic ordering. This compares the lengths of the byte arrays first and uses a lexicographic ordering if the lengths are equal. Subject to change between major versions. Since: primitive-0.6.3.0 |
Defined in Data.Primitive.ByteArray | |
Show ByteArray | Behavior changed in 0.7.2.0. Before 0.7.2.0, this instance rendered
8-bit words less than 16 as a single hexadecimal digit (e.g. 13 was Since: primitive-0.6.3.0 |
Semigroup ByteArray | |
Monoid ByteArray | |
NFData ByteArray | |
Defined in Data.Primitive.ByteArray | |
type Item ByteArray | |
Defined in Data.Primitive.ByteArray |
data MutableByteArray s #
Mutable byte arrays associated with a primitive state token.
Instances
Eq (MutableByteArray s) | |
Defined in Data.Primitive.ByteArray (==) :: MutableByteArray s -> MutableByteArray s -> Bool # (/=) :: MutableByteArray s -> MutableByteArray s -> Bool # | |
Typeable s => Data (MutableByteArray s) | |
Defined in Data.Primitive.ByteArray gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> MutableByteArray s -> c (MutableByteArray s) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (MutableByteArray s) # toConstr :: MutableByteArray s -> Constr # dataTypeOf :: MutableByteArray s -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (MutableByteArray s)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (MutableByteArray s)) # gmapT :: (forall b. Data b => b -> b) -> MutableByteArray s -> MutableByteArray s # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> MutableByteArray s -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> MutableByteArray s -> r # gmapQ :: (forall d. Data d => d -> u) -> MutableByteArray s -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> MutableByteArray s -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> MutableByteArray s -> m (MutableByteArray s) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> MutableByteArray s -> m (MutableByteArray s) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> MutableByteArray s -> m (MutableByteArray s) # | |
NFData (MutableByteArray s) | |
Defined in Data.Primitive.ByteArray rnf :: MutableByteArray s -> () # |
data ByteArray# :: TYPE 'UnliftedRep #
data MutableByteArray# a :: TYPE 'UnliftedRep #
Allocation
newByteArray :: (HasCallStack, PrimMonad m) => Int -> m (MutableByteArray (PrimState m)) Source #
newPinnedByteArray :: (HasCallStack, PrimMonad m) => Int -> m (MutableByteArray (PrimState m)) Source #
newAlignedPinnedByteArray :: (HasCallStack, PrimMonad m) => Int -> Int -> m (MutableByteArray (PrimState m)) Source #
resizeMutableByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> Int -> m (MutableByteArray (PrimState m)) Source #
After a call to resizeMutableByteArray
, the original reference to
the mutable array should not be used again. This cannot truly be enforced
except by linear types. To attempt to enforce this, we always make a
copy of the mutable primitive array and intentionally corrupt the original
of the original one. The strategy used here to corrupt the array is
simply to write 0xFF
to every byte.
shrinkMutableByteArray Source #
:: (HasCallStack, PrimMonad m) | |
=> MutableByteArray (PrimState m) | |
-> Int | new size |
-> m () |
Element access
readByteArray :: forall m a. (HasCallStack, Prim a, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> m a Source #
writeByteArray :: forall m a. (HasCallStack, Prim a, PrimMonad m) => MutableByteArray (PrimState m) -> Int -> a -> m () Source #
indexByteArray :: forall a. (HasCallStack, Prim a) => ByteArray -> Int -> a Source #
Constructing
The empty ByteArray
.
byteArrayFromList :: Prim a => [a] -> ByteArray #
Create a ByteArray
from a list.
byteArrayFromList xs = byteArrayFromListN
(length xs) xs
byteArrayFromListN :: Prim a => Int -> [a] -> ByteArray #
Create a ByteArray
from a list of a known length. If the length
of the list does not match the given length, this throws an exception.
Folding
foldrByteArray :: Prim a => (a -> b -> b) -> b -> ByteArray -> b #
Right-fold over the elements of a ByteArray
.
Comparing
Freezing and thawing
:: (HasCallStack, PrimMonad m) | |
=> MutableByteArray (PrimState m) | source |
-> Int | offset |
-> Int | length |
-> m ByteArray |
:: (HasCallStack, PrimMonad m) | |
=> ByteArray | source |
-> Int | offset |
-> Int | length |
-> m (MutableByteArray (PrimState m)) |
runByteArray :: (forall s. ST s (MutableByteArray s)) -> ByteArray #
Execute the monadic action and freeze the resulting array.
runByteArray m = runST $ m >>= unsafeFreezeByteArray
unsafeFreezeByteArray :: (HasCallStack, PrimMonad m) => MutableByteArray (PrimState m) -> m ByteArray Source #
This corrupts the contents of the argument array by writing 0xFF
to every byte.
unsafeThawByteArray :: PrimMonad m => ByteArray -> m (MutableByteArray (PrimState m)) #
Convert an immutable byte array to a mutable one without copying. The original array should not be used after the conversion.
Block operations
:: forall m. (HasCallStack, PrimMonad m) | |
=> MutableByteArray (PrimState m) | destination array |
-> Int | offset into destination array |
-> ByteArray | source array |
-> Int | offset into source array |
-> Int | number of elements to copy |
-> m () |
:: forall m. (HasCallStack, PrimMonad m) | |
=> MutableByteArray (PrimState m) | destination array |
-> Int | offset into destination array |
-> MutableByteArray (PrimState m) | source array |
-> Int | offset into source array |
-> Int | number of elements to copy |
-> m () |
copyMutableByteArrayToPtr Source #
:: forall m a. (HasCallStack, PrimMonad m, Prim a) | |
=> Ptr a | destination pointer |
-> MutableByteArray (PrimState m) | source array |
-> Int | offset into source array |
-> Int | number of elements to copy |
-> m () |
copyMutableByteArrayToAddr Source #
:: (HasCallStack, PrimMonad m) | |
=> Ptr Word8 | destination pointer |
-> MutableByteArray (PrimState m) | source array |
-> Int | offset into source array |
-> Int | number of bytes to copy |
-> m () |
:: forall m. (HasCallStack, PrimMonad m) | |
=> MutableByteArray (PrimState m) | destination array |
-> Int | offset into destination array |
-> MutableByteArray (PrimState m) | source array |
-> Int | offset into source array |
-> Int | number of bytes to copy |
-> m () |
:: forall m a. (HasCallStack, Prim a, PrimMonad m) | |
=> MutableByteArray (PrimState m) | array to fill |
-> Int | offset into array |
-> Int | number of values to fill |
-> a | value to fill with |
-> m () |
:: (HasCallStack, PrimMonad m) | |
=> MutableByteArray (PrimState m) | array to fill |
-> Int | offset into array |
-> Int | number of bytes to fill |
-> Word8 | byte to fill with |
-> m () |
:: HasCallStack | |
=> ByteArray | source array |
-> Int | offset into source array |
-> Int | number of bytes to copy |
-> ByteArray |
cloneMutableByteArray Source #
:: (HasCallStack, PrimMonad m) | |
=> MutableByteArray (PrimState m) | source array |
-> Int | offset into source array |
-> Int | number of bytes to copy |
-> m (MutableByteArray (PrimState m)) |
Information
sizeofByteArray :: ByteArray -> Int #
Size of the byte array in bytes.
sizeofMutableByteArray :: MutableByteArray s -> Int #
Size of the mutable byte array in bytes. This function's behavior
is undefined if resizeMutableByteArray
is ever called on the mutable
byte array given as the argument. Consequently, use of this function
is discouraged. Prefer getSizeofMutableByteArray
, which ensures correct
sequencing in the presence of resizing.
getSizeofMutableByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> m Int #
Get the size of a byte array in bytes. Unlike sizeofMutableByteArray
,
this function ensures sequencing in the presence of resizing.
sameMutableByteArray :: MutableByteArray s -> MutableByteArray s -> Bool #
Check if the two arrays refer to the same memory block.
isByteArrayPinned :: ByteArray -> Bool #
Check whether or not the byte array is pinned. Pinned byte arrays cannot
be moved by the garbage collector. It is safe to use byteArrayContents
on such byte arrays. This function is only available when compiling with
GHC 8.2 or newer.
Since: primitive-0.6.4.0
isMutableByteArrayPinned :: MutableByteArray s -> Bool #
Check whether or not the mutable byte array is pinned. This function is only available when compiling with GHC 8.2 or newer.
Since: primitive-0.6.4.0
byteArrayContents :: ByteArray -> Ptr Word8 #
Yield a pointer to the array's data. This operation is only safe on
pinned byte arrays allocated by newPinnedByteArray
or
newAlignedPinnedByteArray
.
mutableByteArrayContents :: MutableByteArray s -> Ptr Word8 #
Yield a pointer to the array's data. This operation is only safe on
pinned byte arrays allocated by newPinnedByteArray
or
newAlignedPinnedByteArray
.