basement-0.0.16: Foundation scrap box of array & string

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Basement.BoxedArray

Description

Simple boxed array abstraction

Synopsis

- data Array a
- data MArray a st
- empty :: Array a
- length :: Array a -> CountOf a
- mutableLength :: MArray ty st -> Int
- copy :: Array ty -> Array ty
- unsafeCopyAtRO :: PrimMonad prim => MArray ty (PrimState prim) -> Offset ty -> Array ty -> Offset ty -> CountOf ty -> prim ()
- thaw :: PrimMonad prim => Array ty -> prim (MArray ty (PrimState prim))
- new :: PrimMonad prim => CountOf ty -> prim (MArray ty (PrimState prim))
- create :: CountOf ty -> (Offset ty -> ty) -> Array ty
- unsafeFreeze :: PrimMonad prim => MArray ty (PrimState prim) -> prim (Array ty)
- unsafeThaw :: PrimMonad prim => Array ty -> prim (MArray ty (PrimState prim))
- freeze :: PrimMonad prim => MArray ty (PrimState prim) -> prim (Array ty)
- unsafeWrite :: PrimMonad prim => MArray ty (PrimState prim) -> Offset ty -> ty -> prim ()
- unsafeRead :: PrimMonad prim => MArray ty (PrimState prim) -> Offset ty -> prim ty
- unsafeIndex :: Array ty -> Offset ty -> ty
- write :: PrimMonad prim => MArray ty (PrimState prim) -> Offset ty -> ty -> prim ()
- read :: PrimMonad prim => MArray ty (PrimState prim) -> Offset ty -> prim ty
- index :: Array ty -> Offset ty -> ty
- singleton :: ty -> Array ty
- replicate :: CountOf ty -> ty -> Array ty
- null :: Array ty -> Bool
- take :: CountOf ty -> Array ty -> Array ty
- drop :: CountOf ty -> Array ty -> Array ty
- splitAt :: CountOf ty -> Array ty -> (Array ty, Array ty)
- revTake :: CountOf ty -> Array ty -> Array ty
- revDrop :: CountOf ty -> Array ty -> Array ty
- revSplitAt :: CountOf ty -> Array ty -> (Array ty, Array ty)
- splitOn :: (ty -> Bool) -> Array ty -> [Array ty]
- sub :: Array ty -> Offset ty -> Offset ty -> Array ty
- intersperse :: ty -> Array ty -> Array ty
- span :: (ty -> Bool) -> Array ty -> (Array ty, Array ty)
- spanEnd :: (ty -> Bool) -> Array ty -> (Array ty, Array ty)
- break :: (ty -> Bool) -> Array ty -> (Array ty, Array ty)
- breakEnd :: (ty -> Bool) -> Array ty -> (Array ty, Array ty)
- mapFromUnboxed :: PrimType a => (a -> b) -> UArray a -> Array b
- mapToUnboxed :: PrimType b => (a -> b) -> Array a -> UArray b
- cons :: ty -> Array ty -> Array ty
- snoc :: Array ty -> ty -> Array ty
- uncons :: Array ty -> Maybe (ty, Array ty)
- unsnoc :: Array ty -> Maybe (Array ty, ty)
- sortBy :: (ty -> ty -> Ordering) -> Array ty -> Array ty
- filter :: (ty -> Bool) -> Array ty -> Array ty
- reverse :: Array ty -> Array ty
- elem :: Eq ty => ty -> Array ty -> Bool
- find :: (ty -> Bool) -> Array ty -> Maybe ty
- foldl' :: (a -> ty -> a) -> a -> Array ty -> a
- foldr :: (ty -> a -> a) -> a -> Array ty -> a
- foldl1' :: (ty -> ty -> ty) -> NonEmpty (Array ty) -> ty
- foldr1 :: (ty -> ty -> ty) -> NonEmpty (Array ty) -> ty
- all :: (ty -> Bool) -> Array ty -> Bool
- any :: (ty -> Bool) -> Array ty -> Bool
- isPrefixOf :: Eq ty => Array ty -> Array ty -> Bool
- isSuffixOf :: Eq ty => Array ty -> Array ty -> Bool
- builderAppend :: forall (state :: Type -> Type) ty err. PrimMonad state => ty -> Builder (Array ty) (MArray ty) ty state err ()
- builderBuild :: PrimMonad m => Int -> Builder (Array ty) (MArray ty) ty m err () -> m (Either err (Array ty))
- builderBuild_ :: PrimMonad m => Int -> Builder (Array ty) (MArray ty) ty m () () -> m (Array ty)

# Documentation

data Array a Source #

Array of a

#### Instances

Instances details

Functor Array Source # |
Instance details Defined in Basement.BoxedArray Methods fmap :: (a -> b) -> Array a -> Array b Source # (<$) :: a -> Array b -> Array a Source #
NormalForm a => NormalForm (Array a) Source # |
Instance details Defined in Basement.BoxedArray Methods toNormalForm :: Array a -> () Source #
Monoid (Array a) Source # |
Instance details Defined in Basement.BoxedArray Methods mempty :: Array a Source # mappend :: Array a -> Array a -> Array a Source # mconcat :: [Array a] -> Array a Source #
Semigroup (Array a) Source # |
Instance details Defined in Basement.BoxedArray Methods (<>) :: Array a -> Array a -> Array a Source # sconcat :: NonEmpty (Array a) -> Array a Source # stimes :: Integral b => b -> Array a -> Array a Source #
Data ty => Data (Array ty) Source # |

Instance details

Defined in Basement.BoxedArray

Methods

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

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

toConstr :: Array ty -> Constr Source #

dataTypeOf :: Array ty -> DataType Source #

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

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

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

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

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

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

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

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

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

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

IsList (Array ty) Source # |

Instance details

Defined in Basement.BoxedArray

Associated Types

type Item (Array ty) |
Instance details Defined in Basement.BoxedArray type Item (Array ty) = ty

Methods

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

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

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

Show a => Show (Array a) Source # |
Instance details Defined in Basement.BoxedArray Methods showsPrec :: Int -> Array a -> ShowS Source # show :: Array a -> String Source # showList :: [Array a] -> ShowS Source #
Eq a => Eq (Array a) Source # |
Instance details Defined in Basement.BoxedArray Methods (==) :: Array a -> Array a -> Bool Source # (/=) :: Array a -> Array a -> Bool Source #
Ord a => Ord (Array a) Source # |
Instance details Defined in Basement.BoxedArray Methods compare :: Array a -> Array a -> Ordering Source # (<) :: Array a -> Array a -> Bool Source # (<=) :: Array a -> Array a -> Bool Source # (>) :: Array a -> Array a -> Bool Source # (>=) :: Array a -> Array a -> Bool Source # max :: Array a -> Array a -> Array a Source # min :: Array a -> Array a -> Array a Source #
PrimType ty => From (Array ty) (Block ty) Source # |
Instance details Defined in Basement.From Methods from :: Array ty -> Block ty Source #
PrimType ty => From (Array ty) (UArray ty) Source # |
Instance details Defined in Basement.From Methods from :: Array ty -> UArray ty Source #
PrimType ty => From (UArray ty) (Array ty) Source # |
Instance details Defined in Basement.From Methods from :: UArray ty -> Array ty Source #
(NatWithinBound (CountOf ty) n, KnownNat n, PrimType ty) => TryFrom (Array ty) (BlockN n ty) Source # |
Instance details Defined in Basement.From Methods tryFrom :: Array ty -> Maybe (BlockN n ty) Source #
(NatWithinBound Int n, PrimType ty) => From (BlockN n ty) (Array ty) Source # |
Instance details Defined in Basement.From Methods from :: BlockN n ty -> Array ty Source #
type Item (Array ty) Source # |
Instance details Defined in Basement.BoxedArray type Item (Array ty) = ty

data MArray a st Source #

Mutable Array of a

empty :: Array a Source #

length :: Array a -> CountOf a Source #

mutableLength :: MArray ty st -> Int Source #

return the numbers of elements in a mutable array

copy :: Array ty -> Array ty Source #

Copy the element to a new element array

unsafeCopyAtRO Source #

Arguments

:: PrimMonad prim |
=> MArray ty (PrimState prim) | destination array
-> Offset ty | offset at destination
-> Array ty | source array
-> Offset ty | offset at source
-> CountOf ty | number of elements to copy
-> prim () |

Copy `n` sequential elements from the specified offset in a source array to the specified position in a destination array.

This function does not check bounds. Accessing invalid memory can return unpredictable and invalid values.

thaw :: PrimMonad prim => Array ty -> prim (MArray ty (PrimState prim)) Source #

Thaw an array to a mutable array.

the array is not modified, instead a new mutable array is created and every values is copied, before returning the mutable array.

new :: PrimMonad prim => CountOf ty -> prim (MArray ty (PrimState prim)) Source #

Create a new mutable array of size @n.

all the cells are uninitialized and could contains invalid values.

All mutable arrays are allocated on a 64 bits aligned addresses and always contains a number of bytes multiples of 64 bits.

create Source #

Arguments

:: CountOf ty | the size of the array
-> (Offset ty -> ty) | the function that set the value at the index
-> Array ty | the array created

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

unsafeFreeze :: PrimMonad prim => MArray ty (PrimState prim) -> prim (Array ty) Source #

Freeze a mutable array into an array.

the MArray must not be changed after freezing.

unsafeThaw :: PrimMonad prim => Array ty -> prim (MArray ty (PrimState prim)) Source #

Thaw an immutable array.

The Array must not be used after thawing.

freeze :: PrimMonad prim => MArray ty (PrimState prim) -> prim (Array ty) Source #

unsafeWrite :: PrimMonad prim => MArray ty (PrimState prim) -> Offset ty -> ty -> prim () Source #

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

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

unsafeRead :: PrimMonad prim => MArray ty (PrimState prim) -> Offset ty -> prim ty Source #

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

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

unsafeIndex :: Array 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.

write :: PrimMonad prim => MArray ty (PrimState prim) -> Offset ty -> ty -> prim () Source #

Write to a cell in a mutable array.

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

read :: PrimMonad prim => MArray ty (PrimState prim) -> Offset ty -> prim ty Source #

read a cell in a mutable array.

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

index :: Array 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.

singleton :: ty -> Array ty Source #

replicate :: CountOf ty -> ty -> Array ty Source #

null :: Array ty -> Bool Source #

take :: CountOf ty -> Array ty -> Array ty Source #

drop :: CountOf ty -> Array ty -> Array ty Source #

splitAt :: CountOf ty -> Array ty -> (Array ty, Array ty) Source #

revTake :: CountOf ty -> Array ty -> Array ty Source #

revDrop :: CountOf ty -> Array ty -> Array ty Source #

revSplitAt :: CountOf ty -> Array ty -> (Array ty, Array ty) Source #

splitOn :: (ty -> Bool) -> Array ty -> [Array ty] Source #

sub :: Array ty -> Offset ty -> Offset ty -> Array ty Source #

intersperse :: ty -> Array ty -> Array ty Source #

span :: (ty -> Bool) -> Array ty -> (Array ty, Array ty) Source #

spanEnd :: (ty -> Bool) -> Array ty -> (Array ty, Array ty) Source #

break :: (ty -> Bool) -> Array ty -> (Array ty, Array ty) Source #

breakEnd :: (ty -> Bool) -> Array ty -> (Array ty, Array ty) Source #

mapFromUnboxed :: PrimType a => (a -> b) -> UArray a -> Array b Source #

mapToUnboxed :: PrimType b => (a -> b) -> Array a -> UArray b Source #

cons :: ty -> Array ty -> Array ty Source #

snoc :: Array ty -> ty -> Array ty Source #

uncons :: Array ty -> Maybe (ty, Array ty) Source #

unsnoc :: Array ty -> Maybe (Array ty, ty) Source #

sortBy :: (ty -> ty -> Ordering) -> Array ty -> Array ty Source #

filter :: (ty -> Bool) -> Array ty -> Array ty Source #

reverse :: Array ty -> Array ty Source #

elem :: Eq ty => ty -> Array ty -> Bool Source #

find :: (ty -> Bool) -> Array ty -> Maybe ty Source #

foldl' :: (a -> ty -> a) -> a -> Array ty -> a Source #

foldr :: (ty -> a -> a) -> a -> Array ty -> a Source #

foldl1' :: (ty -> ty -> ty) -> NonEmpty (Array ty) -> ty Source #

foldr1 :: (ty -> ty -> ty) -> NonEmpty (Array ty) -> ty Source #

all :: (ty -> Bool) -> Array ty -> Bool Source #

any :: (ty -> Bool) -> Array ty -> Bool Source #

isPrefixOf :: Eq ty => Array ty -> Array ty -> Bool Source #

isSuffixOf :: Eq ty => Array ty -> Array ty -> Bool Source #

builderAppend :: forall (state :: Type -> Type) ty err. PrimMonad state => ty -> Builder (Array ty) (MArray ty) ty state err () Source #

builderBuild :: PrimMonad m => Int -> Builder (Array ty) (MArray ty) ty m err () -> m (Either err (Array ty)) Source #

builderBuild_ :: PrimMonad m => Int -> Builder (Array ty) (MArray ty) ty m () () -> m (Array ty) Source #