Changeset 19958 for third-party

Show
Ignore:
Timestamp:
02/20/08 18:24:49 (9 months ago)
Author:
gwern
Message:

Update HsJudy?'s bytestring call, also update for split-base. As before, requires a more recent Cabal so can use conditionals, and as before, this package is now also on Hackage. While I was at it, I did some -Wall cleanup

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

Legend:

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

    r12301 r19958  
    11name:                HsJudy 
    22version:             0.1 
    3 description:         Judy bindings, and some nice APIs 
     3Category:            Data 
     4Synopsis:            Judy bindings, and some nice APIs 
     5Description:         Judy[1] bindings (a C library that implements fast sparse dynamic 
     6                     arrays) for Haskell presenting APIs conforming as much as possible to the 
     7                     existent Haskell library interfaces, like Data.Map and Data.Array.MArray. 
     8                     This binding for the Judy library includes all its four types: mapping from 
     9                     words to bits (Judy1), from words to values (JudyL), from strings to values 
     10                     (JudyHS) and from array-of-bytes to values (JudyHS). 
    411license:             BSD3 
    512license-file:        LICENSE 
    6 author:              Caio Marcelo de Oliveira Filho <cmarcelo@gmail.com>, John Meacham 
     13author:              Caio Marcelo de Oliveira Filho, John Meacham 
    714maintainer:          Caio Marcelo de Oliveira Filho <cmarcelo@gmail.com> 
    8 build-depends:       base -any, pugs-fps -any 
    9 exposed-modules:     Judy.BitSet Judy.Freeze Judy.Hash Judy.IntMap Judy.StrMap Judy.CollectionsM Judy.HashIO Judy.Refeable Judy.Stringable 
    10 other-modules:       Judy.Private Judy.MiniGC 
    11 extensions:          ForeignFunctionInterface 
    12 ghc-options:         -fglasgow-exts -O2 -static ../judy/Judy-1.0.3/src/Judy1/*.o ../judy/Judy-1.0.3/src/JudyL/*.o ../judy/Judy-1.0.3/src/JudySL/*.o ../judy/Judy-1.0.3/src/JudyHS/*.o ../judy/Judy-1.0.3/src/JudyCommon/*.o 
    13 include-dirs:        . ../judy/Judy-1.0.3/src 
    14 -- FIXME: make Cabal work nicely with _hsc files, now I think it works, but doesnt clean _hsc files 
    15 c-sources:           Judy/Private_hsc.c 
     15homepage:            http://www.pugscode.org/ 
     16cabal-version:       >= 1.2 
     17tested-with:         GHC==6.8.2 
     18build-type:          Simple 
     19 
     20data-files:          README 
     21 
     22flag small_base 
     23    description: Choose the new smaller, split-up base package. 
     24 
     25Library 
     26        if flag(small_base) 
     27            Build-Depends: base, containers 
     28        else 
     29            Build-Depends: base < 3 
     30        build-depends:     bytestring>=0.9.0.1 
     31        exposed-modules:     Judy.BitSet Judy.Freeze Judy.Hash Judy.IntMap Judy.StrMap 
     32                             Judy.CollectionsM Judy.HashIO Judy.Refeable Judy.Stringable 
     33        other-modules:       Judy.Private Judy.MiniGC 
     34 
     35        include-dirs:        . ../judy/Judy-1.0.3/src 
     36-- FIXME: make Cabal work nicely with _hsc files; now I think it works, but doesn't clean _hsc files 
     37        c-sources:           Judy/Private_hsc.c 
     38 
     39 
     40        extensions:          ForeignFunctionInterface, TypeSynonymInstances, MagicHash, 
     41                             IncoherentInstances, UndecidableInstances 
     42        ghc-options:         -fglasgow-exts -Wall -O2 -static ../judy/Judy-1.0.3/src/Judy1/*.o 
     43                             ../judy/Judy-1.0.3/src/JudyL/*.o ../judy/Judy-1.0.3/src/JudySL/*.o 
     44                             ../judy/Judy-1.0.3/src/JudyHS/*.o ../judy/Judy-1.0.3/src/JudyCommon/*.o 
  • third-party/HsJudy/Judy/BitSet.hs

    r12301 r19958  
    6262-- | Set value in or out the set and return its old value. 
    6363set :: HashIO a => BitSet a -> a -> Bool -> IO Bool 
    64 set (BitSet j) v True = withForeignPtr j $ \j ->  do 
     64set (BitSet k) v True = withForeignPtr k $ \j ->  do 
    6565    vp <- hashIO v 
    6666    r <- judy1Set j vp judyError 
     
    6868        then error "HsJudy: Not enough memory." 
    6969        else return $ r == 0 
    70 set (BitSet j) v False = withForeignPtr j $ \j -> do 
     70set (BitSet k) v False = withForeignPtr k $ \j -> do 
    7171    vp <- hashIO v 
    7272    r <- judy1Unset j vp judyError 
     
    8484    return $ r /= 0 
    8585 
    86 -- | Is the value a member of the set?  
     86-- | Is the value a member of the set? 
    8787member :: HashIO a => a -> BitSet a -> IO Bool 
    8888member v (BitSet j) = do 
     
    110110 
    111111-- | Convert the set to a list of elements. 
    112 toList :: ReversibleHashIO a => BitSet a -> IO [a] 
     112toList :: (Enum a) => BitSet t -> IO [a] 
    113113toList (BitSet j) = do 
    114114    j' <- withForeignPtr j peek 
     
    169169    return bs 
    170170 
    171 toListF :: ReversibleHashIO a => Frozen (BitSet a) -> [a] 
     171toListF :: (Enum a) => Frozen (BitSet t) -> [a] 
    172172toListF (Frozen (BitSet j)) = unsafePerformIO $ do 
    173173    j' <- withForeignPtr j peek 
     
    182182        r <- judy1Last j' vp judyError 
    183183        f r [] 
    184  
    185184 
    186185-- TODO: See if ListFrom and RevList are needed 
  • third-party/HsJudy/Judy/CollectionsM.hs

    r12518 r19958  
    44    MapM (..), 
    55    MapF (..) 
    6 ) where  
     6) where 
    77 
    8 import Judy.Freeze 
    9 import Foreign 
     8-- import Judy.Freeze 
     9-- import Foreign 
    1010import Data.IORef 
    1111import qualified Data.Map       as DM 
     
    1616-- import Prelude (Bool(..), Int, Maybe(..), 
    1717--                 (==), (.), (+), ($), (-), (&&), (||), 
    18 --                 Eq, Ord,  
     18--                 Eq, Ord, 
    1919--                 error, const, not, fst, snd, maybe, head, otherwise, curry, uncurry, flip, 
    2020--                 min, max, Show) 
     
    2727    null :: c -> m Bool 
    2828    size :: c -> m Int 
    29      
     29 
    3030    empty :: m c 
    3131    isSingleton :: c -> m Bool 
     
    7575 
    7676    --insertWith :: (a -> a -> a) -> k -> a -> c -> m () 
    77      
     77 
    7878    -- FIXME: create a new structure? or delete inplace? or have both? 
    7979    --mapWithKey :: (k -> a -> a) -> c -> m c 
     
    147147                Nothing -> return Nothing 
    148148                Just y  -> (HT.insert m k y) >> (return $ Just y) 
    149             Just x  -> case (f (Just x)) of 
     149            Just y  -> case (f $ Just y) of 
    150150                Nothing -> (HT.delete m k)   >> (return Nothing) 
    151                 Just y  -> (HT.insert m k y) >> (return $ Just y) 
     151                Just z  -> (HT.insert m k z) >> (return $ Just z) 
    152152    fromList = HT.fromList HT.hashString 
    153153    toList = HT.toList 
     
    180180                Nothing -> return Nothing 
    181181                Just y  -> (HT.insert m k y) >> (return $ Just y) 
    182             Just x  -> case (f (Just x)) of 
     182            Just a  -> case (f $ Just a) of 
    183183                Nothing -> (HT.delete m k)   >> (return Nothing) 
    184184                Just y  -> (HT.insert m k y) >> (return $ Just y) 
  • third-party/HsJudy/Judy/Hash.hs

    r12505 r19958  
    1313import Control.Monad (when) 
    1414import Foreign.C.String 
    15 import Foreign.C.Types 
    16 import Foreign.ForeignPtr 
    17 import Foreign.Marshal.Alloc 
    18 import Foreign.Ptr 
    19 import Foreign.Storable 
     15-- import Foreign.C.Types 
     16-- import Foreign.ForeignPtr 
     17-- import Foreign.Marshal.Alloc 
     18-- import Foreign.Ptr 
     19-- import Foreign.Storable 
    2020import Foreign 
    2121import Data.Maybe (fromJust) 
     
    7575    return () 
    7676 
     77rawElems :: Hash k a -> IO [Value] 
    7778rawElems = internalMap $ \r _ _ -> peek r 
    7879 
     
    8889 
    8990    finalize' <- mkFin $ finalize $ needGC (dummy m) 
    90     addForeignPtrFinalizer finalize' fp  
     91    addForeignPtrFinalizer finalize' fp 
    9192    return m 
    9293 
     
    112113                    then return Nothing 
    113114                    else insert_ k (fromJust (f Nothing)) m >> return (f Nothing) 
    114             else do  
     115            else do 
    115116                v' <- peek r 
    116117                v <- fromRef v' 
    117118                let fv = f (Just v) 
    118119                if fv == Nothing 
    119                     then do delete_ k m  
     120                    then do delete_ k m 
    120121                            return Nothing 
    121122                    else if v /= (fromJust fv) 
     
    133134        if r == nullPtr 
    134135            then return Nothing 
    135             else do  
     136            else do 
    136137                v' <- peek r 
    137138                v <- fromRef v' 
  • third-party/HsJudy/Judy/HashIO.hs

    r12571 r19958  
     1{-# LANGUAGE MagicHash #-} 
    12{-# OPTIONS -fallow-undecidable-instances -fallow-incoherent-instances -fallow-overlapping-instances #-} 
    23 
     
    2223 
    2324instance Enum a => UniqueHashIO a where 
     25 
    2426instance Enum a => HashIO a where 
    2527    hashIO = return . unsafeCoerce# . fromEnum 
     28 
    2629instance Enum a => ReversibleHashIO a where 
    2730    unHashIO = return . toEnum . unsafeCoerce# 
     
    3033instance HashIO Value where 
    3134    hashIO = return 
     35 
    3236instance UniqueHashIO Value 
     37 
    3338instance ReversibleHashIO Value where 
    3439    unHashIO = return 
    35  
    3640 
    3741instance HashIO Integer where 
  • third-party/HsJudy/Judy/IntMap.hs

    r12505 r19958  
    55module Judy.IntMap ( 
    66    IntMap (..), 
    7      
     7 
    88    freeze, 
    99    toRevList, 
     
    1515import Data.Typeable 
    1616import Control.Monad (when) 
    17 import Foreign.C.String 
    18 import Foreign.C.Types 
    19 import Foreign.ForeignPtr 
    20 import Foreign.Marshal.Alloc 
    21 import Foreign.Ptr 
    22 import Foreign.Storable 
    23 import Foreign.StablePtr 
     17-- import Foreign.C.String 
     18-- import Foreign.C.Types 
     19-- import Foreign.ForeignPtr 
     20-- import Foreign.Marshal.Alloc 
     21-- import Foreign.Ptr 
     22-- import Foreign.Storable 
     23-- import Foreign.StablePtr 
    2424import Foreign 
    2525import Data.Maybe (fromJust) 
     
    8080    return () 
    8181 
     82rawElems :: IntMap k a -> IO [Value] 
    8283rawElems = internalMap $ \r _ -> peek r 
    8384 
     
    9293 
    9394    finalize' <- mkFin $ finalize $ needGC (dummy m) 
    94     addForeignPtrFinalizer finalize' fp  
     95    addForeignPtrFinalizer finalize' fp 
    9596    return m 
    9697 
     
    117118            let fv = f (Just v) 
    118119            if fv == Nothing 
    119                 then do delete_ k m  
     120                then do delete_ k m 
    120121                        return Nothing           -- FIXME check delete output 
    121122                else if v /= (fromJust fv) 
  • third-party/HsJudy/Judy/MiniGC.hs

    r12301 r19958  
    1111import Foreign 
    1212 
    13  
    1413--import Foreign.Ptr 
    1514import Foreign.StablePtr 
     
    1817 
    1918{-# NOINLINE judyGC #-} 
     19judyGC :: GCMap 
    2020judyGC = unsafePerformIO newGCMap 
    2121 
     22newRef :: a -> IO WordPtr 
    2223newRef a = do 
    2324    --putStr "(new)" 
     
    2930         f (Just n) = Just (n+1) 
    3031 
     32freeRef :: Value -> IO () 
    3133freeRef v = do 
    3234    --putStr "(free? " 
     
    5355newGCMap = do 
    5456    fp <- mallocForeignPtr 
    55     addForeignPtrFinalizer judyL_free_ptr fp  
     57    addForeignPtrFinalizer judyL_free_ptr fp 
    5658    withForeignPtr fp $ flip poke nullPtr 
    5759    return $ GCMap fp 
     
    8082                else poke r $ toEnum $ fromJust fv 
    8183 
    82 lookup :: Value -> GCMap -> IO (Maybe Int) 
    83 lookup k (GCMap j) = do 
    84     j' <- withForeignPtr j peek 
    85     r <- judyLGet j' k judyError 
    86     if r == nullPtr 
    87         then return Nothing 
    88         else do { v' <- peek r; return $ Just $ fromEnum v' } 
     84-- -- Not used; dead code 
     85-- lookup :: Value -> GCMap -> IO (Maybe Int) 
     86-- lookup k (GCMap j) = do 
     87--     j' <- withForeignPtr j peek 
     88--     r <- judyLGet j' k judyError 
     89--     if r == nullPtr 
     90--         then return Nothing 
     91--         else do { v' <- peek r; return $ Just $ fromEnum v' } 
    8992 
    9093member :: Value -> GCMap -> IO Bool 
  • third-party/HsJudy/Judy/Private.hsc

    r12301 r19958  
    3636--foreign import ccall unsafe "judy_error" judyError :: JError 
    3737-- #def JError_t *judy_error(void) { static JError_t err; return &err; } 
     38judyError :: JError 
    3839judyError = JError nullPtr 
    3940 
     
    163164 
    164165foreign import ccall "JudyHSIterFirst" judyHSIterFirst :: JudyHS -> Ptr JudyHSIter -> Ptr CString -> Ptr Value -> JError -> IO (Ptr Value) 
    165 foreign import ccall "JudyHSIterNext" judyHSIterNext :: JudyHS -> Ptr JudyHSIter -> Ptr CString -> Ptr Value -> JError -> IO (Ptr Value)  
    166 foreign import ccall "JudyHSIterLast" judyHSIterLast :: JudyHS -> Ptr JudyHSIter -> Ptr CString -> Ptr Value -> JError -> IO (Ptr Value)  
    167 foreign import ccall "JudyHSIterPrev" judyHSIterPrev :: JudyHS -> Ptr JudyHSIter -> Ptr CString -> Ptr Value -> JError -> IO (Ptr Value)  
     166foreign import ccall "JudyHSIterNext" judyHSIterNext :: JudyHS -> Ptr JudyHSIter -> Ptr CString -> Ptr Value -> JError -> IO (Ptr Value) 
     167foreign import ccall "JudyHSIterLast" judyHSIterLast :: JudyHS -> Ptr JudyHSIter -> Ptr CString -> Ptr Value -> JError -> IO (Ptr Value) 
     168foreign import ccall "JudyHSIterPrev" judyHSIterPrev :: JudyHS -> Ptr JudyHSIter -> Ptr CString -> Ptr Value -> JError -> IO (Ptr Value) 
    168169foreign import ccall "JudyHSFreeIter" judyHSFreeIter :: Ptr JudyHSIter -> JError -> IO Value 
    169170 
  • third-party/HsJudy/Judy/Refeable.hs

    r14219 r19958  
    11{-# OPTIONS -fallow-undecidable-instances -fallow-incoherent-instances #-} 
    2  
     2{-# LANGUAGE MagicHash, UndecidableInstances, IncoherentInstances #-} 
    33module Judy.Refeable ( 
    44    Refeable (..) 
     
    2828    needGC :: a -> Bool 
    2929    needGC _ = True 
    30      
     30 
    3131--instance Dummy a => Refeable a where 
    3232instance Refeable a where 
  • third-party/HsJudy/Judy/StrMap.hs

    r12505 r19958  
    1313import Control.Monad (when) 
    1414import Foreign.C.String 
    15 import Foreign.C.Types 
    16 import Foreign.ForeignPtr 
    17 import Foreign.Marshal.Alloc 
    18 import Foreign.Ptr 
    19 import Foreign.Storable 
    20 import Foreign.StablePtr 
     15-- import Foreign.C.Types 
     16-- import Foreign.ForeignPtr 
     17-- import Foreign.Marshal.Alloc 
     18-- import Foreign.Ptr 
     19-- import Foreign.Storable 
     20-- import Foreign.StablePtr 
    2121import Foreign 
    2222import Data.Maybe (fromJust) 
     
    7676    return () 
    7777 
     78rawElems :: StrMap k a -> IO [Value] 
    7879rawElems = internalMap $ \r _ -> peek r 
    7980 
     
    8990    -- putStrLn $ show $ needGC $ dummy m 
    9091    finalize' <- mkFin $ finalize $ needGC $ dummy m 
    91     addForeignPtrFinalizer finalize' fp  
     92    addForeignPtrFinalizer finalize' fp 
    9293    return m 
    9394 
     
    109110                    then return Nothing 
    110111                    else insert_ k (fromJust (f Nothing)) m >> return (f Nothing) 
    111             else do  
     112            else do 
    112113                v' <- peek r 
    113114                v <- fromRef v' 
    114115                let fv = f (Just v) 
    115116                if fv == Nothing 
    116                     then do delete_ k m  
     117                    then do delete_ k m 
    117118                            return Nothing 
    118119                    else if v /= (fromJust fv) 
     
    146147            r <- judySLGet j'' k' judyError 
    147148            if r == nullPtr 
    148                 then return ()  
     149                then return () 
    149150                else do v' <- peek r 
    150151                        GC.freeRef v' 
     
    164165    jj <- withForeignPtr j peek 
    165166    alloca $ \vp -> do 
    166         poke vp 0  
     167        poke vp 0 
    167168        let loop act xs = do 
    168169            r <- act jj vp judyError 
     
    190191mapHelper_ f r vp = do 
    191192    k <- copyCS vp 
    192     v <- peek r >>= fromRef  
     193    v <- peek r >>= fromRef 
    193194    return $ f k v 
    194195 
  • third-party/HsJudy/Judy/Stringable.hs

    r12103 r19958  
    1 {-# OPTIONS -fallow-undecidable-instances -fallow-incoherent-instances #-} 
     1{-# OPTIONS -fglasgow-exts #-} 
     2{-# LANGUAGE TypeSynonymInstances #-} 
    23 
    34module Judy.Stringable ( 
     
    67 
    78import Foreign.C.String 
    8 import qualified Data.ByteString as B 
    9  
     9import qualified Data.ByteString as B (ByteString, useAsCString, useAsCStringLen) 
     10import Data.ByteString.Unsafe as BU (unsafePackCString, unsafePackCStringLen) 
    1011-- TODO: See if its possible to use Storable, ie. to let any Storable type be "stringable". 
    1112 
     
    3132    toString = undefined 
    3233    fromString = undefined 
    33   
    34     useAsCS = B.useAsCString  
     34 
     35    useAsCS = B.useAsCString 
    3536    useAsCSLen = B.useAsCStringLen 
    3637 
    37     copyCS = B.copyCString 
    38     copyCSLen = B.copyCStringLen 
     38    copyCS = BU.unsafePackCString 
     39    copyCSLen = BU.unsafePackCStringLen 
    3940 
    4041--instance Stringable Int where 
  • third-party/HsJudy/README

    r10844 r19958  
    4949candidates are Map, IntSet and IntMap. Doing an interface for DiffArray was 
    5050suggested, too. It's possible that no Haskell API matches some 
    51 functionalities (like 'unbounded' Arrays); in that case new interfaces will 
     51functionality (like 'unbounded' Arrays); in that case new interfaces will 
    5252be created. 
    5353