{-# LANGUAGE DerivingVia #-}
module GHC.Debug.Profile.Types where

import           GHC.Debug.Types
import Data.Monoid
import Data.Semigroup

newtype Count = Count Int
                deriving (NonEmpty Count -> Count
Count -> Count -> Count
forall b. Integral b => b -> Count -> Count
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> Count -> Count
$cstimes :: forall b. Integral b => b -> Count -> Count
sconcat :: NonEmpty Count -> Count
$csconcat :: NonEmpty Count -> Count
<> :: Count -> Count -> Count
$c<> :: Count -> Count -> Count
Semigroup, Semigroup Count
Count
[Count] -> Count
Count -> Count -> Count
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [Count] -> Count
$cmconcat :: [Count] -> Count
mappend :: Count -> Count -> Count
$cmappend :: Count -> Count -> Count
mempty :: Count
$cmempty :: Count
Monoid, Integer -> Count
Count -> Count
Count -> Count -> Count
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> Count
$cfromInteger :: Integer -> Count
signum :: Count -> Count
$csignum :: Count -> Count
abs :: Count -> Count
$cabs :: Count -> Count
negate :: Count -> Count
$cnegate :: Count -> Count
* :: Count -> Count -> Count
$c* :: Count -> Count -> Count
- :: Count -> Count -> Count
$c- :: Count -> Count -> Count
+ :: Count -> Count -> Count
$c+ :: Count -> Count -> Count
Num) via Sum Int
                deriving (Int -> Count -> ShowS
[Count] -> ShowS
Count -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Count] -> ShowS
$cshowList :: [Count] -> ShowS
show :: Count -> String
$cshow :: Count -> String
showsPrec :: Int -> Count -> ShowS
$cshowsPrec :: Int -> Count -> ShowS
Show, Eq Count
Count -> Count -> Bool
Count -> Count -> Ordering
Count -> Count -> Count
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Count -> Count -> Count
$cmin :: Count -> Count -> Count
max :: Count -> Count -> Count
$cmax :: Count -> Count -> Count
>= :: Count -> Count -> Bool
$c>= :: Count -> Count -> Bool
> :: Count -> Count -> Bool
$c> :: Count -> Count -> Bool
<= :: Count -> Count -> Bool
$c<= :: Count -> Count -> Bool
< :: Count -> Count -> Bool
$c< :: Count -> Count -> Bool
compare :: Count -> Count -> Ordering
$ccompare :: Count -> Count -> Ordering
Ord, Count -> Count -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Count -> Count -> Bool
$c/= :: Count -> Count -> Bool
== :: Count -> Count -> Bool
$c== :: Count -> Count -> Bool
Eq)

data CensusStats = CS { CensusStats -> Count
cscount :: !Count, CensusStats -> Size
cssize :: !Size, CensusStats -> Max Size
csmax :: !(Max Size) } deriving (Int -> CensusStats -> ShowS
[CensusStats] -> ShowS
CensusStats -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CensusStats] -> ShowS
$cshowList :: [CensusStats] -> ShowS
show :: CensusStats -> String
$cshow :: CensusStats -> String
showsPrec :: Int -> CensusStats -> ShowS
$cshowsPrec :: Int -> CensusStats -> ShowS
Show, CensusStats -> CensusStats -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CensusStats -> CensusStats -> Bool
$c/= :: CensusStats -> CensusStats -> Bool
== :: CensusStats -> CensusStats -> Bool
$c== :: CensusStats -> CensusStats -> Bool
Eq)

mkCS :: Size -> CensusStats
mkCS :: Size -> CensusStats
mkCS Size
i = Count -> Size -> Max Size -> CensusStats
CS (Int -> Count
Count Int
1) Size
i (forall a. a -> Max a
Max Size
i)

instance Monoid CensusStats where
  mempty :: CensusStats
mempty = Count -> Size -> Max Size -> CensusStats
CS forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty (forall a. a -> Max a
Max (Int -> Size
Size Int
0))

instance Semigroup CensusStats where
  (CS Count
a Size
b Max Size
c) <> :: CensusStats -> CensusStats -> CensusStats
<> (CS Count
a1 Size
b1 Max Size
c1) = Count -> Size -> Max Size -> CensusStats
CS (Count
a forall a. Semigroup a => a -> a -> a
<> Count
a1) (Size
b forall a. Semigroup a => a -> a -> a
<> Size
b1) (Max Size
c forall a. Semigroup a => a -> a -> a
<> Max Size
c1)