Safe Haskell | None |
---|---|

Language | Haskell2010 |

A concurrent, mutable ring buffer that supports atomic updates. This module is most efficient on buffers containing unlifted types.

## Synopsis

- data RingBuffer a
- new :: Prim a => Int -> IO (RingBuffer a)
- clear :: Prim a => RingBuffer a -> IO ()
- append :: Prim a => a -> RingBuffer a -> IO ()
- extend :: Prim a => PrimArray a -> RingBuffer a -> IO ()
- capacity :: Prim a => RingBuffer a -> IO Int
- filledLength :: Prim a => RingBuffer a -> IO Int
- latest :: Prim a => RingBuffer a -> Int -> IO (Maybe a)
- unsafeLatest :: Prim a => RingBuffer a -> Int -> IO a
- foldMap :: (Prim a, Monoid b) => RingBuffer a -> (a -> IO b) -> IO b
- toList :: Prim a => RingBuffer a -> IO [a]

# Documentation

data RingBuffer a Source #

A concurrent, mutable ring buffer that supports atomic updates.

:: Prim a | |

=> Int | capacity of buffer |

-> IO (RingBuffer a) |

Return a new ring buffer of the specified size.

extend :: Prim a => PrimArray a -> RingBuffer a -> IO () Source #

Write multiple items to the end of the ring.

Ignores any elements of the input array whose indices are higher than the length of the ring buffer.

capacity :: Prim a => RingBuffer a -> IO Int Source #

Get the maximum number of items the ring can contain

filledLength :: Prim a => RingBuffer a -> IO Int Source #

Get the current filled length of the ring

latest :: Prim a => RingBuffer a -> Int -> IO (Maybe a) Source #

Retrieve the \(n\)th most-recently added item of the ring

unsafeLatest :: Prim a => RingBuffer a -> Int -> IO a Source #

Retrieve the \(n\)th most-recently added item of the ring

*Note*: This function may exhibit undefined behaviour if
the index is out-of-bounds or uninitialised.