Changeset 12024 for third-party

Show
Ignore:
Timestamp:
08/09/06 07:28:26 (2 years ago)
Author:
cmarcelo
Message:

HsJudy?:
* Renames: (Map -> Hash, Map2 -> IntMap?, MapSL -> StrMap?)
* Extracting Stringable to a separate file.
* IntMap?: Special implementations for n=1 of takeFirst and takeLast.
* StrMap?: Include a new toRevList and backend for

Location:
third-party/HsJudy
Files:
2 added
5 modified
5 moved

Legend:

Unmodified
Added
Removed
  • third-party/HsJudy/HsJudy.cabal

    r11676 r12024  
    77maintainer:          Caio Marcelo de Oliveira Filho <cmarcelo@gmail.com> 
    88build-depends:       base 
    9 exposed-modules:     Judy.BitSet Judy.Freeze Judy.Map Judy.Map2 Judy.MapSL Judy.CollectionsM Judy.HashIO Judy.Refeable 
     9exposed-modules:     Judy.BitSet Judy.Freeze Judy.Hash Judy.IntMap Judy.StrMap Judy.CollectionsM Judy.HashIO Judy.Refeable Judy.Stringable 
    1010other-modules:       Judy.Private Judy.MiniGC 
    1111extensions:          ForeignFunctionInterface 
  • third-party/HsJudy/Judy/Hash.hs

    r11716 r12024  
    11{-# OPTIONS -fallow-undecidable-instances -fallow-incoherent-instances #-} 
    22 
    3 module Judy.Map ( 
     3module Judy.Hash ( 
    44    Stringable (..), 
    5     Map (..), 
     5    Hash (..), 
    66 
    77    -- FIXME: need to move to MapM api 
     
    1919import Foreign 
    2020import Data.Maybe (fromJust) 
    21 import qualified Data.ByteString as B 
    2221 
    2322import Judy.Private 
     
    2524import Judy.Refeable 
    2625import Judy.Freeze 
     26import Judy.Stringable 
    2727import qualified Judy.MiniGC as GC 
    2828 
    2929import Prelude hiding (map) 
    3030 
    31 -- Refeable is now in Judy/Refeable.hs 
    32  
    33 {- Stringable stuff -}  
    34 -- TODO: Work on Storable to let any Storable type be 
    35 -- "stringable" i.e., used as Key. 
    36  
    37 -- TODO: Support using ByteStrings, seems to be trivial with Stringable, just instantiate? 
    38  
    39 class Stringable k where 
    40     toString :: k -> String 
    41     fromString :: String -> k 
    42  
    43     useAsCS :: k -> (CString -> IO a) -> IO a 
    44     useAsCS k = withCAString (toString k) 
    45     useAsCSLen :: k -> (CStringLen -> IO a) -> IO a 
    46     useAsCSLen k = withCAStringLen (toString k) 
    47  
    48     copyCS :: CString -> IO k 
    49     copyCS c = peekCAString c >>= return . fromString 
    50     copyCSLen :: CStringLen -> IO k 
    51     copyCSLen c = peekCAStringLen c >>= return . fromString 
    52  
    53 instance Stringable String where 
    54     toString = id 
    55     fromString = id 
    56  
    57 instance Stringable B.ByteString where 
    58     toString = undefined 
    59     fromString = undefined 
    60  
    61     useAsCS = B.useAsCString  
    62     useAsCSLen = B.useAsCStringLen 
    63  
    64     copyCS = B.copyCString 
    65     copyCSLen = B.copyCStringLen 
    66  
    67  
    68 --instance Stringable Int where 
    69 --    toString = show 
    70 --    fromString = read 
    71 {- End of Stringable stuff -} 
    72  
    7331-- FIXME: really necessary/useful restrict types here? 
    74 newtype (Stringable k, Refeable a) => Map k a = Map { judy :: ForeignPtr JudyHS } 
     32newtype (Stringable k, Refeable a) => Hash k a = Hash { judy :: ForeignPtr JudyHS } 
    7533    deriving (Eq, Ord, Typeable) 
    7634 
    77 instance (Stringable k, Refeable a) => CM.MapM (Map k a) k a IO where 
     35instance (Stringable k, Refeable a) => CM.MapM (Hash k a) k a IO where 
    7836    new = new_ 
    7937    delete = delete_ 
     
    8846    mapToList = mapToList_ 
    8947 
    90 instance (Stringable k, Refeable a) => Freezable (Map k a) where 
     48instance (Stringable k, Refeable a) => Freezable (Hash k a) where 
    9149    freeze m = do 
    9250        m' <- new_ 
     
    9452        return (Frozen m') 
    9553 
    96 instance (Stringable k, Refeable a) => CM.MapF (Frozen (Map k a)) k a where 
     54instance (Stringable k, Refeable a) => CM.MapF (Frozen (Hash k a)) k a where 
    9755    memberF k (Frozen m) = unsafePerformIO $ member_ k m 
    9856    lookupF k (Frozen m) = unsafePerformIO $ lookup_ k m 
     
    10058    toListF (Frozen m) = unsafePerformIO $ toList_ m 
    10159 
    102 instance Show (Map k a) where 
    103     show (Map j) = "<Map " ++ show j ++ ">" 
     60instance Show (Hash k a) where 
     61    show (Hash j) = "<Hash " ++ show j ++ ">" 
    10462 
    10563foreign import ccall "wrapper" mkFin :: (Ptr JudyHS -> IO ()) -> IO (FunPtr (Ptr JudyHS -> IO ())) 
     
    10967    when need $ do 
    11068        j_ <- newForeignPtr_ j 
    111         es <- rawElems (Map j_) 
     69        es <- rawElems (Hash j_) 
    11270        mapM_ GC.freeRef es 
    11371    v <- judyHSFreeArray j judyError 
     
    11775rawElems = internalMap $ \r _ _ -> peek r 
    11876 
    119 dummy :: Refeable a => Map k a -> a 
     77dummy :: Refeable a => Hash k a -> a 
    12078dummy = undefined 
    12179 
    12280 
    123 new_ :: Refeable a => IO (Map k a) 
     81new_ :: Refeable a => IO (Hash k a) 
    12482new_ = do 
    12583    fp <- mallocForeignPtr 
    12684    withForeignPtr fp $ flip poke nullPtr 
    127     m <- return $ Map fp 
     85    m <- return $ Hash fp 
    12886 
    12987    finalize' <- mkFin $ finalize $ needGC (dummy m) 
     
    13189    return m 
    13290 
    133 insert_ :: (Stringable k, Refeable a) => k -> a -> Map k a -> IO () 
    134 insert_ k v (Map j) = withForeignPtr j $ \j' -> do 
     91insert_ :: (Stringable k, Refeable a) => k -> a -> Hash k a -> IO () 
     92insert_ k v (Hash j) = withForeignPtr j $ \j' -> do 
    13593    useAsCSLen k $ \(cp, len) -> do 
    13694        -- TODO: maybe there's a better way to convert Int -> Value 
     
    143101                return () 
    144102 
    145 alter_ :: (Eq a, Stringable k, Refeable a) => (Maybe a -> Maybe a) -> k -> Map k a -> IO (Maybe a) 
    146 alter_ f k m@(Map j) = do 
     103alter_ :: (Eq a, Stringable k, Refeable a) => (Maybe a -> Maybe a) -> k -> Hash k a -> IO (Maybe a) 
     104alter_ f k m@(Hash j) = do 
    147105    j' <- withForeignPtr j peek 
    148106    useAsCSLen k $ \(cp, len) -> do 
     
    166124                             else return fv 
    167125 
    168 lookup_ :: (Stringable k, Refeable a) => k -> Map k a -> IO (Maybe a) 
    169 lookup_ k (Map j) = do 
     126lookup_ :: (Stringable k, Refeable a) => k -> Hash k a -> IO (Maybe a) 
     127lookup_ k (Hash j) = do 
    170128    j' <- withForeignPtr j peek 
    171129    useAsCSLen k $ \(cp, len) -> do 
     
    178136                return $ Just v 
    179137 
    180 member_ :: Stringable k => k -> Map k a -> IO Bool 
    181 member_ k (Map j) = do 
     138member_ :: Stringable k => k -> Hash k a -> IO Bool 
     139member_ k (Hash j) = do 
    182140    j' <- withForeignPtr j peek 
    183141    useAsCSLen k $ \(cp, len) -> do 
     
    185143        return $ r /= nullPtr 
    186144 
    187 delete_ :: Stringable k => k -> Map k a -> IO Bool 
    188 delete_ k m@(Map j) = withForeignPtr j $ \j' -> do 
     145delete_ :: Stringable k => k -> Hash k a -> IO Bool 
     146delete_ k m@(Hash j) = withForeignPtr j $ \j' -> do 
    189147    j'' <- peek j' 
    190148    useAsCSLen k $ \(cp, len) -> do 
     
    199157        return $ r /= 0 
    200158 
    201 -- FIXME: may use MapIter type to enforce some safety in its use? 
    202 newtype MapIter = MapIter { iter :: ForeignPtr JudyHSIter } 
     159-- FIXME: may use HashIter type to enforce some safety in its use? 
     160newtype HashIter = HashIter { iter :: ForeignPtr JudyHSIter } 
    203161    deriving (Eq, Ord, Typeable) 
    204162 
    205 instance Show MapIter where 
    206     show (MapIter i) = "<Iter "++ show i ++ ">" 
    207  
    208  
    209 newIter :: IO (MapIter) 
     163instance Show HashIter where 
     164    show (HashIter i) = "<Iter "++ show i ++ ">" 
     165 
     166 
     167newIter :: IO (HashIter) 
    210168newIter = do 
    211169    fp <- mallocForeignPtr 
    212170--    addForeignPtrFinalizer judyHSIter_free_ptr fp 
    213171    withForeignPtr fp $ flip poke nullPtr 
    214     return $ MapIter fp 
    215  
    216 fromList_ :: (Stringable k, Refeable a) => [(k,a)] -> IO (Map k a) 
     172    return $ HashIter fp 
     173 
     174fromList_ :: (Stringable k, Refeable a) => [(k,a)] -> IO (Hash k a) 
    217175fromList_ xs = do 
    218176    m <- new_ 
     
    220178    return m 
    221179 
    222 internalMap :: (Ptr Value -> Ptr CString -> Ptr Value -> IO b) -> Map k a -> IO [b] 
    223 internalMap f (Map j) = do 
     180internalMap :: (Ptr Value -> Ptr CString -> Ptr Value -> IO b) -> Hash k a -> IO [b] 
     181internalMap f (Hash j) = do 
    224182    jj <- withForeignPtr j peek 
    225     (MapIter i) <- newIter 
     183    (HashIter i) <- newIter 
    226184    withForeignPtr i $ \ii -> alloca $ \cp -> alloca $ \len -> do 
    227185        poke len 0 
     
    235193        loop judyHSIterFirst [] 
    236194 
    237 mapToList_ :: (Stringable k, Refeable a) => (k -> a -> b) -> Map k a -> IO [b] 
     195mapToList_ :: (Stringable k, Refeable a) => (k -> a -> b) -> Hash k a -> IO [b] 
    238196mapToList_ f = internalMap $ \r cp len -> do 
    239197    l <- peek len 
     
    244202    return $ f v d' 
    245203 
    246 toList_ :: (Stringable k, Refeable a) => Map k a -> IO [(k,a)] 
     204toList_ :: (Stringable k, Refeable a) => Hash k a -> IO [(k,a)] 
    247205toList_ = mapToList_ $ \k a -> (k, a) 
    248206 
    249 elems_ :: Refeable a => Map k a -> IO [a] 
     207elems_ :: Refeable a => Hash k a -> IO [a] 
    250208elems_ = internalMap $ \r _ _ -> do 
    251209    d <- peek r 
    252210    fromRef d 
    253211 
    254 keys_ :: Stringable k => Map k a -> IO [k] 
     212keys_ :: Stringable k => Hash k a -> IO [k] 
    255213keys_ = internalMap $ \_ cp len -> do 
    256214    l <- peek len 
     
    260218 
    261219 
    262 swapMaps :: Map k a -> Map k a -> IO () 
    263 swapMaps (Map j1) (Map j2) = do 
     220swapMaps :: Hash k a -> Hash k a -> IO () 
     221swapMaps (Hash j1) (Hash j2) = do 
    264222    withForeignPtr j1 $ \p1 -> withForeignPtr j2 $ \p2 -> do 
    265223        v1 <- peek p1 
  • third-party/HsJudy/Judy/IntMap.hs

    r11917 r12024  
    11{-# OPTIONS -fallow-undecidable-instances -fallow-incoherent-instances #-} 
    22 
    3 module Judy.Map2 ( 
    4     Map2 (..), 
     3module Judy.IntMap ( 
     4    IntMap (..), 
    55    swapMaps, freeze, 
    66    toRevList, 
     
    3131import Prelude hiding (map) 
    3232 
    33 newtype (ReversibleHashIO k, Refeable a) => Map2 k a = Map2 { judy :: ForeignPtr JudyL } 
     33newtype (ReversibleHashIO k, Refeable a) => IntMap k a = IntMap { judy :: ForeignPtr JudyL } 
    3434    deriving (Eq, Ord, Typeable) 
    3535 
    36 instance (ReversibleHashIO k, Refeable a) => CM.MapM (Map2 k a) k a IO where 
     36instance (ReversibleHashIO k, Refeable a) => CM.MapM (IntMap k a) k a IO where 
    3737    new = new_ 
    3838    delete = delete_ 
     
    4747    mapToList = mapToList_ 
    4848 
    49 instance (ReversibleHashIO k, Refeable a) => Freezable (Map2 k a) where 
     49instance (ReversibleHashIO k, Refeable a) => Freezable (IntMap k a) where 
    5050    freeze m = do 
    5151        m' <- new_ 
     
    5353        return (Frozen m') 
    5454 
    55 instance (ReversibleHashIO k, Refeable a) => CM.MapF (Frozen (Map2 k a)) k a where 
     55instance (ReversibleHashIO k, Refeable a) => CM.MapF (Frozen (IntMap k a)) k a where 
    5656    memberF k (Frozen m) = unsafePerformIO $ member_ k m 
    5757    lookupF k (Frozen m) = unsafePerformIO $ lookup_ k m 
     
    5959    toListF (Frozen m) = unsafePerformIO $ toList_ m 
    6060 
    61 instance Show (Map2 k a) where 
    62     show (Map2 j) = "<Map2 " ++ show j ++ ">" 
     61instance Show (IntMap k a) where 
     62    show (IntMap j) = "<IntMap " ++ show j ++ ">" 
    6363 
    6464 
     
    7070    when need $ do 
    7171        j_ <- newForeignPtr_ j 
    72         es <- rawElems (Map2 j_) 
     72        es <- rawElems (IntMap j_) 
    7373        mapM_ GC.freeRef es 
    7474    v <- judyLFreeArray j judyError 
     
    7878rawElems = internalMap $ \r _ -> peek r 
    7979 
    80 dummy :: Refeable a => Map2 k a -> a 
     80dummy :: Refeable a => IntMap k a -> a 
    8181dummy = undefined 
    8282 
    83 new_ :: Refeable a => IO (Map2 k a) 
     83new_ :: Refeable a => IO (IntMap k a) 
    8484new_ = do 
    8585    fp <- mallocForeignPtr 
    8686    withForeignPtr fp $ flip poke nullPtr 
    87     m <- return $ Map2 fp 
     87    m <- return $ IntMap fp 
    8888 
    8989    finalize' <- mkFin $ finalize $ needGC (dummy m) 
     
    9191    return m 
    9292 
    93 insert_ :: (ReversibleHashIO k, Refeable a) => k -> a -> Map2 k a -> IO () 
    94 insert_ k v (Map2 j) = withForeignPtr j $ \j' -> do 
     93insert_ :: (ReversibleHashIO k, Refeable a) => k -> a -> IntMap k a -> IO () 
     94insert_ k v (IntMap j) = withForeignPtr j $ \j' -> do 
    9595    k' <- hashIO k 
    9696    r <- judyLIns j' k' judyError 
     
    9999        else do { v' <- toRef v; poke r v'; return () } 
    100100 
    101 alter_ :: (Eq a, ReversibleHashIO k, Refeable a) => (Maybe a -> Maybe a) -> k -> Map2 k a -> IO (Maybe a) 
    102 alter_ f k m@(Map2 j) = do 
     101alter_ :: (Eq a, ReversibleHashIO k, Refeable a) => (Maybe a -> Maybe a) -> k -> IntMap k a -> IO (Maybe a) 
     102alter_ f k m@(IntMap j) = do 
    103103    j' <- withForeignPtr j peek 
    104104    k' <- hashIO k 
     
    122122                         else return fv 
    123123 
    124 lookup_ :: (ReversibleHashIO k, Refeable a) => k -> Map2 k a -> IO (Maybe a) 
    125 lookup_ k (Map2 j) = do 
     124lookup_ :: (ReversibleHashIO k, Refeable a) => k -> IntMap k a -> IO (Maybe a) 
     125lookup_ k (IntMap j) = do 
    126126    j' <- withForeignPtr j peek 
    127127    k' <- hashIO k 
     
    131131        else do { v' <- peek r; v <- fromRef v'; return $ Just v } 
    132132 
    133 member_ :: ReversibleHashIO k => k -> Map2 k a -> IO Bool 
    134 member_ k (Map2 j) = do 
     133member_ :: ReversibleHashIO k => k -> IntMap k a -> IO Bool 
     134member_ k (IntMap j) = do 
    135135    j' <- withForeignPtr j peek 
    136136    k' <- hashIO k 
     
    138138    return $ r /= nullPtr 
    139139 
    140 delete_ :: ReversibleHashIO k => k -> Map2 k a -> IO Bool 
    141 delete_ k m@(Map2 j) = withForeignPtr j $ \j' -> do 
     140delete_ :: ReversibleHashIO k => k -> IntMap k a -> IO Bool 
     141delete_ k m@(IntMap j) = withForeignPtr j $ \j' -> do 
    142142    j'' <- peek j' 
    143143    k' <- hashIO k 
     
    152152    return $ r /= 0 
    153153 
    154 size :: Map2 k a -> IO Int 
    155 size (Map2 j) = withForeignPtr j $ \j' -> do 
     154size :: IntMap k a -> IO Int 
     155size (IntMap j) = withForeignPtr j $ \j' -> do 
    156156    jj <- peek j' 
    157157    r <- judyLCount jj 0 (-1) judyError 
     
    160160 
    161161 
    162 fromList_ :: (ReversibleHashIO k, Refeable a) => [(k,a)] -> IO (Map2 k a) 
     162fromList_ :: (ReversibleHashIO k, Refeable a) => [(k,a)] -> IO (IntMap k a) 
    163163fromList_ xs = do 
    164164    m <- new_ 
     
    166166    return m 
    167167 
    168 internalMap' :: (Ptr Value -> Ptr Value -> IO b) -> Map2 k a -> IO [b] 
    169 internalMap' f (Map2 j) = do 
     168internalMap' :: (Ptr Value -> Ptr Value -> IO b) -> IntMap k a -> IO [b] 
     169internalMap' f (IntMap j) = do 
    170170    jj <- withForeignPtr j peek 
    171171    alloca $ \vp -> do 
     
    179179        loop judyLFirst [] 
    180180 
    181 withLast :: (Ptr Value -> Ptr Value -> IO b) -> Int -> Map2 k a -> IO [b] 
    182 withLast f n (Map2 j) = do 
     181withLast :: (Ptr Value -> Ptr Value -> IO b) -> Int -> IntMap k a -> IO [b] 
     182withLast f n (IntMap j) = do 
    183183    jj <- withForeignPtr j peek 
    184184    alloca $ \vp -> do 
     
    193193        loop judyLLast [] n 
    194194 
     195takeLast :: (ReversibleHashIO k, Refeable a) => Int -> IntMap k a -> IO [(k,a)] 
     196-- this case is here as a tentative to optimize, in case GHC doesn't do it 
     197takeLast 1 (IntMap j) = do 
     198    jj <- withForeignPtr j peek 
     199    alloca $ \vp -> do 
     200        poke vp (-1) 
     201        r <- judyLLast jj vp judyError 
     202        if r == nullPtr 
     203            then return [] 
     204            else do k <- peek vp >>= unHashIO 
     205                    v <- peek r  >>= fromRef 
     206                    return [(k,v)] 
    195207-- FIXME: use a less obscure syntax =P 
    196 takeLast :: (ReversibleHashIO k, Refeable a) => Int -> Map2 k a -> IO [(k,a)] 
    197208takeLast n m = do 
    198209    withLast (\r vp -> do { k <- peek vp >>= unHashIO; v <- peek r >>= fromRef; return (k,v) }) n m 
    199210 
    200 takeLastElems :: Refeable a => Int -> Map2 k a -> IO [a] 
     211takeLastElems :: Refeable a => Int -> IntMap k a -> IO [a] 
    201212takeLastElems n m = do 
    202213    withLast (\r _ -> peek r >>= fromRef) n m 
     
    205216 
    206217 
    207 withFirst :: (Ptr Value -> Ptr Value -> IO b) -> Int -> Map2 k a -> IO [b] 
    208 withFirst f n (Map2 j) = do 
     218withFirst :: (Ptr Value -> Ptr Value -> IO b) -> Int -> IntMap k a -> IO [b] 
     219withFirst f n (IntMap j) = do 
    209220    jj <- withForeignPtr j peek 
    210221    alloca $ \vp -> do 
     
    223234 
    224235 
     236takeFirst :: (ReversibleHashIO k, Refeable a) => Int -> IntMap k a -> IO [(k,a)] 
     237-- this case is here as a tentative to optimize, in case GHC doesn't do it 
     238takeFirst 1 (IntMap j) = do 
     239    jj <- withForeignPtr j peek 
     240    alloca $ \vp -> do 
     241        poke vp (0 :: Value) 
     242        r <- judyLFirst jj vp judyError 
     243        if r == nullPtr 
     244            then return [] 
     245            else do k <- peek vp >>= unHashIO 
     246                    v <- peek r  >>= fromRef 
     247                    return [(k,v)] 
    225248-- FIXME: use a less obscure syntax =P 
    226 takeFirst :: (ReversibleHashIO k, Refeable a) => Int -> Map2 k a -> IO [(k,a)] 
    227249takeFirst n m = do 
    228250    l <- withFirst (\r vp -> do { k <- peek vp >>= unHashIO; v <- peek r >>= fromRef; return (k,v) }) n m 
    229251    return $ reverse l 
    230252 
    231 takeFirstElems :: Refeable a => Int -> Map2 k a -> IO [a] 
     253takeFirstElems :: Refeable a => Int -> IntMap k a -> IO [a] 
    232254takeFirstElems n m = do 
    233255    l <- withFirst (\r _ -> peek r >>= fromRef) n m 
    234256    return $ reverse l 
    235257 
    236 internalMap :: (Ptr Value -> Ptr Value -> IO b) -> Map2 k a -> IO [b] 
    237 internalMap f (Map2 j) = do 
     258internalMap :: (Ptr Value -> Ptr Value -> IO b) -> IntMap k a -> IO [b] 
     259internalMap f (IntMap j) = do 
    238260    jj <- withForeignPtr j peek 
    239261    alloca $ \vp -> do 
     
    248270                          -- to get ordered list right. 
    249271 
    250 mapToList_ :: (ReversibleHashIO k, Refeable a) => (k -> a -> b) -> Map2 k a -> IO [b] 
     272mapToList_ :: (ReversibleHashIO k, Refeable a) => (k -> a -> b) -> IntMap k a -> IO [b] 
    251273mapToList_ f = internalMap $ \r vp -> do 
    252274    k <- peek vp 
     
    256278    return $ f k' v' 
    257279 
    258 mapToRevList_ :: (ReversibleHashIO k, Refeable a) => (k -> a -> b) -> Map2 k a -> IO [b] 
     280mapToRevList_ :: (ReversibleHashIO k, Refeable a) => (k -> a -> b) -> IntMap k a -> IO [b] 
    259281mapToRevList_ f = internalMap' $ \r vp -> do 
    260282    k <- peek vp 
     
    264286    return $ f k' v' 
    265287 
    266 toList_ :: (ReversibleHashIO k, Refeable a) => Map2 k a -> IO [(k,a)] 
     288toList_ :: (ReversibleHashIO k, Refeable a) => IntMap k a -> IO [(k,a)] 
    267289toList_ = mapToList_ $ \k a -> (k,a) 
    268290 
    269 toRevList :: (ReversibleHashIO k, Refeable a) => Map2 k a -> IO [(k,a)] 
     291toRevList :: (ReversibleHashIO k, Refeable a) => IntMap k a -> IO [(k,a)] 
    270292toRevList = mapToRevList_ $ \k a -> (k,a) 
    271293 
    272 keys_ :: ReversibleHashIO k => Map2 k a -> IO [k] 
     294keys_ :: ReversibleHashIO k => IntMap k a -> IO [k] 
    273295keys_ = internalMap $ \_ vp -> do 
    274296    k <- peek vp 
    275297    unHashIO k 
    276298 
    277 elems_ :: Refeable a => Map2 k a -> IO [a] 
     299elems_ :: Refeable a => IntMap k a -> IO [a] 
    278300elems_ = internalMap $ \r _ -> do 
    279301    v <- peek r 
    280302    fromRef v 
    281303 
    282 swapMaps :: Map2 k a -> Map2 k a -> IO () 
    283 swapMaps (Map2 j1) (Map2 j2) = do 
     304swapMaps :: IntMap k a -> IntMap k a -> IO () 
     305swapMaps (IntMap j1) (IntMap j2) = do 
    284306    withForeignPtr j1 $ \p1 -> withForeignPtr j2 $ \p2 -> do 
    285307        v1 <- peek p1 
  • third-party/HsJudy/Judy/StrMap.hs

    r11917 r12024  
    11{-# OPTIONS -fallow-undecidable-instances -fallow-incoherent-instances #-} 
    22 
    3 module Judy.MapSL ( 
    4     MapSL (..), 
    5     swapMaps, freeze 
     3module Judy.StrMap ( 
     4    StrMap (..), 
     5    swapMaps, 
     6    freeze, 
     7    toRevList 
    68) where 
    79 
     
    2123import qualified Judy.CollectionsM as CM 
    2224import Judy.Refeable 
    23 import Judy.Map (Stringable (..)) 
     25import Judy.Stringable 
    2426import Judy.Freeze 
    2527import qualified Judy.MiniGC as GC 
     
    2729import Prelude hiding (map) 
    2830 
    29 newtype (Stringable k, Refeable a) => MapSL k a = MapSL { judy :: ForeignPtr JudySL } 
     31newtype (Stringable k, Refeable a) => StrMap k a = StrMap { judy :: ForeignPtr JudySL } 
    3032    deriving (Eq, Ord, Typeable) 
    3133 
    32 instance (Stringable k, Refeable a) => CM.MapM (MapSL k a) k a IO where 
     34instance (Stringable k, Refeable a) => CM.MapM (StrMap k a) k a IO where 
    3335    new = new_ 
    3436    delete = delete_ 
     
    4345    mapToList = mapToList_ 
    4446 
    45 instance (Stringable k, Refeable a) => Freezable (MapSL k a) where 
     47instance (Stringable k, Refeable a) => Freezable (StrMap k a) where 
    4648    freeze m = do 
    4749        m' <- new_ 
     
    4951        return (Frozen m') 
    5052 
    51 instance (Stringable k, Refeable a) => CM.MapF (Frozen (MapSL k a)) k a where 
     53instance (Stringable k, Refeable a) => CM.MapF (Frozen (StrMap k a)) k a where 
    5254    memberF k (Frozen m) = unsafePerformIO $ member_ k m 
    5355    lookupF k (Frozen m) = unsafePerformIO $ lookup_ k m 
     
    5557    toListF (Frozen m) = unsafePerformIO $ toList_ m 
    5658 
    57 instance Show (MapSL k a) where 
    58     show (MapSL j) = "<MapSL " ++ show j ++ ">" 
     59instance Show (StrMap k a) where 
     60    show (StrMap j) = "<StrMap " ++ show j ++ ">" 
    5961 
    6062foreign import ccall "wrapper" mkFin :: (Ptr JudySL -> IO ()) -> IO (FunPtr (Ptr JudySL -> IO ())) 
     
    6567    when need $ do 
    6668        j_ <- newForeignPtr_ j 
    67         es <- rawElems (MapSL j_) 
     69        es <- rawElems (StrMap j_) 
    6870        mapM_ GC.freeRef es 
    6971    v <- judySLFreeArray j judyError 
     
    7375rawElems = internalMap $ \r _ -> peek r 
    7476 
    75 dummy :: Refeable a => MapSL k a -> a 
     77dummy :: Refeable a => StrMap k a -> a 
    7678dummy = undefined 
    7779 
    78 new_ :: Refeable a => IO (MapSL k a) 
     80new_ :: Refeable a => IO (StrMap k a) 
    7981new_ = do 
    8082    fp <- mallocForeignPtr 
    8183    withForeignPtr fp $ flip poke nullPtr