{-# LANGUAGE MagicHash, FlexibleInstances #-}

{- |
    Module      :  SDP.Hashable
    Copyright   :  (c) Andrey Mulik 2020
    License     :  BSD-style
    Maintainer  :  work.a.mulik@gmail.com
    Portability :  portable
    
    @SDP.Hashable@ provides 'Hashable' instances for @sdp@ structures.
-}
module SDP.Hashable
  (
    -- * Export
    module Data.Hashable
  )
where

import Prelude ()
import SDP.SafePrelude
import SDP.Templates.AnyBorder
import SDP.Templates.AnyChunks
import SDP.Prim.SArray
import SDP.Prim.SBytes

import Data.Hashable

default ()

--------------------------------------------------------------------------------

instance (Hashable e) => Hashable (SArray# e)
  where
    hashWithSalt :: Int -> SArray# e -> Int
hashWithSalt = (Int -> e -> Int) -> Int -> SArray# e -> Int
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Int -> e -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt

instance (Unboxed e) => Hashable (SBytes# e)
  where
    hashWithSalt :: Int -> SBytes# e -> Int
hashWithSalt = Int -> SBytes# e -> Int
forall e. Unboxed e => Int -> SBytes# e -> Int
hashSBytesWith#

instance (Hashable (rep e), Hashable i, Index i) => Hashable (AnyBorder rep i e)
  where
    hashWithSalt :: Int -> AnyBorder rep i e -> Int
hashWithSalt Int
salt (AnyBorder i
_ i
_ rep e
rep) = Int
salt Int -> rep e -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` rep e
rep

instance (Nullable (rep e), Hashable (rep e)) => Hashable (AnyChunks rep e)
  where
    hashWithSalt :: Int -> AnyChunks rep e -> Int
hashWithSalt Int
salt = (Int -> rep e -> Int) -> Int -> [rep e] -> Int
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Int -> rep e -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt ([rep e] -> Int)
-> (AnyChunks rep e -> [rep e]) -> AnyChunks rep e -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyChunks rep e -> [rep e]
forall (rep :: * -> *) e. AnyChunks rep e -> [rep e]
toChunks