File: Key.hs

package info (click to toggle)
tokyocabinet-haskell 0.0.5-8
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 304 kB
  • ctags: 1
  • sloc: haskell: 2,276; makefile: 3
file content (59 lines) | stat: -rw-r--r-- 1,280 bytes parent folder | download | duplicates (2)
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, FlexibleInstances #-}
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