1{-# LANGUAGE TypeFamilies #-}
2module Data.FastMutableIntMap
12 , traverseIntMapPatchWithKey
14 , forIntersectionWithImmutable_
16 , patchIntMapNewElements
17 , patchIntMapNewElementsMap
21--TODO: Pure JS version
22--TODO: Fast copy to FastIntMap
23--TODO: Fast patch type
25import Prelude hiding (lookup)
27import Control.Monad.IO.Class
28import Data.Foldable (traverse_)
29import Data.IntMap.Strict (IntMap)
30import qualified Data.IntMap.Strict as IntMap
32import Reflex.Patch.Class
33import Reflex.Patch.IntMap
35newtype FastMutableIntMap a = FastMutableIntMap (IORef (IntMap a))
37new :: IntMap a -> IO (FastMutableIntMap a)
38new m = FastMutableIntMap <$> newIORef m
40newEmpty :: IO (FastMutableIntMap a)
41newEmpty = FastMutableIntMap <$> newIORef IntMap.empty
43insert :: FastMutableIntMap a -> Int -> a -> IO ()
44insert (FastMutableIntMap r) k v = modifyIORef' r $ IntMap.insert k v
46lookup :: FastMutableIntMap a -> Int -> IO (Maybe a)
47lookup (FastMutableIntMap r) k = IntMap.lookup k <$> readIORef r
49forIntersectionWithImmutable_ :: MonadIO m => FastMutableIntMap a -> IntMap b -> (a -> b -> m ()) -> m ()
50forIntersectionWithImmutable_ (FastMutableIntMap r) b f = do
51 a <- liftIO $ readIORef r
52 traverse_ (uncurry f) $ IntMap.intersectionWith (,) a b
54for_ :: MonadIO m => FastMutableIntMap a -> (a -> m ()) -> m ()
55for_ (FastMutableIntMap r) f = do
56 a <- liftIO $ readIORef r
59isEmpty :: FastMutableIntMap a -> IO Bool
60isEmpty (FastMutableIntMap r) = IntMap.null <$> readIORef r
62size :: FastMutableIntMap a -> IO Int
63size (FastMutableIntMap r) = IntMap.size <$> readIORef r
65-- | Make an immutable snapshot of the datastructure and clear it
66getFrozenAndClear :: FastMutableIntMap a -> IO (IntMap a)
67getFrozenAndClear (FastMutableIntMap r) = do
69 writeIORef r IntMap.empty
72applyPatch :: FastMutableIntMap a -> PatchIntMap a -> IO (IntMap a)
73applyPatch (FastMutableIntMap r) p@(PatchIntMap m) = do
75 writeIORef r $! applyAlways p v
76 return $ IntMap.intersection v m
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