basement-0.0.2: Foundation scrap box of array & string

LicenseBSD-style
MaintainerHaskell Foundation
Safe HaskellNone
LanguageHaskell2010

Basement.Block

Contents

Description

A block of memory that contains elements of a type, very similar to an unboxed array but with the key difference:

  • It doesn't have slicing capability (no cheap take or drop)
  • It consume less memory: 1 Offset, 1 CountOf
  • It's unpackable in any constructor
  • It uses unpinned memory by default

Synopsis

Documentation

data Block ty Source #

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

Constructors

Block ByteArray# 

Instances

PrimType ty => IsList (Block ty) Source # 

Associated Types

type Item (Block ty) :: * #

Methods

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

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

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

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

Methods

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

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

Data ty => Data (Block ty) Source # 

Methods

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

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

toConstr :: Block ty -> Constr #

dataTypeOf :: Block ty -> DataType #

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

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

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

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

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

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

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

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

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

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

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

Methods

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

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

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

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

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

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

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

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

Methods

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

show :: Block ty -> String #

showList :: [Block ty] -> ShowS #

PrimType ty => Monoid (Block ty) Source # 

Methods

mempty :: Block ty #

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

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

NormalForm (Block ty) Source # 

Methods

toNormalForm :: Block ty -> () Source #

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

Methods

from :: Block ty -> UArray ty Source #

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

Methods

from :: UArray ty -> Block ty Source #

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

Methods

from :: Array ty -> Block ty Source #

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

Methods

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

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

Methods

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

type Item (Block ty) Source # 
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) 

Properties

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

Lowlevel functions

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.

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.

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

Thaw a Block into a MutableBlock

the Block is not modified, instead a new Mutable Block is created and its content is copied to the mutable block

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

copy :: PrimType ty => Block ty -> Block ty Source #

Copy every cells of an existing Block to a new Block

safer api

create Source #

Arguments

:: PrimType ty 
=> CountOf ty

the size of the block (in element of ty)

-> (Offset ty -> ty)

the function that set the value at the index

-> Block ty

the array created

Create a new array of size n by settings each cells through the function f.

singleton :: PrimType ty => ty -> Block ty Source #

replicate :: PrimType ty => CountOf ty -> ty -> Block ty Source #

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

Return the element at a specific index from an array.

If the index @n is out of bounds, an error is raised.

map :: (PrimType a, PrimType b) => (a -> b) -> Block a -> Block b Source #

Map all element a from a block to a new block of b

foldl' :: PrimType ty => (a -> ty -> a) -> a -> Block ty -> a Source #

foldr :: PrimType ty => (ty -> a -> a) -> a -> Block ty -> a Source #

foldl1' :: PrimType ty => (ty -> ty -> ty) -> NonEmpty (Block ty) -> ty Source #

foldr1 :: PrimType ty => (ty -> ty -> ty) -> NonEmpty (Block ty) -> ty Source #

cons :: PrimType ty => ty -> Block ty -> Block ty Source #

snoc :: PrimType ty => Block ty -> ty -> Block ty Source #

uncons :: PrimType ty => Block ty -> Maybe (ty, Block ty) Source #

unsnoc :: PrimType ty => Block ty -> Maybe (Block ty, ty) Source #

sub :: PrimType ty => Block ty -> Offset ty -> Offset ty -> Block ty Source #

splitAt :: PrimType ty => CountOf ty -> Block ty -> (Block ty, Block ty) Source #

revSplitAt :: PrimType ty => CountOf ty -> Block ty -> (Block ty, Block ty) Source #

splitOn :: PrimType ty => (ty -> Bool) -> Block ty -> [Block ty] Source #

break :: PrimType ty => (ty -> Bool) -> Block ty -> (Block ty, Block ty) Source #

breakEnd :: PrimType ty => (ty -> Bool) -> Block ty -> (Block ty, Block ty) Source #

span :: PrimType ty => (ty -> Bool) -> Block ty -> (Block ty, Block ty) Source #

elem :: PrimType ty => ty -> Block ty -> Bool Source #

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

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

find :: PrimType ty => (ty -> Bool) -> Block ty -> Maybe ty Source #

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

reverse :: forall ty. PrimType ty => Block ty -> Block ty Source #

sortBy :: PrimType ty => (ty -> ty -> Ordering) -> Block ty -> Block ty Source #

intersperse :: forall ty. PrimType ty => ty -> Block ty -> Block ty Source #

Foreign interfaces

unsafeCopyToPtr Source #

Arguments

:: PrimMonad prim 
=> Block ty

the source block to copy

-> Ptr ty

The destination address where the copy is going to start

-> prim () 

Copy all the block content to the memory starting at the destination address