Copyright | (c) Dominik Schrempf 2020 |
---|---|
License | GPL-3.0-or-later |
Maintainer | dominik.schrempf@gmail.com |
Stability | unstable |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Creation date: Thu Jun 18 10:00:28 2020.
Synopsis
- data CStack v a = CStack {}
- empty :: Vector v a => Int -> CStack v a
- toVector :: Vector v a => CStack v a -> v a
- toVectorN :: Vector v a => Int -> CStack v a -> v a
- fromVector :: Vector v a => v a -> CStack v a
- get :: Vector v a => CStack v a -> a
- pop :: Vector v a => CStack v a -> (a, CStack v a)
- push :: Vector v a => a -> CStack v a -> CStack v a
- unsafePush :: Vector v a => a -> CStack v a -> CStack v a
- isFull :: Vector v a => CStack v a -> Bool
- foldl1' :: Vector v a => (a -> a -> a) -> CStack v a -> a
- sum :: (Num a, Vector v a) => CStack v a -> a
- mean :: (Real a, Vector v a, Fractional b) => CStack v a -> b
- product :: (Num a, Vector v a) => CStack v a -> a
Boxed circular stacks
Circular stacks with fxed maximum size are just normal vectors with a pointer to the last element.
Construction of CStack
s is done with empty
and subsequent push
es, or
the provided type conversion functions so that the index and bounds are
updated and checked consistently. The data constructor CStack
is exported
only to enable creation of orphan instances such as Arbitrary (QuickCheck).
When denoting the efficiency of the functions m
refers to the current size
of the stack, and n
to the maximum size.
Instances
(Eq (v a), Vector v a) => Eq (CStack v a) Source # | |
(Show (v a), Vector v a) => Show (CStack v a) Source # | |
(ToJSON a, ToJSON (v a), Vector v a) => ToJSON (CStack v a) Source # | We have |
Defined in Data.Stack.Circular | |
(FromJSON a, FromJSON (v a), Vector v a) => FromJSON (CStack v a) Source # | |
Construction
empty :: Vector v a => Int -> CStack v a Source #
A circular stack without an element but of a given maximum size. At this state, it is not very useful :). O(n).
Conversion
toVector :: Vector v a => CStack v a -> v a Source #
Convert a circular stack to a vector. The first element of the returned vector is the deepest (oldest) element of the stack, the last element of the returned vector is the current (newest) element of the stack.
This is a relatively expensive operation. O(m).
toVectorN :: Vector v a => Int -> CStack v a -> v a Source #
Convert the last N elements of a circular stack to a vector. The first element of the returned vector is the deepest (oldest) element of the stack, the last element of the returned vector is the current (newest) element of the stack.
The size of the stack must be larger than N.
This is a relatively expensive operation. O(N).
fromVector :: Vector v a => v a -> CStack v a Source #
Convert a vector to a circular stack. The first element of the vector is the deepest (oldest) element of the stack, the last element of the vector is the current (newest) element of the stack. O(n).
The vector must be non-empty.
Accessors
pop :: Vector v a => CStack v a -> (a, CStack v a) Source #
Get the last element and remove it from the stack. O(1).
The stack must be non-empty.
unsafePush :: Vector v a => a -> CStack v a -> CStack v a Source #
Push an element on the stack. O(1).
Be careful; the internal vector is mutated! The immutable circular stack may not be used after this operation.
Queries
Folding
foldl1' :: Vector v a => (a -> a -> a) -> CStack v a -> a Source #
Compute summary statistics of the elements on the stack using a custom
commutative mappend
function.