-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Circular fixed-sized mutable vectors -- -- Please see the README on GitHub at -- https://github.com/dschrempf/circular#readme @package circular @version 0.1.1 -- | Creation date: Thu Jun 18 10:00:28 2020. module Data.Stack.Circular -- | Circular stacks with fxed maximum size are just normal vectors with a -- pointer to the last element. -- -- Construction of CStacks is done with empty and -- subsequent pushes, 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. data CStack v a CStack :: v a -> !Int -> !Int -> CStack v a [stack] :: CStack v a -> v a [index] :: CStack v a -> !Int [curSize] :: CStack v a -> !Int -- | A circular stack without an element but of a given maximum size. At -- this state, it is not very useful :). O(n). empty :: Vector v a => Int -> CStack v a -- | See empty; do no check that length is strictly positive. unsafeEmpty :: Vector v a => Int -> CStack v a -- | 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). toVector :: Vector v a => CStack v a -> v a -- | 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). toVectorN :: Vector v a => Int -> CStack v a -> v a -- | See toVectorN but do not check that N is positive. unsafeToVectorN :: Vector v a => Int -> CStack v a -> v a -- | 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. fromVector :: Vector v a => v a -> CStack v a -- | See fromVector but do not check for empty vector. unsafeFromVector :: Vector v a => v a -> CStack v a -- | Get the last element without changing the stack. O(1). get :: Vector v a => CStack v a -> a -- | Get the last element and remove it from the stack. O(1). -- -- The stack must be non-empty. pop :: Vector v a => CStack v a -> (a, CStack v a) -- | Push an element on the stack. Slow! If possible, use -- unsafePush. O(n). push :: Vector v a => a -> CStack v a -> CStack v a -- | 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. unsafePush :: Vector v a => a -> CStack v a -> CStack v a -- | Reset the stack. O(1). reset :: CStack v a -> CStack v a -- | Check if the stack is full. isFull :: Vector v a => CStack v a -> Bool -- | Left fold. O(m). foldl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> CStack v b -> a -- | Left fold with strict accumulator. O(m). foldl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> CStack v b -> a -- | Left fold on non-empty vectors with strict accumulator. O(m). foldl1' :: Vector v a => (a -> a -> a) -> CStack v a -> a -- | Compute the sum of the elements on the stack. O(m). sum :: (Num a, Vector v a) => CStack v a -> a -- | Compute the product of the elements on the stack. O(m). product :: (Num a, Vector v a) => CStack v a -> a instance (GHC.Classes.Eq (v a), Data.Vector.Generic.Base.Vector v a) => GHC.Classes.Eq (Data.Stack.Circular.CStack v a) instance (GHC.Show.Show (v a), Data.Vector.Generic.Base.Vector v a) => GHC.Show.Show (Data.Stack.Circular.CStack v a) instance (Data.Aeson.Types.ToJSON.ToJSON a, Data.Aeson.Types.ToJSON.ToJSON (v a), Data.Vector.Generic.Base.Vector v a) => Data.Aeson.Types.ToJSON.ToJSON (Data.Stack.Circular.CStack v a) instance (Data.Aeson.Types.FromJSON.FromJSON a, Data.Aeson.Types.FromJSON.FromJSON (v a), Data.Vector.Generic.Base.Vector v a) => Data.Aeson.Types.FromJSON.FromJSON (Data.Stack.Circular.CStack v a)