~singpolyma/tokyocabinet-haskell

ref: b4fdd27f34c558e70464b38ae15123562c2a9278 tokyocabinet-haskell/Database/TokyoCabinet/FDB/Key.hs -rw-r--r-- 1.2 KiB
b4fdd27f — tom.lpsd don't export ECODE from ADB module 11 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{-# LANGUAGE TypeSynonymInstances #-}
module Database.TokyoCabinet.FDB.Key (Key(..), ID(..)) where

import Database.TokyoCabinet.FDB.C (ID(..), unID)

import Data.Int
import Data.Word

class Key a where
    toID   :: a -> ID
    fromID :: ID -> a

instance Key Int where
    toID = ID . fromIntegral
    fromID = fromIntegral . unID

instance Key Int8 where
    toID = ID . fromIntegral
    fromID = fromIntegral . unID

instance Key Int16 where
    toID = ID . fromIntegral
    fromID = fromIntegral . unID

instance Key Int32 where
    toID = ID . fromIntegral
    fromID = fromIntegral . unID

instance Key Int64 where
    toID = ID
    fromID = fromIntegral . unID

instance Key Word8 where
    toID = ID . fromIntegral
    fromID = fromIntegral . unID

instance Key Word16 where
    toID = ID . fromIntegral
    fromID = fromIntegral . unID

instance Key Word32 where
    toID = ID . fromIntegral
    fromID = fromIntegral . unID

instance Key Word64 where
    toID = ID . fromIntegral
    fromID = fromIntegral . unID

instance Key ID where
    toID = id
    fromID = id

instance Key String where
    toID "min"  = IDMIN
    toID "max"  = IDMAX
    toID "prev" = IDPREV
    toID "next" = IDNEXT
    toID idstr  = ID (read idstr)
    fromID = show . unID