Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Deque v s a
- type UDeque = Deque MVector
- type SDeque = Deque MVector
- type BDeque = Deque MVector
- newDeque :: (MVector v a, PrimMonad m) => m (Deque v (PrimState m) a)
- getDequeSize :: PrimMonad m => Deque v (PrimState m) a -> m Int
- popFrontDeque :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> m (Maybe a)
- popBackDeque :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> m (Maybe a)
- pushFrontDeque :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> a -> m ()
- pushBackDeque :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> a -> m ()
- foldlDeque :: (MVector v a, PrimMonad m) => (acc -> a -> m acc) -> acc -> Deque v (PrimState m) a -> m acc
- foldrDeque :: (MVector v a, PrimMonad m) => (a -> acc -> m acc) -> acc -> Deque v (PrimState m) a -> m acc
- dequeToList :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> m [a]
- dequeToVector :: (Vector v' a, MVector v a, PrimMonad m) => Deque v (PrimState m) a -> m (v' a)
- freezeDeque :: (Vector v a, PrimMonad m) => Deque (Mutable v) (PrimState m) a -> m (v a)
- asUDeque :: UDeque s a -> UDeque s a
- asSDeque :: SDeque s a -> SDeque s a
- asBDeque :: BDeque s a -> BDeque s a
Types
A double-ended queue supporting any underlying vector type and any monad.
This implements a circular double-ended queue with exponential growth.
Since: 0.1.9.0
Operations
newDeque :: (MVector v a, PrimMonad m) => m (Deque v (PrimState m) a) Source #
Create a new, empty Deque
Since: 0.1.9.0
getDequeSize :: PrimMonad m => Deque v (PrimState m) a -> m Int Source #
O(1) - Get the number of elements that is currently in the Deque
Since: 0.1.9.0
popFrontDeque :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> m (Maybe a) Source #
Pop the first value from the beginning of the Deque
Since: 0.1.9.0
popBackDeque :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> m (Maybe a) Source #
Pop the first value from the end of the Deque
Since: 0.1.9.0
pushFrontDeque :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> a -> m () Source #
Push a new value to the beginning of the Deque
Since: 0.1.9.0
pushBackDeque :: (MVector v a, PrimMonad m) => Deque v (PrimState m) a -> a -> m () Source #
Push a new value to the end of the Deque
Since: 0.1.9.0
foldlDeque :: (MVector v a, PrimMonad m) => (acc -> a -> m acc) -> acc -> Deque v (PrimState m) a -> m acc Source #
foldrDeque :: (MVector v a, PrimMonad m) => (a -> acc -> m acc) -> acc -> Deque v (PrimState m) a -> m acc Source #
dequeToVector :: (Vector v' a, MVector v a, PrimMonad m) => Deque v (PrimState m) a -> m (v' a) Source #
Convert to an immutable vector of any type. If resulting pure vector corresponds to the mutable
one used by the Deque
, it will be more efficient to use freezeDeque
instead.
Example
>>>
:set -XTypeApplications
>>>
import qualified RIO.Vector.Unboxed as U
>>>
import qualified RIO.Vector.Storable as S
>>>
d <- newDeque @U.MVector @Int
>>>
mapM_ (pushFrontDeque d) [0..10]
>>>
dequeToVector @S.Vector d
[10,9,8,7,6,5,4,3,2,1,0]
Since: 0.1.9.0
freezeDeque :: (Vector v a, PrimMonad m) => Deque (Mutable v) (PrimState m) a -> m (v a) Source #
Yield an immutable copy of the underlying mutable vector. The difference from dequeToVector
is that the the copy will be performed with a more efficient memcpy
, rather than element by
element. The downside is that the resulting vector type must be the one that corresponds to the
mutable one that is used in the Deque
.
Example
>>>
:set -XTypeApplications
>>>
import qualified RIO.Vector.Unboxed as U
>>>
d <- newDeque @U.MVector @Int
>>>
mapM_ (pushFrontDeque d) [0..10]
>>>
freezeDeque @U.Vector d
[10,9,8,7,6,5,4,3,2,1,0]
Since: 0.1.9.0
Inference helpers
asUDeque :: UDeque s a -> UDeque s a Source #
Helper function to assist with type inference, forcing usage of an unboxed vector.
Since: 0.1.9.0