toy-lib-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Buffer

Description

Data.Buffer taken from cojna/iota (thanks!) It's a fixed-sized mutable vector with push/pop API.

Synopsis

Documentation

data Buffer s a #

A fixed-sized mutable vector with push/pop API.

Constructors

Buffer 

Fields

newBuffer :: (Unbox a, PrimMonad m) => Int -> m (Buffer (PrimState m) a) #

\(O(N)\) Creates a buffer of length n with initial value at zero. This is mostlly for queues.

newRevBuffer :: (Unbox a, PrimMonad m) => Int -> m (Buffer (PrimState m) a) #

\(O(N)\) Creates a buffer of length n with initial value at n - 1. This is mostly for stacks.

buildBuffer :: (Unbox a, PrimMonad m) => MVector (PrimState m) a -> m (Buffer (PrimState m) a) #

\(O(N)\) Wraps a mutable vector with push/pop API.

generateBuffer :: (Unbox a, PrimMonad m) => Int -> (Int -> a) -> m (Buffer (PrimState m) a) #

\(O(N)\) Creates a mutable vector with push/pop API.

type Deque s a = Buffer s a #

Alias to Buffer creates with newBufferAsDeuque.

newBufferAsDeque :: (Unbox a, PrimMonad m) => Int -> m (Buffer (PrimState m) a) #

\(O(N)\) Creates a buffer of length 2 * n with initial value at n.

createBuffer :: Unbox a => (forall s. ST s (Buffer s a)) -> Vector a #

\(O(N)\) Freezes a buffer after creation.

lengthBuffer :: PrimMonad m => Buffer (PrimState m) a -> m Int #

\(O(1)\)

nullBuffer :: PrimMonad m => Buffer (PrimState m) a -> m Bool #

\(O(1)\)

clearBuffer :: PrimMonad m => Buffer (PrimState m) a -> m () #

\(O(1)\)

freezeBuffer :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> m (Vector a) #

\(O(N)\)

unsafeFreezeBuffer :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> m (Vector a) #

\(O(1)\)

freezeInternalBuffer :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> m (Vector a) #

\(O(N)\)

unsafeFreezeInternalBuffer :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> m (Vector a) #

\(O(1)\)

popFront :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> m (Maybe a) #

\(O(1)\)

popFront_ :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> m () #

popFrontN :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> m (Maybe (Vector a)) #

\(O(L)\) The popped vector is from left to the right order.

popBackN :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> m (Maybe (Vector a)) #

\(O(L)\) The popped vector is from left to the right order.

popFrontN_ :: PrimMonad m => Buffer (PrimState m) a -> Int -> m (Maybe ()) #

\(O(1)\)

popBackN_ :: PrimMonad m => Buffer (PrimState m) a -> Int -> m (Maybe ()) #

\(O(1)\)

popBack :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> m (Maybe a) #

\(O(1)\)

popBack_ :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> m () #

\(O(1)\)

pushFront :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> a -> m () #

\(O(1)\)

pushBack :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> a -> m () #

\(O(1)\)

pushFronts :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Vector a -> m () #

\(O(K)\)

pushBacks :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Vector a -> m () #

\(O(K)\)

readMaybeFront :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> m (Maybe a) #

\(O(1)\)

readMaybeBack :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> m (Maybe a) #

\(O(1)\)

readFront :: (HasCallStack, Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> m a #

\(O(1)\)

readBack :: (HasCallStack, Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> m a #

\(O(1)\)

writeFront :: (HasCallStack, Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> a -> m () #

\(O(1)\)

writeBack :: (HasCallStack, Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> a -> m () #

\(O(1)\)

unsafeWriteFront :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> a -> m () #

\(O(1)\)

unsafeWriteBack :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> a -> m () #

\(O(1)\)

swapFront :: (HasCallStack, Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> Int -> m () #

\(O(1)\)

swapBack :: (HasCallStack, Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> Int -> m () #

\(O(1)\)

unsafeSwapFront :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> Int -> m () #

\(O(1)\)

unsafeSwapBack :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> Int -> m () #

\(O(1)\)

modifyFront :: (HasCallStack, Unbox a, PrimMonad m) => Buffer (PrimState m) a -> (a -> a) -> Int -> m () #

\(O(1)\)

modifyBack :: (HasCallStack, Unbox a, PrimMonad m) => Buffer (PrimState m) a -> (a -> a) -> Int -> m () #

\(O(1)\)

unsafeModifyFront :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> (a -> a) -> Int -> m () #

\(O(1)\)

unsafeModifyBack :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> (a -> a) -> Int -> m () #

\(O(1)\)

modifyMFront :: (HasCallStack, Unbox a, PrimMonad m) => Buffer (PrimState m) a -> (a -> m a) -> Int -> m () #

\(O(1)\)

modifyMBack :: (HasCallStack, Unbox a, PrimMonad m) => Buffer (PrimState m) a -> (a -> m a) -> Int -> m () #

\(O(1)\)

unsafeModifyMFront :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> (a -> m a) -> Int -> m () #

\(O(1)\)

unsafeModifyMBack :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> (a -> m a) -> Int -> m () #

\(O(1)\)

exchangeFront :: (HasCallStack, Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> a -> m a #

\(O(1)\)

exchangeBack :: (HasCallStack, Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> a -> m a #

\(O(1)\)

unsafeExchangeFront :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> a -> m a #

\(O(1)\)

unsafeExchangeBack :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> Int -> a -> m a #

\(O(1)\)

cloneBuffer :: (Unbox a, PrimMonad m) => Buffer (PrimState m) a -> m (Buffer (PrimState m) a) #

\(O(N)\)