Changeset 19958 for third-party
- Timestamp:
- 02/20/08 18:24:49 (9 months ago)
- Location:
- third-party/HsJudy
- Files:
-
- 1 added
- 12 modified
-
HsJudy.cabal (modified) (1 diff)
-
Judy/BitSet.hs (modified) (6 diffs)
-
Judy/CollectionsM.hs (modified) (6 diffs)
-
Judy/Hash.hs (modified) (5 diffs)
-
Judy/HashIO.hs (modified) (3 diffs)
-
Judy/IntMap.hs (modified) (5 diffs)
-
Judy/MiniGC.hs (modified) (5 diffs)
-
Judy/Private.hsc (modified) (2 diffs)
-
Judy/Refeable.hs (modified) (2 diffs)
-
Judy/StrMap.hs (modified) (7 diffs)
-
Judy/Stringable.hs (modified) (3 diffs)
-
LICENSE (added)
-
README (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
third-party/HsJudy/HsJudy.cabal
r12301 r19958 1 1 name: HsJudy 2 2 version: 0.1 3 description: Judy bindings, and some nice APIs 3 Category: Data 4 Synopsis: Judy bindings, and some nice APIs 5 Description: 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). 4 11 license: BSD3 5 12 license-file: LICENSE 6 author: Caio Marcelo de Oliveira Filho <cmarcelo@gmail.com>, John Meacham13 author: Caio Marcelo de Oliveira Filho, John Meacham 7 14 maintainer: 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 15 homepage: http://www.pugscode.org/ 16 cabal-version: >= 1.2 17 tested-with: GHC==6.8.2 18 build-type: Simple 19 20 data-files: README 21 22 flag small_base 23 description: Choose the new smaller, split-up base package. 24 25 Library 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 62 62 -- | Set value in or out the set and return its old value. 63 63 set :: HashIO a => BitSet a -> a -> Bool -> IO Bool 64 set (BitSet j) v True = withForeignPtr j$ \j -> do64 set (BitSet k) v True = withForeignPtr k $ \j -> do 65 65 vp <- hashIO v 66 66 r <- judy1Set j vp judyError … … 68 68 then error "HsJudy: Not enough memory." 69 69 else return $ r == 0 70 set (BitSet j) v False = withForeignPtr j$ \j -> do70 set (BitSet k) v False = withForeignPtr k $ \j -> do 71 71 vp <- hashIO v 72 72 r <- judy1Unset j vp judyError … … 84 84 return $ r /= 0 85 85 86 -- | Is the value a member of the set? 86 -- | Is the value a member of the set? 87 87 member :: HashIO a => a -> BitSet a -> IO Bool 88 88 member v (BitSet j) = do … … 110 110 111 111 -- | Convert the set to a list of elements. 112 toList :: ReversibleHashIO a => BitSet a-> IO [a]112 toList :: (Enum a) => BitSet t -> IO [a] 113 113 toList (BitSet j) = do 114 114 j' <- withForeignPtr j peek … … 169 169 return bs 170 170 171 toListF :: ReversibleHashIO a => Frozen (BitSet a) -> [a]171 toListF :: (Enum a) => Frozen (BitSet t) -> [a] 172 172 toListF (Frozen (BitSet j)) = unsafePerformIO $ do 173 173 j' <- withForeignPtr j peek … … 182 182 r <- judy1Last j' vp judyError 183 183 f r [] 184 185 184 186 185 -- TODO: See if ListFrom and RevList are needed -
third-party/HsJudy/Judy/CollectionsM.hs
r12518 r19958 4 4 MapM (..), 5 5 MapF (..) 6 ) where 6 ) where 7 7 8 import Judy.Freeze9 import Foreign8 -- import Judy.Freeze 9 -- import Foreign 10 10 import Data.IORef 11 11 import qualified Data.Map as DM … … 16 16 -- import Prelude (Bool(..), Int, Maybe(..), 17 17 -- (==), (.), (+), ($), (-), (&&), (||), 18 -- Eq, Ord, 18 -- Eq, Ord, 19 19 -- error, const, not, fst, snd, maybe, head, otherwise, curry, uncurry, flip, 20 20 -- min, max, Show) … … 27 27 null :: c -> m Bool 28 28 size :: c -> m Int 29 29 30 30 empty :: m c 31 31 isSingleton :: c -> m Bool … … 75 75 76 76 --insertWith :: (a -> a -> a) -> k -> a -> c -> m () 77 77 78 78 -- FIXME: create a new structure? or delete inplace? or have both? 79 79 --mapWithKey :: (k -> a -> a) -> c -> m c … … 147 147 Nothing -> return Nothing 148 148 Just y -> (HT.insert m k y) >> (return $ Just y) 149 Just x -> case (f (Just x)) of149 Just y -> case (f $ Just y) of 150 150 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) 152 152 fromList = HT.fromList HT.hashString 153 153 toList = HT.toList … … 180 180 Nothing -> return Nothing 181 181 Just y -> (HT.insert m k y) >> (return $ Just y) 182 Just x -> case (f (Just x)) of182 Just a -> case (f $ Just a) of 183 183 Nothing -> (HT.delete m k) >> (return Nothing) 184 184 Just y -> (HT.insert m k y) >> (return $ Just y) -
third-party/HsJudy/Judy/Hash.hs
r12505 r19958 13 13 import Control.Monad (when) 14 14 import Foreign.C.String 15 import Foreign.C.Types16 import Foreign.ForeignPtr17 import Foreign.Marshal.Alloc18 import Foreign.Ptr19 import Foreign.Storable15 -- import Foreign.C.Types 16 -- import Foreign.ForeignPtr 17 -- import Foreign.Marshal.Alloc 18 -- import Foreign.Ptr 19 -- import Foreign.Storable 20 20 import Foreign 21 21 import Data.Maybe (fromJust) … … 75 75 return () 76 76 77 rawElems :: Hash k a -> IO [Value] 77 78 rawElems = internalMap $ \r _ _ -> peek r 78 79 … … 88 89 89 90 finalize' <- mkFin $ finalize $ needGC (dummy m) 90 addForeignPtrFinalizer finalize' fp 91 addForeignPtrFinalizer finalize' fp 91 92 return m 92 93 … … 112 113 then return Nothing 113 114 else insert_ k (fromJust (f Nothing)) m >> return (f Nothing) 114 else do 115 else do 115 116 v' <- peek r 116 117 v <- fromRef v' 117 118 let fv = f (Just v) 118 119 if fv == Nothing 119 then do delete_ k m 120 then do delete_ k m 120 121 return Nothing 121 122 else if v /= (fromJust fv) … … 133 134 if r == nullPtr 134 135 then return Nothing 135 else do 136 else do 136 137 v' <- peek r 137 138 v <- fromRef v' -
third-party/HsJudy/Judy/HashIO.hs
r12571 r19958 1 {-# LANGUAGE MagicHash #-} 1 2 {-# OPTIONS -fallow-undecidable-instances -fallow-incoherent-instances -fallow-overlapping-instances #-} 2 3 … … 22 23 23 24 instance Enum a => UniqueHashIO a where 25 24 26 instance Enum a => HashIO a where 25 27 hashIO = return . unsafeCoerce# . fromEnum 28 26 29 instance Enum a => ReversibleHashIO a where 27 30 unHashIO = return . toEnum . unsafeCoerce# … … 30 33 instance HashIO Value where 31 34 hashIO = return 35 32 36 instance UniqueHashIO Value 37 33 38 instance ReversibleHashIO Value where 34 39 unHashIO = return 35 36 40 37 41 instance HashIO Integer where -
third-party/HsJudy/Judy/IntMap.hs
r12505 r19958 5 5 module Judy.IntMap ( 6 6 IntMap (..), 7 7 8 8 freeze, 9 9 toRevList, … … 15 15 import Data.Typeable 16 16 import Control.Monad (when) 17 import Foreign.C.String18 import Foreign.C.Types19 import Foreign.ForeignPtr20 import Foreign.Marshal.Alloc21 import Foreign.Ptr22 import Foreign.Storable23 import Foreign.StablePtr17 -- 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 24 24 import Foreign 25 25 import Data.Maybe (fromJust) … … 80 80 return () 81 81 82 rawElems :: IntMap k a -> IO [Value] 82 83 rawElems = internalMap $ \r _ -> peek r 83 84 … … 92 93 93 94 finalize' <- mkFin $ finalize $ needGC (dummy m) 94 addForeignPtrFinalizer finalize' fp 95 addForeignPtrFinalizer finalize' fp 95 96 return m 96 97 … … 117 118 let fv = f (Just v) 118 119 if fv == Nothing 119 then do delete_ k m 120 then do delete_ k m 120 121 return Nothing -- FIXME check delete output 121 122 else if v /= (fromJust fv) -
third-party/HsJudy/Judy/MiniGC.hs
r12301 r19958 11 11 import Foreign 12 12 13 14 13 --import Foreign.Ptr 15 14 import Foreign.StablePtr … … 18 17 19 18 {-# NOINLINE judyGC #-} 19 judyGC :: GCMap 20 20 judyGC = unsafePerformIO newGCMap 21 21 22 newRef :: a -> IO WordPtr 22 23 newRef a = do 23 24 --putStr "(new)" … … 29 30 f (Just n) = Just (n+1) 30 31 32 freeRef :: Value -> IO () 31 33 freeRef v = do 32 34 --putStr "(free? " … … 53 55 newGCMap = do 54 56 fp <- mallocForeignPtr 55 addForeignPtrFinalizer judyL_free_ptr fp 57 addForeignPtrFinalizer judyL_free_ptr fp 56 58 withForeignPtr fp $ flip poke nullPtr 57 59 return $ GCMap fp … … 80 82 else poke r $ toEnum $ fromJust fv 81 83 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' } 89 92 90 93 member :: Value -> GCMap -> IO Bool -
third-party/HsJudy/Judy/Private.hsc
r12301 r19958 36 36 --foreign import ccall unsafe "judy_error" judyError :: JError 37 37 -- #def JError_t *judy_error(void) { static JError_t err; return &err; } 38 judyError :: JError 38 39 judyError = JError nullPtr 39 40 … … 163 164 164 165 foreign 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) 166 foreign import ccall "JudyHSIterNext" judyHSIterNext :: JudyHS -> Ptr JudyHSIter -> Ptr CString -> Ptr Value -> JError -> IO (Ptr Value) 167 foreign import ccall "JudyHSIterLast" judyHSIterLast :: JudyHS -> Ptr JudyHSIter -> Ptr CString -> Ptr Value -> JError -> IO (Ptr Value) 168 foreign import ccall "JudyHSIterPrev" judyHSIterPrev :: JudyHS -> Ptr JudyHSIter -> Ptr CString -> Ptr Value -> JError -> IO (Ptr Value) 168 169 foreign import ccall "JudyHSFreeIter" judyHSFreeIter :: Ptr JudyHSIter -> JError -> IO Value 169 170 -
third-party/HsJudy/Judy/Refeable.hs
r14219 r19958 1 1 {-# OPTIONS -fallow-undecidable-instances -fallow-incoherent-instances #-} 2 2 {-# LANGUAGE MagicHash, UndecidableInstances, IncoherentInstances #-} 3 3 module Judy.Refeable ( 4 4 Refeable (..) … … 28 28 needGC :: a -> Bool 29 29 needGC _ = True 30 30 31 31 --instance Dummy a => Refeable a where 32 32 instance Refeable a where -
third-party/HsJudy/Judy/StrMap.hs
r12505 r19958 13 13 import Control.Monad (when) 14 14 import Foreign.C.String 15 import Foreign.C.Types16 import Foreign.ForeignPtr17 import Foreign.Marshal.Alloc18 import Foreign.Ptr19 import Foreign.Storable20 import Foreign.StablePtr15 -- 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 21 21 import Foreign 22 22 import Data.Maybe (fromJust) … … 76 76 return () 77 77 78 rawElems :: StrMap k a -> IO [Value] 78 79 rawElems = internalMap $ \r _ -> peek r 79 80 … … 89 90 -- putStrLn $ show $ needGC $ dummy m 90 91 finalize' <- mkFin $ finalize $ needGC $ dummy m 91 addForeignPtrFinalizer finalize' fp 92 addForeignPtrFinalizer finalize' fp 92 93 return m 93 94 … … 109 110 then return Nothing 110 111 else insert_ k (fromJust (f Nothing)) m >> return (f Nothing) 111 else do 112 else do 112 113 v' <- peek r 113 114 v <- fromRef v' 114 115 let fv = f (Just v) 115 116 if fv == Nothing 116 then do delete_ k m 117 then do delete_ k m 117 118 return Nothing 118 119 else if v /= (fromJust fv) … … 146 147 r <- judySLGet j'' k' judyError 147 148 if r == nullPtr 148 then return () 149 then return () 149 150 else do v' <- peek r 150 151 GC.freeRef v' … … 164 165 jj <- withForeignPtr j peek 165 166 alloca $ \vp -> do 166 poke vp 0 167 poke vp 0 167 168 let loop act xs = do 168 169 r <- act jj vp judyError … … 190 191 mapHelper_ f r vp = do 191 192 k <- copyCS vp 192 v <- peek r >>= fromRef 193 v <- peek r >>= fromRef 193 194 return $ f k v 194 195 -
third-party/HsJudy/Judy/Stringable.hs
r12103 r19958 1 {-# OPTIONS -fallow-undecidable-instances -fallow-incoherent-instances #-} 1 {-# OPTIONS -fglasgow-exts #-} 2 {-# LANGUAGE TypeSynonymInstances #-} 2 3 3 4 module Judy.Stringable ( … … 6 7 7 8 import Foreign.C.String 8 import qualified Data.ByteString as B 9 9 import qualified Data.ByteString as B (ByteString, useAsCString, useAsCStringLen) 10 import Data.ByteString.Unsafe as BU (unsafePackCString, unsafePackCStringLen) 10 11 -- TODO: See if its possible to use Storable, ie. to let any Storable type be "stringable". 11 12 … … 31 32 toString = undefined 32 33 fromString = undefined 33 34 useAsCS = B.useAsCString 34 35 useAsCS = B.useAsCString 35 36 useAsCSLen = B.useAsCStringLen 36 37 37 copyCS = B .copyCString38 copyCSLen = B .copyCStringLen38 copyCS = BU.unsafePackCString 39 copyCSLen = BU.unsafePackCStringLen 39 40 40 41 --instance Stringable Int where -
third-party/HsJudy/README
r10844 r19958 49 49 candidates are Map, IntSet and IntMap. Doing an interface for DiffArray was 50 50 suggested, too. It's possible that no Haskell API matches some 51 functionalit ies(like 'unbounded' Arrays); in that case new interfaces will51 functionality (like 'unbounded' Arrays); in that case new interfaces will 52 52 be created. 53 53
