{-# OPTIONS_GHC -Wno-orphans #-}

-- |
-- Copyright: © 2025–2026 Jonathan Knowles
-- License: Apache-2.0
--
module Data.MonoidMap.Hashable
    (
    -- * Introduction
    -- $_introduction
    )
    where

import Data.Bool
    ( Bool
    )
import Data.Eq
    ( Eq ((==))
    )
import Data.Hashable
    ( Hashable (hash, hashWithSalt)
    )
import Data.Map.Strict
    ( Map
    )
import Data.MonoidMap
    ( MonoidMap
    , toMap
    )
import Prelude
    ( undefined
    , (.)
    )

-- $_introduction
-- #_introduction#
--
-- This module provides a 'Hashable' instance for 'MonoidMap'.
--
-- This instance behaves identically to the 'Hashable' instance for 'Map',
-- satisfying the following the laws:
--
-- @
-- 'hash'           '==' 'hash'           '.' 'MonoidMap'.'toMap'
-- 'hashWithSalt' i '==' 'hashWithSalt' i '.' 'MonoidMap'.'toMap'
-- @
--

_importsRequiredForDocumentation :: ()
_importsRequiredForDocumentation :: ()
_importsRequiredForDocumentation = ()
  where
    _Map :: Map () ()
    _Map :: Map () ()
_Map = Map () ()
forall a. HasCallStack => a
undefined

    _equals :: () -> () -> Bool
    _equals :: () -> () -> Bool
_equals = () -> () -> Bool
forall a. Eq a => a -> a -> Bool
(==)

instance (Hashable k, Hashable v) => Hashable (MonoidMap k v)
  where
    hash :: MonoidMap k v -> Int
hash           = Map k v -> Int
forall a. Hashable a => a -> Int
hash           (Map k v -> Int)
-> (MonoidMap k v -> Map k v) -> MonoidMap k v -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonoidMap k v -> Map k v
forall k v. MonoidMap k v -> Map k v
toMap
    hashWithSalt :: Int -> MonoidMap k v -> Int
hashWithSalt Int
i = Int -> Map k v -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
i (Map k v -> Int)
-> (MonoidMap k v -> Map k v) -> MonoidMap k v -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonoidMap k v -> Map k v
forall k v. MonoidMap k v -> Map k v
toMap