Changeset 12518 for third-party

Show
Ignore:
Timestamp:
08/20/06 14:51:42 (2 years ago)
Author:
cmarcelo
Message:

* HsJudy?: Add instance of HashTable? for MapM.

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

Legend:

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

    r12505 r12518  
    99import Foreign 
    1010import Data.IORef 
    11 import qualified Data.Map as DM 
    12  
     11import qualified Data.Map       as DM 
     12import qualified Data.HashTable as HT 
    1313 
    1414import Prelude hiding (lookup) 
     
    130130        writeIORef x y' 
    131131        writeIORef y x' 
     132 
     133instance MapM (HT.HashTable String a) String a IO where 
     134    new = HT.new (==) HT.hashString 
     135    delete k m = (HT.delete m k) >> (return True) 
     136    member k m = do 
     137        x <- HT.lookup m k 
     138        return $ case x of 
     139            Nothing -> False 
     140            Just _  -> True 
     141    lookup = flip HT.lookup 
     142    insert k a m = HT.insert m k a 
     143    alter f k m = do 
     144        x <- HT.lookup m k 
     145        case x of 
     146            Nothing -> case (f Nothing) of 
     147                Nothing -> return Nothing 
     148                Just y  -> (HT.insert m k y) >> (return $ Just y) 
     149            Just x  -> case (f (Just x)) of 
     150                Nothing -> (HT.delete m k)   >> (return Nothing) 
     151                Just y  -> (HT.insert m k y) >> (return $ Just y) 
     152    fromList = HT.fromList HT.hashString 
     153    toList = HT.toList 
     154    elems = (fmap (map snd)) . HT.toList 
     155    keys  = (fmap (map fst)) . HT.toList 
     156    mapToList f = (fmap (map f')) . HT.toList 
     157        where f' (a,b) = f a b 
     158    swapMaps x y = do 
     159        x' <- HT.toList x 
     160        y' <- HT.toList y 
     161        mapM_ (\(a,_) -> HT.delete x a) x' 
     162        mapM_ (\(a,_) -> HT.delete y a) y' 
     163        mapM_ (\(a,b) -> HT.insert x a b) y' 
     164        mapM_ (\(a,b) -> HT.insert y a b) x' 
     165 
     166instance MapM (HT.HashTable Int a) Int a IO where 
     167    new = HT.new (==) HT.hashInt 
     168    delete k m = (HT.delete m k) >> (return True) 
     169    member k m = do 
     170        x <- HT.lookup m k 
     171        return $ case x of 
     172            Nothing -> False 
     173            Just _  -> True 
     174    lookup = flip HT.lookup 
     175    insert k a m = HT.insert m k a 
     176    alter f k m = do 
     177        x <- HT.lookup m k 
     178        case x of 
     179            Nothing -> case (f Nothing) of 
     180                Nothing -> return Nothing 
     181                Just y  -> (HT.insert m k y) >> (return $ Just y) 
     182            Just x  -> case (f (Just x)) of 
     183                Nothing -> (HT.delete m k)   >> (return Nothing) 
     184                Just y  -> (HT.insert m k y) >> (return $ Just y) 
     185    fromList = HT.fromList HT.hashInt 
     186    toList = HT.toList 
     187    elems = (fmap (map snd)) . HT.toList 
     188    keys  = (fmap (map fst)) . HT.toList 
     189    mapToList f = (fmap (map f')) . HT.toList 
     190        where f' (a,b) = f a b 
     191    swapMaps x y = do 
     192        x' <- HT.toList x 
     193        y' <- HT.toList y 
     194        mapM_ (\(a,_) -> HT.delete x a) x' 
     195        mapM_ (\(a,_) -> HT.delete y a) y' 
     196        mapM_ (\(a,b) -> HT.insert x a b) y' 
     197        mapM_ (\(a,b) -> HT.insert y a b) x' 
  • third-party/HsJudy/Makefile

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

    r12505 r12518  
    11# Makefile for static linkage 
    22 
    3 TESTS=TestBS TestJL TestJSL TestJHS TestHash TestIntMap TestStrMap TestDM 
     3TESTS=TestBS TestJL TestJSL TestJHS TestHash TestIntMap TestStrMap TestDM TestHT 
    44 
    55GHC=ghc # -debug