2-- Module : Streamly.Internal.Data.Ring
3-- Copyright : (c) 2021 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
6-- Stability : experimental
10module Streamly.Internal.Data.Ring
16import Control.Monad.Primitive (PrimMonad(PrimState))
17import Data.IORef (modifyIORef', newIORef, readIORef, writeIORef, IORef)
18import Data.Primitive.Array (newArray, writeArray, MutableArray)
21 { arr :: MutableArray (PrimState IO) a
22 , ringHead :: IORef Int -- current index to be over-written
23 , ringMax :: !Int -- first index beyond allocated memory
26{-# INLINE createRing #-}
27createRing :: Int -> IO (Ring a)
29 arr' <- newArray count (undefined :: a)
37{-# INLINE unsafeInsertRing #-}
38unsafeInsertRing :: Ring a -> Int -> a -> IO ()
39unsafeInsertRing Ring{..} idx x = do
40 writeArray arr (mod idx ringMax) x
41 ref <- readIORef ringHead
43 then modifyIORef' ringHead ( + 1)
44 else writeIORef ringHead 0
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list