-- |
-- Module:     Data.Vector.Algorithms.Quicksort.Predefined.Pair
-- Copyright:  (c) Sergey Vinokurov 2023
-- License:    Apache-2.0 (see LICENSE)
-- Maintainer: serg.foo@gmail.com

{-# LANGUAGE DerivingVia  #-}
{-# LANGUAGE TypeFamilies #-}

module Data.Vector.Algorithms.Quicksort.Predefined.Pair
  ( TestPair(..)
  , toTuple
  ) where

import Data.Vector.Generic qualified as G
import Data.Vector.Generic.Mutable qualified as GM
import Data.Vector.Unboxed qualified as U

data TestPair a b = TestPair a b
  deriving (Int -> TestPair a b -> ShowS
[TestPair a b] -> ShowS
TestPair a b -> String
(Int -> TestPair a b -> ShowS)
-> (TestPair a b -> String)
-> ([TestPair a b] -> ShowS)
-> Show (TestPair a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> TestPair a b -> ShowS
forall a b. (Show a, Show b) => [TestPair a b] -> ShowS
forall a b. (Show a, Show b) => TestPair a b -> String
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> TestPair a b -> ShowS
showsPrec :: Int -> TestPair a b -> ShowS
$cshow :: forall a b. (Show a, Show b) => TestPair a b -> String
show :: TestPair a b -> String
$cshowList :: forall a b. (Show a, Show b) => [TestPair a b] -> ShowS
showList :: [TestPair a b] -> ShowS
Show)

{-# INLINE toTuple #-}
toTuple :: TestPair a b -> (a, b)
toTuple :: forall a b. TestPair a b -> (a, b)
toTuple (TestPair a
a b
b) = (a
a, b
b)

instance U.IsoUnbox (TestPair a b) (a, b) where
  {-# INLINE toURepr   #-}
  {-# INLINE fromURepr #-}
  toURepr :: TestPair a b -> (a, b)
toURepr          = TestPair a b -> (a, b)
forall a b. TestPair a b -> (a, b)
toTuple
  fromURepr :: (a, b) -> TestPair a b
fromURepr (a
a, b
b) = a -> b -> TestPair a b
forall a b. a -> b -> TestPair a b
TestPair a
a b
b

newtype instance U.MVector s (TestPair a b) = MV_TestPair (U.MVector s (a, b))
newtype instance U.Vector    (TestPair a b) = V_TestPair  (U.Vector    (a, b))
deriving via (TestPair a b `U.As` (a, b)) instance (U.Unbox a, U.Unbox b) => GM.MVector U.MVector (TestPair a b)
deriving via (TestPair a b `U.As` (a, b)) instance (U.Unbox a, U.Unbox b) => G.Vector   U.Vector  (TestPair a b)
instance (U.Unbox a, U.Unbox b) => U.Unbox (TestPair a b)

instance Eq a => Eq (TestPair a b) where
  TestPair a
x b
_ == :: TestPair a b -> TestPair a b -> Bool
== TestPair a
x' b
_ = a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
x'

instance Ord a => Ord (TestPair a b) where
  TestPair a
x b
_ compare :: TestPair a b -> TestPair a b -> Ordering
`compare` TestPair a
x' b
_ = a
x a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` a
x'