Changeset 12571 for third-party

Show
Ignore:
Timestamp:
08/21/06 20:01:28 (2 years ago)
Author:
cmarcelo
Message:

* HsJudy?: Fixes usage for negative numbers as keys and values.

Location:
third-party/HsJudy
Files:
3 modified

Legend:

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

    r12103 r12571  
    1010 
    1111import Judy.Private 
     12import GHC.Exts (unsafeCoerce#) 
    1213 
    1314class HashIO a where 
     
    2223instance Enum a => UniqueHashIO a where 
    2324instance Enum a => HashIO a where 
    24     hashIO = return . toEnum . fromEnum 
     25    hashIO = return . unsafeCoerce# . fromEnum 
    2526instance Enum a => ReversibleHashIO a where 
    26     unHashIO = return . toEnum . fromEnum 
     27    unHashIO = return . toEnum . unsafeCoerce# 
    2728 
    2829 
  • third-party/HsJudy/Judy/Refeable.hs

    r12204 r12571  
    1313import Judy.Private 
    1414import qualified Judy.MiniGC as GC 
    15  
     15import GHC.Exts (unsafeCoerce#) 
    1616 
    1717-- FIXME: It results in an illegal instruction if I take the "Dummy a" 
     
    3535 
    3636instance Refeable Int where 
    37     toRef i = return $ toEnum i 
    38     fromRef v = return $ fromEnum v 
     37    toRef i = return $ unsafeCoerce# i 
     38    fromRef v = return $ unsafeCoerce# v 
    3939    needGC _ = False 
    4040 
  • third-party/HsJudy/tests/TestIntMap.hs

    r12505 r12571  
    1616    insert 1 42 s 
    1717    lookup 1 s    .=> Just 42 
     18 
     19t "Negative values" $ do 
     20    s <- new :: IO (IntMap Int Int) 
     21    insert 1 (-1) s 
     22    insert 2 (-2) s 
     23    lookup 1 s      .=> Just (-1) 
     24    lookup 2 s      .=> Just (-2) 
    1825 
    1926t "Delete" $ do 
     
    161168    J.takeLast 1 m       .=> [(98,198)] 
    162169 
     170t "Negative keys" $ do 
     171    s <- new :: IO (IntMap Int Int) 
     172    insert (-1) (-1) s 
     173    insert (-2) (-2) s 
     174    insert   1    3  s 
     175    insert (-3)   4  s 
     176    lookup (-1) s      .=> Just (-1) 
     177    lookup (-2) s      .=> Just (-2) 
     178    lookup   1  s      .=> Just   3 
     179    lookup (-3) s      .=> Just   4 
     180 
     181     
     182 
    163183-- TODO: test some crazy haskell type as value (to check stableptrs)