{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
module Raaz.Primitive.Keyed.Internal
(
Keyed(..), KeyedHash(..), Key(..), unsafeToKeyed, unsafeToPrim
) where
import Data.ByteString as BS
import Foreign.Storable ( Storable )
import Raaz.Core
class KeyedHash prim where
hashInit :: BYTES Int -> prim
newtype Keyed prim = Keyed prim
deriving (Keyed prim -> Keyed prim -> Bool
(Keyed prim -> Keyed prim -> Bool)
-> (Keyed prim -> Keyed prim -> Bool) -> Eq (Keyed prim)
forall prim. Eq prim => Keyed prim -> Keyed prim -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Keyed prim -> Keyed prim -> Bool
$c/= :: forall prim. Eq prim => Keyed prim -> Keyed prim -> Bool
== :: Keyed prim -> Keyed prim -> Bool
$c== :: forall prim. Eq prim => Keyed prim -> Keyed prim -> Bool
Eq, Keyed prim -> Keyed prim -> Result
(Keyed prim -> Keyed prim -> Result) -> Equality (Keyed prim)
forall prim. Equality prim => Keyed prim -> Keyed prim -> Result
forall a. (a -> a -> Result) -> Equality a
eq :: Keyed prim -> Keyed prim -> Result
$ceq :: forall prim. Equality prim => Keyed prim -> Keyed prim -> Result
Equality, Ptr b -> Int -> IO (Keyed prim)
Ptr b -> Int -> Keyed prim -> IO ()
Ptr (Keyed prim) -> IO (Keyed prim)
Ptr (Keyed prim) -> Int -> IO (Keyed prim)
Ptr (Keyed prim) -> Int -> Keyed prim -> IO ()
Ptr (Keyed prim) -> Keyed prim -> IO ()
Keyed prim -> Int
(Keyed prim -> Int)
-> (Keyed prim -> Int)
-> (Ptr (Keyed prim) -> Int -> IO (Keyed prim))
-> (Ptr (Keyed prim) -> Int -> Keyed prim -> IO ())
-> (forall b. Ptr b -> Int -> IO (Keyed prim))
-> (forall b. Ptr b -> Int -> Keyed prim -> IO ())
-> (Ptr (Keyed prim) -> IO (Keyed prim))
-> (Ptr (Keyed prim) -> Keyed prim -> IO ())
-> Storable (Keyed prim)
forall b. Ptr b -> Int -> IO (Keyed prim)
forall b. Ptr b -> Int -> Keyed prim -> IO ()
forall prim. Storable prim => Ptr (Keyed prim) -> IO (Keyed prim)
forall prim.
Storable prim =>
Ptr (Keyed prim) -> Int -> IO (Keyed prim)
forall prim.
Storable prim =>
Ptr (Keyed prim) -> Int -> Keyed prim -> IO ()
forall prim.
Storable prim =>
Ptr (Keyed prim) -> Keyed prim -> IO ()
forall prim. Storable prim => Keyed prim -> Int
forall prim b. Storable prim => Ptr b -> Int -> IO (Keyed prim)
forall prim b. Storable prim => Ptr b -> Int -> Keyed prim -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
poke :: Ptr (Keyed prim) -> Keyed prim -> IO ()
$cpoke :: forall prim.
Storable prim =>
Ptr (Keyed prim) -> Keyed prim -> IO ()
peek :: Ptr (Keyed prim) -> IO (Keyed prim)
$cpeek :: forall prim. Storable prim => Ptr (Keyed prim) -> IO (Keyed prim)
pokeByteOff :: Ptr b -> Int -> Keyed prim -> IO ()
$cpokeByteOff :: forall prim b. Storable prim => Ptr b -> Int -> Keyed prim -> IO ()
peekByteOff :: Ptr b -> Int -> IO (Keyed prim)
$cpeekByteOff :: forall prim b. Storable prim => Ptr b -> Int -> IO (Keyed prim)
pokeElemOff :: Ptr (Keyed prim) -> Int -> Keyed prim -> IO ()
$cpokeElemOff :: forall prim.
Storable prim =>
Ptr (Keyed prim) -> Int -> Keyed prim -> IO ()
peekElemOff :: Ptr (Keyed prim) -> Int -> IO (Keyed prim)
$cpeekElemOff :: forall prim.
Storable prim =>
Ptr (Keyed prim) -> Int -> IO (Keyed prim)
alignment :: Keyed prim -> Int
$calignment :: forall prim. Storable prim => Keyed prim -> Int
sizeOf :: Keyed prim -> Int
$csizeOf :: forall prim. Storable prim => Keyed prim -> Int
Storable, Storable (Keyed prim)
Ptr (Keyed prim) -> IO (Keyed prim)
Ptr (Keyed prim) -> Int -> IO ()
Ptr (Keyed prim) -> Keyed prim -> IO ()
Storable (Keyed prim)
-> (Ptr (Keyed prim) -> Keyed prim -> IO ())
-> (Ptr (Keyed prim) -> IO (Keyed prim))
-> (Ptr (Keyed prim) -> Int -> IO ())
-> EndianStore (Keyed prim)
forall w.
Storable w
-> (Ptr w -> w -> IO ())
-> (Ptr w -> IO w)
-> (Ptr w -> Int -> IO ())
-> EndianStore w
forall prim. EndianStore prim => Storable (Keyed prim)
forall prim.
EndianStore prim =>
Ptr (Keyed prim) -> IO (Keyed prim)
forall prim. EndianStore prim => Ptr (Keyed prim) -> Int -> IO ()
forall prim.
EndianStore prim =>
Ptr (Keyed prim) -> Keyed prim -> IO ()
adjustEndian :: Ptr (Keyed prim) -> Int -> IO ()
$cadjustEndian :: forall prim. EndianStore prim => Ptr (Keyed prim) -> Int -> IO ()
load :: Ptr (Keyed prim) -> IO (Keyed prim)
$cload :: forall prim.
EndianStore prim =>
Ptr (Keyed prim) -> IO (Keyed prim)
store :: Ptr (Keyed prim) -> Keyed prim -> IO ()
$cstore :: forall prim.
EndianStore prim =>
Ptr (Keyed prim) -> Keyed prim -> IO ()
$cp1EndianStore :: forall prim. EndianStore prim => Storable (Keyed prim)
EndianStore, ByteString -> Maybe (Keyed prim)
ByteString -> Keyed prim
Keyed prim -> ByteString
(Keyed prim -> ByteString)
-> (ByteString -> Maybe (Keyed prim))
-> (ByteString -> Keyed prim)
-> Encodable (Keyed prim)
forall prim. Encodable prim => ByteString -> Maybe (Keyed prim)
forall prim. Encodable prim => ByteString -> Keyed prim
forall prim. Encodable prim => Keyed prim -> ByteString
forall a.
(a -> ByteString)
-> (ByteString -> Maybe a) -> (ByteString -> a) -> Encodable a
unsafeFromByteString :: ByteString -> Keyed prim
$cunsafeFromByteString :: forall prim. Encodable prim => ByteString -> Keyed prim
fromByteString :: ByteString -> Maybe (Keyed prim)
$cfromByteString :: forall prim. Encodable prim => ByteString -> Maybe (Keyed prim)
toByteString :: Keyed prim -> ByteString
$ctoByteString :: forall prim. Encodable prim => Keyed prim -> ByteString
Encodable)
instance IsString prim => IsString (Keyed prim) where
fromString :: String -> Keyed prim
fromString = prim -> Keyed prim
forall prim. prim -> Keyed prim
unsafeToKeyed (prim -> Keyed prim) -> (String -> prim) -> String -> Keyed prim
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> prim
forall a. IsString a => String -> a
fromString
instance Show prim => Show (Keyed prim) where
show :: Keyed prim -> String
show = prim -> String
forall a. Show a => a -> String
show (prim -> String) -> (Keyed prim -> prim) -> Keyed prim -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Keyed prim -> prim
forall prim. Keyed prim -> prim
unsafeToPrim
instance Primitive prim => Primitive (Keyed prim) where
type WordType (Keyed prim) = WordType prim
type WordsPerBlock (Keyed prim) = WordsPerBlock prim
newtype instance Key (Keyed prim) = Key ByteString
instance IsString (Key (Keyed prim)) where
fromString :: String -> Key (Keyed prim)
fromString = ByteString -> Key (Keyed prim)
forall prim. ByteString -> Key (Keyed prim)
Key (ByteString -> Key (Keyed prim))
-> (String -> ByteString) -> String -> Key (Keyed prim)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
forall a. Encodable a => String -> a
fromBase16
instance Show (Key (Keyed prim)) where
show :: Key (Keyed prim) -> String
show (Key hkey) = ByteString -> String
forall a. Encodable a => a -> String
showBase16 ByteString
hkey
instance Encodable (Key (Keyed prim)) where
toByteString :: Key (Keyed prim) -> ByteString
toByteString (Key bs) = ByteString
bs
fromByteString :: ByteString -> Maybe (Key (Keyed prim))
fromByteString = Key (Keyed prim) -> Maybe (Key (Keyed prim))
forall a. a -> Maybe a
Just (Key (Keyed prim) -> Maybe (Key (Keyed prim)))
-> (ByteString -> Key (Keyed prim))
-> ByteString
-> Maybe (Key (Keyed prim))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Key (Keyed prim)
forall prim. ByteString -> Key (Keyed prim)
Key
unsafeFromByteString :: ByteString -> Key (Keyed prim)
unsafeFromByteString = ByteString -> Key (Keyed prim)
forall prim. ByteString -> Key (Keyed prim)
Key
unsafeToPrim :: Keyed prim -> prim
unsafeToPrim :: Keyed prim -> prim
unsafeToPrim (Keyed prim
p) = prim
p
unsafeToKeyed :: prim -> Keyed prim
unsafeToKeyed :: prim -> Keyed prim
unsafeToKeyed = prim -> Keyed prim
forall prim. prim -> Keyed prim
Keyed