gameServer/Store.hs
changeset 3501 a3159a410e5c
parent 3435 4e4f88a7bdf2
child 3566 772a46ef8288
equal deleted inserted replaced
3500:af8390d807d6 3501:a3159a410e5c
     7     removeElem,
     7     removeElem,
     8     readElem,
     8     readElem,
     9     writeElem,
     9     writeElem,
    10     modifyElem,
    10     modifyElem,
    11     firstIndex,
    11     firstIndex,
       
    12     indicesM,
    12     withIStore,
    13     withIStore,
    13     withIStore2,
    14     withIStore2,
    14     (!),
    15     (!),
    15     indices
    16     indices
    16     ) where
    17     ) where
    92 modifyElem (MStore ref) f (ElemIndex n) = do
    93 modifyElem (MStore ref) f (ElemIndex n) = do
    93     (_, _, arr) <- readIORef ref
    94     (_, _, arr) <- readIORef ref
    94     IOA.readArray arr n >>= (IOA.writeArray arr n) . f
    95     IOA.readArray arr n >>= (IOA.writeArray arr n) . f
    95 
    96 
    96 
    97 
       
    98 indicesM :: MStore e -> IO [ElemIndex]
       
    99 indicesM (MStore ref) = do
       
   100     (busy, _, _) <- readIORef ref
       
   101     return $ map ElemIndex $ IntSet.toList busy
       
   102 
       
   103 
    97 -- A way to use see MStore elements in pure code via IStore
   104 -- A way to use see MStore elements in pure code via IStore
    98 m2i :: MStore e -> IO (IStore e)
   105 m2i :: MStore e -> IO (IStore e)
    99 m2i (MStore ref) = do
   106 m2i (MStore ref) = do
   100     (a, _, c') <- readIORef ref 
   107     (a, _, c') <- readIORef ref 
   101     c <- IOA.unsafeFreeze c'
   108     c <- IOA.unsafeFreeze c'
   102     return $ IStore (a, c)
   109     return $ IStore (a, c)
       
   110 
   103 
   111 
   104 withIStore :: MStore e -> (IStore e -> a) -> IO a
   112 withIStore :: MStore e -> (IStore e -> a) -> IO a
   105 withIStore m f = liftM f (m2i m)
   113 withIStore m f = liftM f (m2i m)
   106 
   114 
   107 
   115