Changeset 11831 for third-party

Show
Ignore:
Timestamp:
07/31/06 08:11:22 (2 years ago)
Author:
cmarcelo
Message:

* Judy.Map2: toRevList. And TODO updates.

Location:
third-party/HsJudy
Files:
4 modified

Legend:

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

    r11716 r11831  
    33module Judy.Map2 ( 
    44    Map2 (..), 
    5     swapMaps, freeze 
     5    swapMaps, freeze, toRevList 
    66) where 
    77 
     
    160160--    return $ r 
    161161 
     162 
     163internalMap' :: (Ptr Value -> Ptr Value -> IO b) -> Map2 k a -> IO [b] 
     164internalMap' f (Map2 j) = do 
     165    jj <- withForeignPtr j peek 
     166    alloca $ \vp -> do 
     167        poke vp (0 :: Value) 
     168        let loop act xs = do 
     169            r <- act jj vp judyError 
     170            if r == nullPtr 
     171                then return xs 
     172                else do x <- f r vp 
     173                        loop judyLNext (x:xs) 
     174        loop judyLFirst [] 
     175 
    162176internalMap :: (Ptr Value -> Ptr Value -> IO b) -> Map2 k a -> IO [b] 
    163177internalMap f (Map2 j) = do 
     
    171185                else do x <- f r vp 
    172186                        loop judyLPrev (x:xs) 
    173         loop judyLLast [] 
     187        loop judyLLast [] -- Because of list concat we go backwards 
     188                          -- to get ordered list right. 
    174189 
    175190mapToList_ :: (ReversibleHashIO k, Refeable a) => (k -> a -> b) -> Map2 k a -> IO [b] 
     
    181196    return $ f k' v' 
    182197 
     198mapToRevList_ :: (ReversibleHashIO k, Refeable a) => (k -> a -> b) -> Map2 k a -> IO [b] 
     199mapToRevList_ f = internalMap' $ \r vp -> do 
     200    k <- peek vp 
     201    k' <- unHashIO k 
     202    v <- peek r 
     203    v' <- fromRef v 
     204    return $ f k' v' 
     205 
    183206toList_ :: (ReversibleHashIO k, Refeable a) => Map2 k a -> IO [(k,a)] 
    184207toList_ = mapToList_ $ \k a -> (k,a) 
     208 
     209toRevList :: (ReversibleHashIO k, Refeable a) => Map2 k a -> IO [(k,a)] 
     210toRevList = mapToRevList_ $ \k a -> (k,a) 
    185211 
    186212keys_ :: ReversibleHashIO k => Map2 k a -> IO [k] 
     
    201227        poke p1 v2 
    202228        poke p2 v1 
    203  
    204  
    205  
    206  
    207  
  • third-party/HsJudy/TODO

    r11716 r11831  
    11# TODO 
    2 - Use Judy to implement Pugs IHash substitute. (First patch done, but it's old by now) 
     2- Use Judy for Hash and Array in Pugs. Maybe creating some special 
     3  operators for Judy.Map2 to be used for Array (think shift and pop). 
    34- CollectionsM: complete the subset of MapM and uncomment/complete CollectionM. 
    45- See if needGC hack can be improved. It seems its eating CPU time. 
    56 
    67- First RBR test: 1/3 running time when using MapL (via Map2). Not sure 
    7 if the results are correct (they seem to be). 
    8 - Should I call MapSL and Map2 just Map? 
     8  if the results are correct (they seem to be). Check with Ketil about usage 
     9  of Map2, if its enough. 
     10 
     11- Names names names 
     12  - Idea: Map2 -> IntMap 
     13  - Should I call MapSL just Map too? 
     14 
    915- Other missing malloc error checking 
    1016- Tests that stress MiniGC (w/ two maps at same time would be nice too) 
     17 
    1118- Check how GHC do interning 
     19- Check how's sparse array implementation of Parrot. 
    1220 
    13 # "CRAZY" BUGS 
    14 - Dummy/Refeable Bug: need to ask in #haskell and reply Simon's email. 
    15 X Bug on HSIter stuff when use a lot of memory. (One of them is solved. Need to GC now.) 
     21# "CRAZY" BUGS (X means "solved") 
     22X Dummy/Refeable Bug: need to ask in #haskell and reply Simon's email. 
     23  It dissapeared recently. Dunno the reason. 
     24X Bug on HSIter stuff when use a lot of memory. 
    1625X Finalizer may be not working right => test with sequencing a lot of operations 
    17   causes error in GHC runtime. (seems to be fixed by having ONLY ONE gc for everyone) 
     26  causes error in GHC runtime. (seems to be fixed by having ONLY ONE gc 
     27  for everyone) 
    1828 
    1929 
     
    2535  on the page (are they updated?). 
    2636- Implementations specific to unboxed values like Int and Double: Int seems to 
    27   be ok now, but Double and other unboxed still need to check 
     37  be ok now, but Double and other unboxable still need to check 
    2838 
    2939- Discuss APIs 
    30 -- Unbounded arrays: see Bulat work on this 
     40-- Unbounded arrays: see Bulat work on this. 
    3141 
    3242- Refeable vs. HashIO => unify? 
     
    7080Bulat says "sorry, i don't think so. especially for Arrays ;)" 
    7181 
     82Judy is useful for applications for (very-)sparse Arrays, which is Pugs' case. 
     83 
  • third-party/HsJudy/tests/CheckDup.results

    r11694 r11831  
    17176 Judy.MapSL     ByteString Int     0.642 
    18187 Data.HashTable String Int         2.790 
    19 8 Data.HashTable String Int         3.809  
     198 Data.HashTable ByteString Int     3.809  
    2020 
  • third-party/HsJudy/tests/TestMap2.hs

    r11694 r11831  
    2020    testSwapMaps 
    2121    testAlter 
     22    testRevList 
    2223 
    2324testSimple = do 
     
    6263    say "Elems" 
    6364    s <- new :: IO (Map2 Int Int) 
    64     elems s .-= [] 
     65    elems s .=> [] 
    6566    insert 3 42 s 
    6667    insert 37 1 s 
    6768    insert 0 2 s 
    68     elems s .-= [1,2,42] 
     69    elems s .=> [2,42,1] 
    6970 
    7071testKeys = do 
     
    7576    insert 37 1 s 
    7677    insert 0 2 s 
    77     keys s .-= [0,3,37] 
     78    keys s .=> [0,3,37] 
    7879    delete 37 s 
    7980    delete 15 s 
    80     keys s .-= [0,3] 
     81    keys s .=> [0,3] 
    8182 
    8283testStringValue = do 
     
    8788    insert 22 "string" s 
    8889    insert 59 "i am not a number" s 
    89     toList s    .-= [(22, "string"), (59,"i am not a number")]  
     90    toList s    .=> [(22, "string"), (59,"i am not a number")]  
    9091    member 22 s .=> True 
    9192 
     
    102103    insert 23 "string" s 
    103104    insert 59 "i am not a number" s 
    104     toList s    .-= [(22, "string"), (23, "string"), (59,"i am not a number")]  
     105    toList s .=> [(22, "string"), (23, "string"), (59,"i am not a number")]  
    105106    member 22 s .=> True 
    106107 
     
    138139    lookup 1 m .=> Nothing 
    139140 
     141testRevList = do 
     142    say "RevList" 
     143    let l = [(1,2), (2,3), (4,5)] 
     144    m <- fromList l :: IO (J.Map2 Int Int) 
     145    J.toRevList m .=> reverse l 
     146 
     147    insert 3 10 m 
     148    J.toRevList m .=> reverse (sort $ (3,10):l) 
     149 
    140150-- TODO: test some crazy haskell type as value (to check stableptrs) 
    141151