{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.Binary.Instances.UnorderedContainers where

import Data.Binary         (Binary, get, put)
import Data.Binary.Orphans ()

import qualified Data.Hashable     as Hashable
import qualified Data.HashMap.Lazy as HM
import qualified Data.HashSet      as HS

instance  (Hashable.Hashable k, Eq k, Binary k, Binary v) => Binary (HM.HashMap k v) where
    get :: Get (HashMap k v)
get = ([(k, v)] -> HashMap k v) -> Get [(k, v)] -> Get (HashMap k v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(k, v)] -> HashMap k v
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HM.fromList Get [(k, v)]
forall t. Binary t => Get t
get
    put :: HashMap k v -> Put
put = [(k, v)] -> Put
forall t. Binary t => t -> Put
put ([(k, v)] -> Put)
-> (HashMap k v -> [(k, v)]) -> HashMap k v -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap k v -> [(k, v)]
forall k v. HashMap k v -> [(k, v)]
HM.toList

instance (Hashable.Hashable v, Eq v, Binary v) => Binary (HS.HashSet v) where
    get :: Get (HashSet v)
get = ([v] -> HashSet v) -> Get [v] -> Get (HashSet v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [v] -> HashSet v
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HS.fromList Get [v]
forall t. Binary t => Get t
get
    put :: HashSet v -> Put
put = [v] -> Put
forall t. Binary t => t -> Put
put ([v] -> Put) -> (HashSet v -> [v]) -> HashSet v -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashSet v -> [v]
forall a. HashSet a -> [a]
HS.toList