Data.Bytes.Mutable

byteslice-0.2.14.0: Slicing managed and unmanaged memory

Safe Haskell | None
Language | Haskell2010

Data.Bytes.Mutable

Contents

- Types
- Filtering
- Unsafe Slicing
- Conversion

Description

If you are interested in sub-arrays of `MutableByteArray`s (e.g. writing quicksort), it would be grossly inefficient to make a copy of the sub-array. On the other hand, it'd be really annoying to track limit indices by hand.

This module defines the `MutableBytes` type which exposes a standard array interface for a sub-arrays without copying and without manual index manipulation. For immutable arrays, see `Bytes`.

Synopsis

- data MutableBytes s
- takeWhile :: PrimMonad m => (Word8 -> m Bool) -> MutableBytes (PrimState m) -> m (MutableBytes (PrimState m))
- dropWhile :: PrimMonad m => (Word8 -> m Bool) -> MutableBytes (PrimState m) -> m (MutableBytes (PrimState m))
- unsafeTake :: Int -> MutableBytes s -> MutableBytes s
- unsafeDrop :: Int -> MutableBytes s -> MutableBytes s
- fromMutableByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> m (MutableBytes (PrimState m))

# Types

data MutableBytes s #

A slice of a `MutableByteArray`.

# Filtering

takeWhile :: PrimMonad m => (Word8 -> m Bool) -> MutableBytes (PrimState m) -> m (MutableBytes (PrimState m)) #

Take bytes while the predicate is true, aliasing the argument array.

dropWhile :: PrimMonad m => (Word8 -> m Bool) -> MutableBytes (PrimState m) -> m (MutableBytes (PrimState m)) #

Drop bytes while the predicate is true, aliasing the argument array.

# Unsafe Slicing

unsafeTake :: Int -> MutableBytes s -> MutableBytes s #

Take the first `n` bytes from the argument, aliasing it.

unsafeDrop :: Int -> MutableBytes s -> MutableBytes s #

Drop the first `n` bytes from the argument, aliasing it. The new length will be `len - n`.

# Conversion

fromMutableByteArray :: PrimMonad m => MutableByteArray (PrimState m) -> m (MutableBytes (PrimState m)) #

Create a slice of `MutableBytes` that spans the entire argument array. This aliases the argument.