-- SPDX-FileCopyrightText: 2026 Alexandra de Wit
--
-- SPDX-License-Identifier: MIT

{- | Retained-document accounting and fixed resource estimates.
Compact representation charges differ from original source bytes. The retained estimate
does not bound active input, parser, policy, merge, or output memory.
-}
module Ecluse.Core.Server.MemoryModel (
    expandWireBytes,
    chargeForResident,
    mirrorJobEstimatedBytes,
) where

{- | Estimate retained bytes from a compact representation charge using the 7.5 factor.
This factor is independent of source-byte regression envelopes and active-work admission.
-}
expandWireBytes :: Int -> Int
expandWireBytes :: Int -> Int
expandWireBytes Int
wireBytes = Int
wireBytes Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
residentRatioNumerator Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
residentRatioDenominator

-- | The smallest compact charge that 'expandWireBytes' expands to at least the given heap bytes.
chargeForResident :: Int -> Int
chargeForResident :: Int -> Int
chargeForResident Int
resident = (Int
resident Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
residentRatioDenominator Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
residentRatioNumerator Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
residentRatioNumerator

residentRatioNumerator :: Int
residentRatioNumerator :: Int
residentRatioNumerator = Int
15

residentRatioDenominator :: Int
residentRatioDenominator :: Int
residentRatioDenominator = Int
2

-- | The resident-byte allowance per in-memory mirror queue slot.
mirrorJobEstimatedBytes :: Int
mirrorJobEstimatedBytes :: Int
mirrorJobEstimatedBytes = Int
1024