Safe Haskell | None |
---|---|
Language | Haskell2010 |
This is a thread-safe implementation of a mutable ring-buffer
built upon vector
.
- data RingBuffer v a
- new :: Vector v a => Int -> IO (RingBuffer v a)
- clear :: Vector v a => RingBuffer v a -> IO ()
- append :: Vector v a => a -> RingBuffer v a -> IO ()
- concat :: Vector v a => v a -> RingBuffer v a -> IO ()
- capacity :: Vector v a => RingBuffer v a -> Int
- length :: Vector v a => RingBuffer v a -> IO Int
- latest :: Vector v a => RingBuffer v a -> Int -> IO (Maybe a)
- toList :: Vector v a => RingBuffer v a -> IO [a]
- withItems :: (MonadIO m, MonadMask m, Vector v a) => RingBuffer v a -> (v a -> m b) -> m b
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
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
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.