ring-buffer-0.4: A concurrent, mutable ring-buffer

Safe HaskellNone
LanguageHaskell2010

Data.RingBuffer

Description

This is a thread-safe implementation of a mutable ring-buffer built upon vector.

Synopsis

Documentation

data RingBuffer v a Source #

A concurrent ring buffer.

new :: Vector v a => Int -> IO (RingBuffer v a) Source #

Create a new ring of a given length

Note: size must be non-zero

clear :: Vector v a => RingBuffer v a -> IO () Source #

Reset the ringbuffer to its empty state

append :: Vector v a => a -> RingBuffer v a -> IO () Source #

Add an item to the end of the ring

concat :: Vector v a => v a -> RingBuffer v a -> IO () Source #

Add multiple items to the end of the ring This ignores any items above the length of the ring

capacity :: Vector v a => RingBuffer v a -> Int Source #

The maximum number of items the ring can contain

length :: Vector v a => RingBuffer v a -> IO Int Source #

The current filled length of the ring

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

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

toList :: Vector v a => RingBuffer v a -> IO [a] Source #

Get the entire contents of the ring, with the most recently added element at the head. Note that this is rather inefficient.

withItems :: (MonadIO m, MonadMask m, Vector v a) => RingBuffer v a -> (v a -> m b) -> m b Source #

Execute the given action with the items of the ring. Note that no references to the vector may leak out of the action as it will later be mutated. Moreover, the items in the vector are in no particular order.