Changeset 12505 for third-party

Show
Ignore:
Timestamp:
08/20/06 08:18:46 (2 years ago)
Author:
cmarcelo
Message:

* HsJudy?: swapMaps is now part of MapM. Also, now we have a
instance of MapM for IORef (Data.Map.Map a b).

Location:
third-party/HsJudy
Files:
1 added
9 modified

Legend:

Unmodified
Added
Removed
  • third-party/HsJudy/Judy/CollectionsM.hs

    r11676 r12505  
    11{-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-} 
    22 
    3 module Judy.CollectionsM where  
     3module Judy.CollectionsM ( 
     4    MapM (..), 
     5    MapF (..) 
     6) where  
    47 
    58import Judy.Freeze 
    69import Foreign 
     10import Data.IORef 
     11import qualified Data.Map as DM 
     12 
    713 
    814import Prelude hiding (lookup) 
     
    5359    mapToList :: (k -> a -> b) -> c -> m [b] 
    5460 
     61    swapMaps :: c -> c -> m () 
     62 
    5563 
    5664 
     
    8189    toListF :: c -> [(k, a)] 
    8290 
     91instance (Ord k) => MapM (IORef (DM.Map k a)) k a IO where 
     92    new = newIORef DM.empty 
     93    delete k m = do 
     94        modifyIORef m (\x -> DM.delete k x) 
     95        return True 
     96    member k m = do 
     97        m' <- readIORef m 
     98        return $ DM.member k m' 
     99    lookup k m = do 
     100        m' <- readIORef m 
     101        return $ DM.lookup k m' 
     102    insert k a m = modifyIORef m (\x -> DM.insert k a x) 
     103    alter f k m = do 
     104        m' <- readIORef m 
     105        case DM.lookup k m' of 
     106            Nothing -> case (f Nothing) of 
     107                Nothing -> return Nothing 
     108                Just y  -> (insert k y m) >> (return $ Just y) 
     109            Just x  -> case (f (Just x)) of 
     110                Nothing -> (delete k m)   >> (return Nothing) 
     111                Just y  -> (insert k y m) >> (return $ Just y) 
     112    fromList = newIORef . DM.fromList 
     113    toList m = do 
     114        m' <- readIORef m 
     115        return $ DM.toList m' 
     116    elems m = do 
     117        m' <- readIORef m 
     118        return $ DM.elems m' 
     119    keys m = do 
     120        m' <- readIORef m 
     121        return $ DM.keys m' 
     122    mapToList f m = do 
     123        m' <- readIORef m 
     124        let l = DM.toList m' 
     125        let f' (k,a) = f k a 
     126        return $ map f' l 
     127    swapMaps x y = do 
     128        x' <- readIORef x 
     129        y' <- readIORef y 
     130        writeIORef x y' 
     131        writeIORef y x' 
  • third-party/HsJudy/Judy/Hash.hs

    r12301 r12505  
    44 
    55module Judy.Hash ( 
    6     Stringable (..), 
    76    Hash (..), 
    87 
    98    -- FIXME: need to move to MapM api 
    10     swapMaps, freeze 
     9    freeze 
    1110) where 
    1211 
     
    4746    keys = keys_ 
    4847    mapToList = mapToList_ 
     48    swapMaps = swapMaps_ 
    4949 
    5050instance (Stringable k, Refeable a) => Freezable (Hash k a) where 
    5151    freeze m = do 
    5252        m' <- new_ 
    53         swapMaps m' m 
     53        swapMaps_ m' m 
    5454        return (Frozen m') 
    5555 
     
    220220 
    221221 
    222 swapMaps :: Hash k a -> Hash k a -> IO () 
    223 swapMaps (Hash j1) (Hash j2) = do 
     222swapMaps_ :: Hash k a -> Hash k a -> IO () 
     223swapMaps_ (Hash j1) (Hash j2) = do 
    224224    withForeignPtr j1 $ \p1 -> withForeignPtr j2 $ \p2 -> do 
    225225        v1 <- peek p1 
  • third-party/HsJudy/Judy/IntMap.hs

    r12301 r12505  
    55module Judy.IntMap ( 
    66    IntMap (..), 
    7     swapMaps, freeze, 
     7     
     8    freeze, 
    89    toRevList, 
    910    size, 
     
    4849    keys = keys_ 
    4950    mapToList = mapToList_ 
     51    swapMaps = swapMaps_ 
    5052 
    5153instance (ReversibleHashIO k, Refeable a) => Freezable (IntMap k a) where 
    5254    freeze m = do 
    5355        m' <- new_ 
    54         swapMaps m' m 
     56        swapMaps_ m' m 
    5557        return (Frozen m') 
    5658 
     
    304306    fromRef v 
    305307 
    306 swapMaps :: IntMap k a -> IntMap k a -> IO () 
    307 swapMaps (IntMap j1) (IntMap j2) = do 
     308swapMaps_ :: IntMap k a -> IntMap k a -> IO () 
     309swapMaps_ (IntMap j1) (IntMap j2) = do 
    308310    withForeignPtr j1 $ \p1 -> withForeignPtr j2 $ \p2 -> do 
    309311        v1 <- peek p1 
  • third-party/HsJudy/Judy/StrMap.hs

    r12301 r12505  
    55module Judy.StrMap ( 
    66    StrMap (..), 
    7     swapMaps, 
     7 
    88    freeze, 
    99    toRevList 
     
    4646    keys = keys_ 
    4747    mapToList = mapToList_ 
     48    swapMaps = swapMaps_ 
    4849 
    4950instance (Stringable k, Refeable a) => Freezable (StrMap k a) where 
    5051    freeze m = do 
    5152        m' <- new_ 
    52         swapMaps m' m 
     53        swapMaps_ m' m 
    5354        return (Frozen m') 
    5455 
     
    214215    fromRef v 
    215216 
    216 swapMaps :: StrMap k a -> StrMap k a -> IO () 
    217 swapMaps (StrMap j1) (StrMap j2) = do 
     217swapMaps_ :: StrMap k a -> StrMap k a -> IO () 
     218swapMaps_ (StrMap j1) (StrMap j2) = do 
    218219    withForeignPtr j1 $ \p1 -> withForeignPtr j2 $ \p2 -> do 
    219220        v1 <- peek p1 
  • third-party/HsJudy/Makefile

    r12103 r12505  
    33 
    44CC=$(GHC) 
    5 TESTS=TestBS TestJL TestJSL TestJHS TestHash TestIntMap TestStrMap 
     5TESTS=TestBS TestJL TestJSL TestJHS TestHash TestIntMap TestStrMap TestDM 
    66#HSC2HS=/usr/bin/hsc2hs 
    77HSC2HS=hsc2hs 
  • third-party/HsJudy/Makefile.static

    r12103 r12505  
    11# Makefile for static linkage 
    22 
    3 TESTS=TestBS TestJL TestJSL TestJHS TestHash TestIntMap TestStrMap 
     3TESTS=TestBS TestJL TestJSL TestJHS TestHash TestIntMap TestStrMap TestDM 
    44 
    55GHC=ghc # -debug 
  • third-party/HsJudy/tests/TestHash.hs

    r12103 r12505  
    1515 
    1616type M = J.Hash 
    17 swapMaps = J.swapMaps 
    1817 
    1918main = no_plan $ do 
  • third-party/HsJudy/tests/TestIntMap.hs

    r12103 r12505  
    9999    lookup 3 m2 .=> Just 42 
    100100 
    101     J.swapMaps m1 m2 
     101    swapMaps m1 m2 
    102102    lookup 2 m1 .=> Just 42 
    103103    lookup 2 m2 .=> Just 3 
  • third-party/HsJudy/tests/TestStrMap.hs

    r12103 r12505  
    1515 
    1616type M = J.StrMap 
    17 swapMaps = J.swapMaps 
    1817 
    1918newStringInt = new :: IO (M String Int)