<commit_before>{-# LANGUAGE BangPatterns, OverloadedStrings #-}

module Network.HPACK.Table.Entry (
  -- * Type
    Size
  , Entry
  , Header      -- re-exporting
  , HeaderName  -- re-exporting
  , HeaderValue -- re-exporting
  , Index       -- re-exporting
  -- * Header and Entry
  , toEntry
  , fromEntry
  -- * Getters
  , entrySize
  , entryHeaderName
  , entryHeaderValue
  -- * For initialization
  , dummyEntry
  , maxNumbers
  ) where

import Data.CaseInsensitive (foldedCase)
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Network.HPACK.Types

----------------------------------------------------------------

-- | Size in bytes.
type Size = Int

-- | Type for table entry.
type Entry = (Size,Header)

----------------------------------------------------------------

headerSizeMagicNumber :: Size
headerSizeMagicNumber = 32

headerSize :: Header -> Size
headerSize (k,v) = BS.length (foldedCase k) + BS.length v + headerSizeMagicNumber

----------------------------------------------------------------

-- | From 'Header' to 'Entry'.
toEntry :: Header -> Entry
toEntry h = (siz,h)
  where
    !siz = headerSize h

-- | From 'Entry' to 'Header'.
fromEntry :: Entry -> Header
fromEntry = snd

----------------------------------------------------------------

-- | Getting the size of 'Entry'.
entrySize :: Entry -> Size
entrySize = fst

-- | Getting 'HeaderName'.
entryHeaderName :: Entry -> HeaderName
entryHeaderName (_,(k,_)) = k

-- | Getting 'HeaderValue'. (FIXME)
entryHeaderValue :: Entry -> ByteString
entryHeaderValue (_,(_,v)) = v

----------------------------------------------------------------

-- | Dummy 'Entry' to initialize a table.
dummyEntry :: Entry
dummyEntry = (0,("",""))

maxNumbers :: Size -> Int
maxNumbers siz = siz `div` headerSizeMagicNumber<commit_msg>lower case.<commit_after>{-# LANGUAGE BangPatterns, OverloadedStrings #-}

module Network.HPACK.Table.Entry (
  -- * Type
    Size
  , Entry
  , Header      -- re-exporting
  , HeaderName  -- re-exporting
  , HeaderValue -- re-exporting
  , Index       -- re-exporting
  -- * Header and Entry
  , toEntry
  , fromEntry
  -- * Getters
  , entrySize
  , entryHeaderName
  , entryHeaderValue
  -- * For initialization
  , dummyEntry
  , maxNumbers
  ) where

import Data.CaseInsensitive (foldedCase)
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Network.HPACK.Types

----------------------------------------------------------------

-- | Size in bytes.
type Size = Int

-- | Type for table entry.
type Entry = (Size,Header)

----------------------------------------------------------------

headerSizeMagicNumber :: Size
headerSizeMagicNumber = 32

headerSize :: Header -> Size
headerSize (k,v) = BS.length (foldedCase k) + BS.length v + headerSizeMagicNumber

----------------------------------------------------------------

-- | From 'Header' to 'Entry'.
toEntry :: Header -> Entry
toEntry h = (siz,h)
  where
    !siz = headerSize h

-- | From 'Entry' to 'Header'.
fromEntry :: Entry -> Header
fromEntry = snd

----------------------------------------------------------------

-- | Getting the size of 'Entry'.
entrySize :: Entry -> Size
entrySize = fst

-- | Getting 'HeaderName'.
entryHeaderName :: Entry -> HeaderName
entryHeaderName (_,(k,_)) = k

-- | Getting 'HeaderValue'. (FIXME)
entryHeaderValue :: Entry -> ByteString
entryHeaderValue (_,(_,v)) = v

----------------------------------------------------------------

-- | Dummy 'Entry' to initialize a table.
dummyEntry :: Entry
dummyEntry = (0,("dummy","dummy"))

maxNumbers :: Size -> Int
maxNumbers siz = siz `div` headerSizeMagicNumber
{'fraction_non_alphanumeric': 0.280993992353905, 'fraction_numerical': 0.0016384489350081922, 'mean_word_length': 1.7113249444855663, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5872149', 'n_tokens_mistral': 1007, 'n_tokens_neox': 987, 'n_words': 280}