basement-0.0.12: Foundation scrap box of array & string
Safe HaskellNone
LanguageHaskell2010

Basement.Block.Base

Synopsis

Documentation

data Block ty Source #

A block of memory containing unpacked bytes representing values of type ty

Constructors

Block ByteArray# 

Instances

Instances details
PrimType ty => IsList (Block ty) Source # 
Instance details

Defined in Basement.Block.Base

Associated Types

type Item (Block ty) Source #

Methods

fromList :: [Item (Block ty)] -> Block ty Source #

fromListN :: Int -> [Item (Block ty)] -> Block ty Source #

toList :: Block ty -> [Item (Block ty)] Source #

(PrimType ty, Eq ty) => Eq (Block ty) Source # 
Instance details

Defined in Basement.Block.Base

Methods

(==) :: Block ty -> Block ty -> Bool Source #

(/=) :: Block ty -> Block ty -> Bool Source #

Data ty => Data (Block ty) Source # 
Instance details

Defined in Basement.Block.Base

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Block ty -> c (Block ty) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Block ty) Source #

toConstr :: Block ty -> Constr Source #

dataTypeOf :: Block ty -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Block ty)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Block ty)) Source #

gmapT :: (forall b. Data b => b -> b) -> Block ty -> Block ty Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Block ty -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Block ty -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Block ty -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Block ty -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Block ty -> m (Block ty) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Block ty -> m (Block ty) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Block ty -> m (Block ty) Source #

(PrimType ty, Ord ty) => Ord (Block ty) Source # 
Instance details

Defined in Basement.Block.Base

Methods

compare :: Block ty -> Block ty -> Ordering Source #

(<) :: Block ty -> Block ty -> Bool Source #

(<=) :: Block ty -> Block ty -> Bool Source #

(>) :: Block ty -> Block ty -> Bool Source #

(>=) :: Block ty -> Block ty -> Bool Source #

max :: Block ty -> Block ty -> Block ty Source #

min :: Block ty -> Block ty -> Block ty Source #

(PrimType ty, Show ty) => Show (Block ty) Source # 
Instance details

Defined in Basement.Block.Base

Methods

showsPrec :: Int -> Block ty -> ShowS Source #

show :: Block ty -> String Source #

showList :: [Block ty] -> ShowS Source #

PrimType ty => Semigroup (Block ty) Source # 
Instance details

Defined in Basement.Block.Base

Methods

(<>) :: Block ty -> Block ty -> Block ty Source #

sconcat :: NonEmpty (Block ty) -> Block ty Source #

stimes :: Integral b => b -> Block ty -> Block ty Source #

PrimType ty => Monoid (Block ty) Source # 
Instance details

Defined in Basement.Block.Base

Methods

mempty :: Block ty Source #

mappend :: Block ty -> Block ty -> Block ty Source #

mconcat :: [Block ty] -> Block ty Source #

NormalForm (Block ty) Source # 
Instance details

Defined in Basement.Block.Base

Methods

toNormalForm :: Block ty -> () Source #

Indexable (Block Word8) Word64 Source # 
Instance details

Defined in Basement.Block

PrimType ty => Indexable (Block ty) ty Source # 
Instance details

Defined in Basement.Block

Methods

index :: Block ty -> Offset ty -> ty Source #

Cast (Block a) (Block Word8) Source # 
Instance details

Defined in Basement.Cast

Methods

cast :: Block a -> Block Word8 Source #

PrimType ty => From (Block ty) (UArray ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: Block ty -> UArray ty Source #

PrimType ty => From (UArray ty) (Block ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: UArray ty -> Block ty Source #

PrimType ty => From (Array ty) (Block ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: Array ty -> Block ty Source #

(NatWithinBound (CountOf ty) n, KnownNat n, PrimType ty) => TryFrom (Block ty) (BlockN n ty) Source # 
Instance details

Defined in Basement.From

Methods

tryFrom :: Block ty -> Maybe (BlockN n ty) Source #

From (BlockN n ty) (Block ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: BlockN n ty -> Block ty Source #

type Item (Block ty) Source # 
Instance details

Defined in Basement.Block.Base

type Item (Block ty) = ty

data MutableBlock ty st Source #

A Mutable block of memory containing unpacked bytes representing values of type ty

Constructors

MutableBlock (MutableByteArray# st) 

Instances

Instances details
(PrimMonad prim, st ~ PrimState prim, PrimType ty) => RandomAccess (MutableBlock ty st) prim ty Source # 
Instance details

Defined in Basement.Block

Methods

read :: MutableBlock ty st -> Offset ty -> prim ty Source #

write :: MutableBlock ty st -> Offset ty -> ty -> prim () Source #

Basic accessor

unsafeNew :: PrimMonad prim => PinnedStatus -> CountOf Word8 -> prim (MutableBlock ty (PrimState prim)) Source #

Create a new mutable block of a specific size in bytes.

Note that no checks are made to see if the size in bytes is compatible with the size of the underlaying element ty in the block.

use new if unsure

unsafeThaw :: (PrimType ty, PrimMonad prim) => Block ty -> prim (MutableBlock ty (PrimState prim)) Source #

Thaw an immutable block.

If the immutable block is modified, then the original immutable block will be modified too, but lead to unexpected results when querying

unsafeFreeze :: PrimMonad prim => MutableBlock ty (PrimState prim) -> prim (Block ty) Source #

Freeze a mutable block into a block.

If the mutable block is still use after freeze, then the modification will be reflected in an unexpected way in the Block.

unsafeShrink :: PrimMonad prim => MutableBlock ty (PrimState prim) -> CountOf ty -> prim (MutableBlock ty (PrimState prim)) Source #

unsafeCopyElements Source #

Arguments

:: forall prim ty. (PrimMonad prim, PrimType ty) 
=> MutableBlock ty (PrimState prim)

destination mutable block

-> Offset ty

offset at destination

-> MutableBlock ty (PrimState prim)

source mutable block

-> Offset ty

offset at source

-> CountOf ty

number of elements to copy

-> prim () 

Copy a number of elements from an array to another array with offsets

unsafeCopyElementsRO Source #

Arguments

:: forall prim ty. (PrimMonad prim, PrimType ty) 
=> MutableBlock ty (PrimState prim)

destination mutable block

-> Offset ty

offset at destination

-> Block ty

source block

-> Offset ty

offset at source

-> CountOf ty

number of elements to copy

-> prim () 

unsafeCopyBytes Source #

Arguments

:: forall prim ty. PrimMonad prim 
=> MutableBlock ty (PrimState prim)

destination mutable block

-> Offset Word8

offset at destination

-> MutableBlock ty (PrimState prim)

source mutable block

-> Offset Word8

offset at source

-> CountOf Word8

number of elements to copy

-> prim () 

Copy a number of bytes from a MutableBlock to another MutableBlock with specific byte offsets

unsafeCopyBytesRO Source #

Arguments

:: forall prim ty. PrimMonad prim 
=> MutableBlock ty (PrimState prim)

destination mutable block

-> Offset Word8

offset at destination

-> Block ty

source block

-> Offset Word8

offset at source

-> CountOf Word8

number of elements to copy

-> prim () 

Copy a number of bytes from a Block to a MutableBlock with specific byte offsets

unsafeCopyBytesPtr Source #

Arguments

:: forall prim ty. PrimMonad prim 
=> MutableBlock ty (PrimState prim)

destination mutable block

-> Offset Word8

offset at destination

-> Ptr ty

source block

-> CountOf Word8

number of bytes to copy

-> prim () 

Copy a number of bytes from a Ptr to a MutableBlock with specific byte offsets

unsafeRead :: (PrimMonad prim, PrimType ty) => MutableBlock ty (PrimState prim) -> Offset ty -> prim ty Source #

read from a cell in a mutable block without bounds checking.

Reading from invalid memory can return unpredictable and invalid values. use read if unsure.

unsafeWrite :: (PrimMonad prim, PrimType ty) => MutableBlock ty (PrimState prim) -> Offset ty -> ty -> prim () Source #

write to a cell in a mutable block without bounds checking.

Writing with invalid bounds will corrupt memory and your program will become unreliable. use write if unsure.

unsafeIndex :: forall ty. PrimType ty => Block ty -> Offset ty -> ty Source #

Return the element at a specific index from an array without bounds checking.

Reading from invalid memory can return unpredictable and invalid values. use index if unsure.

Properties

length :: forall ty. PrimType ty => Block ty -> CountOf ty Source #

mutableLength :: forall ty st. PrimType ty => MutableBlock ty st -> CountOf ty Source #

Return the length of a Mutable Block

note: we don't allow resizing yet, so this can remain a pure function

Other methods

empty :: Block ty Source #

Create an empty block of memory

mutableEmpty :: PrimMonad prim => prim (MutableBlock ty (PrimState prim)) Source #

new :: forall prim ty. (PrimMonad prim, PrimType ty) => CountOf ty -> prim (MutableBlock ty (PrimState prim)) Source #

Create a new unpinned mutable block of a specific N size of ty elements

If the size exceeds a GHC-defined threshold, then the memory will be pinned. To be certain about pinning status with small size, use newPinned

newPinned :: forall prim ty. (PrimMonad prim, PrimType ty) => CountOf ty -> prim (MutableBlock ty (PrimState prim)) Source #

Create a new pinned mutable block of a specific N size of ty elements

withPtr :: PrimMonad prim => Block ty -> (Ptr ty -> prim a) -> prim a Source #

Get a Ptr pointing to the data in the Block.

Since a Block is immutable, this Ptr shouldn't be to use to modify the contents

If the Block is pinned, then its address is returned as is, however if it's unpinned, a pinned copy of the Block is made before getting the address.

withMutablePtr :: PrimMonad prim => MutableBlock ty (PrimState prim) -> (Ptr ty -> prim a) -> prim a Source #

Create a pointer on the beginning of the MutableBlock and call a function f.

The mutable block can be mutated by the f function and the change will be reflected in the mutable block

If the mutable block is unpinned, a trampoline buffer is created and the data is only copied when f return.

it is all-in-all highly inefficient as this cause 2 copies

withMutablePtrHint Source #

Arguments

:: forall ty prim a. PrimMonad prim 
=> Bool

hint that the buffer doesn't need to have the same value as the mutable block when calling f

-> Bool

hint that the buffer is not supposed to be modified by call of f

-> MutableBlock ty (PrimState prim) 
-> (Ptr ty -> prim a) 
-> prim a 

Same as withMutablePtr but allow to specify 2 optimisations which is only useful when the MutableBlock is unpinned and need a pinned trampoline to be called safely.

If skipCopy is True, then the first copy which happen before the call to f, is skipped. The Ptr is now effectively pointing to uninitialized data in a new mutable Block.

If skipCopyBack is True, then the second copy which happen after the call to f, is skipped. Then effectively in the case of a trampoline being used the memory changed by f will not be reflected in the original Mutable Block.

If using the wrong parameters, it will lead to difficult to debug issue of corrupted buffer which only present themselves with certain Mutable Block that happened to have been allocated unpinned.

If unsure use withMutablePtr, which default to *not* skip any copy.

mutableWithPtr :: PrimMonad prim => MutableBlock ty (PrimState prim) -> (Ptr ty -> prim a) -> prim a Source #

Deprecated: use withMutablePtr

Use the Ptr to a mutable block in a safer construct

If the block is not pinned, this is a _dangerous_ operation