Skip to content

Instantly share code, notes, and snippets.

@tom-lpsd
Created April 14, 2009 13:33
Show Gist options
  • Save tom-lpsd/95180 to your computer and use it in GitHub Desktop.
Save tom-lpsd/95180 to your computer and use it in GitHub Desktop.
import Database.TokyoCabinet.BDB
import qualified Database.TokyoCabinet.BDB.Cursor as C
import Data.ByteString.Char8 (ByteString, unpack)
myCMP :: ByteString -> ByteString -> Ordering
myCMP k1 k2 = compare (reverse (unpack k1)) (reverse (unpack k2))
main = do bdb <- new
setcmpfunc bdb (CMP myCMP)
open bdb "foo.tcb" [OWRITER, OCREAT]
put bdb "abz" "100"
put bdb "def" "200"
cur <- C.new bdb
C.first cur
Just key <- C.key cur
putStrLn key
close bdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment