packages feed

tokyocabinet-haskell 0.0.2 → 0.0.3

raw patch · 3 files changed

+53/−3 lines, 3 files

Files

Database/TokyoCabinet/BDB.hs view
@@ -8,6 +8,7 @@     , ECODE(..)     , OpenMode(..)     , TuningOption(..)+    , CMP(..)     -- * Basic API (tokyocabinet.idl compliant)     , new     , delete@@ -16,6 +17,7 @@     , tune     , setcache     , setxmsiz+    , setcmpfunc     , open     , close     , put@@ -47,6 +49,8 @@  import Data.Int import Data.Word+import Data.ByteString (ByteString)+import Data.ByteString.Unsafe (unsafePackCStringLen)  import Foreign.Ptr import Foreign.ForeignPtr@@ -106,6 +110,12 @@ -- @ -- +data CMP = CMPLEXICAL |+           CMPDECIMAL |+           CMPINT32 |+           CMPINT64 |+           CMP (ByteString -> ByteString -> Ordering)+ -- | Create a B+ tree database object.  new :: IO BDB new = BDB `fmap` (c_tcbdbnew >>= newForeignPtr tcbdbFinalizer)@@ -147,6 +157,30 @@ setxmsiz :: BDB -> Int64 -> IO Bool setxmsiz bdb xmsiz =     withForeignPtr (unTCBDB bdb) $ \bdb' -> c_tcbdbsetxmsiz bdb' xmsiz++-- | Set the custom comparison function of a B+ tree database object.+setcmpfunc :: BDB -> CMP -> IO Bool+setcmpfunc bdb CMPLEXICAL =+    withForeignPtr (unTCBDB bdb) $ flip c_tcbdbsetcmpfunc c_tccmplexical+setcmpfunc bdb CMPDECIMAL =+    withForeignPtr (unTCBDB bdb) $ flip c_tcbdbsetcmpfunc c_tccmpdecimal+setcmpfunc bdb CMPINT32 =+    withForeignPtr (unTCBDB bdb) $ flip c_tcbdbsetcmpfunc c_tccmpint32+setcmpfunc bdb CMPINT64 =+    withForeignPtr (unTCBDB bdb) $ flip c_tcbdbsetcmpfunc c_tccmpint64+setcmpfunc bdb (CMP func) =+    withForeignPtr (unTCBDB bdb) $ \bdb' ->+        do cmpfunc <- mkCMP mycmpfunc+           c_tcbdbsetcmpfunc bdb' cmpfunc+        where+          mycmpfunc :: TCCMP'+          mycmpfunc k1buf k1siz k2buf k2siz _ =+              do key1 <- unsafePackCStringLen (k1buf, fromIntegral k1siz)+                 key2 <- unsafePackCStringLen (k2buf, fromIntegral k2siz)+                 case func key1 key2 of+                   LT -> return (-1)+                   EQ -> return 0+                   GT -> return 1  -- | Open BDB database file. open :: BDB -> String -> [OpenMode] -> IO Bool
Database/TokyoCabinet/BDB/C.hsc view
@@ -57,7 +57,7 @@ combineTuningOption :: [TuningOption] -> Word8 combineTuningOption = foldr ((.|.) . tuningOptionToWord8) 0 -type TCCMP = Ptr CChar -> CInt -> Ptr CChar -> CInt -> Ptr Word8 -> CInt+type TCCMP' = Ptr CChar -> CInt -> Ptr CChar -> CInt -> Ptr Word8 -> IO CInt  data BDB' @@ -77,7 +77,7 @@   c_tcbdbsetmutex :: Ptr BDB' -> IO Bool  foreign import ccall safe "tcbdbsetcmpfunc"-  c_tcbdbsetcmpfunc :: Ptr BDB' -> FunPtr TCCMP -> IO Bool+  c_tcbdbsetcmpfunc :: Ptr BDB' -> FunPtr TCCMP' -> IO Bool  foreign import ccall safe "tcbdbtune"   c_tcbdbtune ::@@ -209,3 +209,18 @@  foreign import ccall safe "tcbdbfsiz"   c_tcbdbfsiz :: Ptr BDB' -> IO Word64++foreign import ccall safe "tcutil.h &tccmplexical"+  c_tccmplexical :: FunPtr TCCMP'++foreign import ccall safe "tcutil.h &tccmpdecimal"+  c_tccmpdecimal :: FunPtr TCCMP'++foreign import ccall safe "tcutil.h &tccmpint32"+  c_tccmpint32 :: FunPtr TCCMP'++foreign import ccall safe "tcutil.h &tccmpint64"+  c_tccmpint64 :: FunPtr TCCMP'++foreign import ccall "wrapper"+  mkCMP :: TCCMP' -> IO (FunPtr TCCMP')
tokyocabinet-haskell.cabal view
@@ -1,10 +1,11 @@ Name:           tokyocabinet-haskell-Version:        0.0.2+Version:        0.0.3 Cabal-Version:  >= 1.2 License:        BSD3 License-File:   LICENSE Author:         Tom Tsuruhara Maintainer:     tom.lpsd@gmail.com+Homepage:       http://tom-lpsd.github.com/tokyocabinet-haskell/ Stability:      experimental Category:       Database Synopsis:       Haskell binding of Tokyo Cabinet