basement-0.0.16: Foundation scrap box of array & string

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Basement.Types.OffsetSize

Description

Synopsis

- newtype FileSize = FileSize Word64
- newtype Offset ty = Offset Int
- type Offset8 = Offset Word8
- sentinel :: Offset ty
- offsetOfE :: CountOf Word8 -> Offset ty -> Offset8
- offsetPlusE :: Offset ty -> CountOf ty -> Offset ty
- offsetMinusE :: Offset ty -> CountOf ty -> Offset ty
- offsetRecast :: CountOf Word8 -> CountOf Word8 -> Offset ty -> Offset ty2
- offsetCast :: Proxy (a -> b) -> Offset a -> Offset b
- offsetSub :: Offset a -> Offset a -> Offset a
- offsetShiftL :: Int -> Offset ty -> Offset ty2
- offsetShiftR :: Int -> Offset ty -> Offset ty2
- sizeCast :: Proxy (a -> b) -> CountOf a -> CountOf b
- sizeLastOffset :: CountOf a -> Offset a
- sizeAsOffset :: CountOf a -> Offset a
- sizeSub :: CountOf a -> CountOf a -> CountOf a
- countOfRoundUp :: Int -> CountOf ty -> CountOf ty
- offsetAsSize :: Offset a -> CountOf a
- (+.) :: Offset ty -> Int -> Offset ty
- (.==#) :: Offset ty -> CountOf ty -> Bool
- newtype CountOf ty = CountOf Int
- sizeOfE :: CountOf Word8 -> CountOf ty -> CountOf Word8
- csizeOfOffset :: Offset8 -> CSize
- csizeOfSize :: CountOf Word8 -> CSize
- sizeOfCSSize :: CSsize -> CountOf Word8
- sizeOfCSize :: CSize -> CountOf Word8
- type Countable ty (n :: Nat) = NatWithinBound (CountOf ty) n
- type Offsetable ty (n :: Nat) = NatWithinBound (Offset ty) n
- natValCountOf :: forall (n :: Nat) ty proxy. (KnownNat n, NatWithinBound (CountOf ty) n) => proxy n -> CountOf ty
- natValOffset :: forall (n :: Nat) ty proxy. (KnownNat n, NatWithinBound (Offset ty) n) => proxy n -> Offset ty

# Documentation

newtype FileSize Source #

File size in bytes

Constructors

FileSize Word64 |

#### Instances

Instances details

Show FileSize Source # |
Instance details Defined in Basement.Types.OffsetSize Methods showsPrec :: Int -> FileSize -> ShowS Source # show :: FileSize -> String Source # showList :: [FileSize] -> ShowS Source #
Eq FileSize Source # |
Instance details Defined in Basement.Types.OffsetSize Methods (==) :: FileSize -> FileSize -> Bool Source # (/=) :: FileSize -> FileSize -> Bool Source #
Ord FileSize Source # |
Instance details Defined in Basement.Types.OffsetSize Methods compare :: FileSize -> FileSize -> Ordering Source # (<) :: FileSize -> FileSize -> Bool Source # (<=) :: FileSize -> FileSize -> Bool Source # (>) :: FileSize -> FileSize -> Bool Source # (>=) :: FileSize -> FileSize -> Bool Source # max :: FileSize -> FileSize -> FileSize Source # min :: FileSize -> FileSize -> FileSize Source #

newtype Offset ty Source #

Offset in a data structure consisting of elements of type `ty`.

Int is a terrible backing type which is hard to get away from, considering that GHC/Haskell are mostly using this for offset. Trying to bring some sanity by a lightweight wrapping.

Constructors

Offset Int |

#### Instances

Instances details

From Word (Offset ty) Source # |
Instance details Defined in Basement.From Methods from :: Word -> Offset ty Source #
TryFrom Int (Offset ty) Source # |
Instance details Defined in Basement.From Methods tryFrom :: Int -> Maybe (Offset ty) Source #
Integral (Offset ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods fromInteger :: Integer -> Offset ty Source #
NormalForm (Offset a) Source # |
Instance details Defined in Basement.NormalForm Methods toNormalForm :: Offset a -> () Source #
Additive (Offset ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods azero :: Offset ty Source # (+) :: Offset ty -> Offset ty -> Offset ty Source # scale :: IsNatural n => n -> Offset ty -> Offset ty Source #
IsIntegral (Offset ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods toInteger :: Offset ty -> Integer Source #
IsNatural (Offset ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods toNatural :: Offset ty -> Natural Source #
Subtractive (Offset ty) Source # |

Instance details

Defined in Basement.Types.OffsetSize

Associated Types

type Difference (Offset ty) |
Instance details Defined in Basement.Types.OffsetSize type Difference (Offset ty) = CountOf ty

Methods

(-) :: Offset ty -> Offset ty -> Difference (Offset ty) Source #

Enum (Offset ty) Source # |

Instance details

Defined in Basement.Types.OffsetSize

Methods

succ :: Offset ty -> Offset ty Source #

pred :: Offset ty -> Offset ty Source #

toEnum :: Int -> Offset ty Source #

fromEnum :: Offset ty -> Int Source #

enumFrom :: Offset ty -> [Offset ty] Source #

enumFromThen :: Offset ty -> Offset ty -> [Offset ty] Source #

enumFromTo :: Offset ty -> Offset ty -> [Offset ty] Source #

enumFromThenTo :: Offset ty -> Offset ty -> Offset ty -> [Offset ty] Source #

Num (Offset ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods (+) :: Offset ty -> Offset ty -> Offset ty Source # (-) :: Offset ty -> Offset ty -> Offset ty Source # (*) :: Offset ty -> Offset ty -> Offset ty Source # negate :: Offset ty -> Offset ty Source # abs :: Offset ty -> Offset ty Source # signum :: Offset ty -> Offset ty Source # fromInteger :: Integer -> Offset ty Source #
Show (Offset ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods showsPrec :: Int -> Offset ty -> ShowS Source # show :: Offset ty -> String Source # showList :: [Offset ty] -> ShowS Source #
Eq (Offset ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods (==) :: Offset ty -> Offset ty -> Bool Source # (/=) :: Offset ty -> Offset ty -> Bool Source #
Ord (Offset ty) Source # |

Instance details

Defined in Basement.Types.OffsetSize

Methods

compare :: Offset ty -> Offset ty -> Ordering Source #

(<) :: Offset ty -> Offset ty -> Bool Source #

(<=) :: Offset ty -> Offset ty -> Bool Source #

(>) :: Offset ty -> Offset ty -> Bool Source #

(>=) :: Offset ty -> Offset ty -> Bool Source #

max :: Offset ty -> Offset ty -> Offset ty Source #

min :: Offset ty -> Offset ty -> Offset ty Source #

type NatNumMaxBound (Offset x) Source # |
Instance details Defined in Basement.Types.OffsetSize type NatNumMaxBound (Offset x) = NatNumMaxBound Int
type Difference (Offset ty) Source # |
Instance details Defined in Basement.Types.OffsetSize type Difference (Offset ty) = CountOf ty

type Offset8 = Offset Word8 Source #

Offset in bytes used for memory addressing (e.g. in a vector, string, ..)

sentinel :: Offset ty Source #

offsetOfE :: CountOf Word8 -> Offset ty -> Offset8 Source #

offsetPlusE :: Offset ty -> CountOf ty -> Offset ty Source #

offsetMinusE :: Offset ty -> CountOf ty -> Offset ty Source #

offsetRecast :: CountOf Word8 -> CountOf Word8 -> Offset ty -> Offset ty2 Source #

offsetCast :: Proxy (a -> b) -> Offset a -> Offset b Source #

offsetSub :: Offset a -> Offset a -> Offset a Source #

subtract 2 CountOf values of the same type.

m need to be greater than n, otherwise negative count error ensue use the safer (-) version if unsure.

offsetShiftL :: Int -> Offset ty -> Offset ty2 Source #

offsetShiftR :: Int -> Offset ty -> Offset ty2 Source #

sizeCast :: Proxy (a -> b) -> CountOf a -> CountOf b Source #

sizeLastOffset :: CountOf a -> Offset a Source #

sizeAsOffset :: CountOf a -> Offset a Source #

sizeSub :: CountOf a -> CountOf a -> CountOf a Source #

subtract 2 CountOf values of the same type.

m need to be greater than n, otherwise negative count error ensue use the safer (-) version if unsure.

countOfRoundUp :: Int -> CountOf ty -> CountOf ty Source #

alignment need to be a power of 2

offsetAsSize :: Offset a -> CountOf a Source #

(+.) :: Offset ty -> Int -> Offset ty Source #

(.==#) :: Offset ty -> CountOf ty -> Bool Source #

newtype CountOf ty Source #

CountOf of a data structure.

More specifically, it represents the number of elements of type `ty` that fit into the data structure.

    >>> length (fromList ['a', 'b', 'c', '🌟']) :: CountOf Char
    CountOf 4

Same caveats as `Offset` apply here.

Constructors

CountOf Int |

#### Instances

Instances details

From Word (CountOf ty) Source # |
Instance details Defined in Basement.From Methods from :: Word -> CountOf ty Source #
TryFrom Int (CountOf ty) Source # |
Instance details Defined in Basement.From Methods tryFrom :: Int -> Maybe (CountOf ty) Source #
Integral (CountOf ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods fromInteger :: Integer -> CountOf ty Source #
NormalForm (CountOf a) Source # |
Instance details Defined in Basement.NormalForm Methods toNormalForm :: CountOf a -> () Source #
Additive (CountOf ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods azero :: CountOf ty Source # (+) :: CountOf ty -> CountOf ty -> CountOf ty Source # scale :: IsNatural n => n -> CountOf ty -> CountOf ty Source #
IsIntegral (CountOf ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods toInteger :: CountOf ty -> Integer Source #
IsNatural (CountOf ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods toNatural :: CountOf ty -> Natural Source #
Subtractive (CountOf ty) Source # |

Instance details

Defined in Basement.Types.OffsetSize

Associated Types

type Difference (CountOf ty) |
Instance details Defined in Basement.Types.OffsetSize type Difference (CountOf ty) = Maybe (CountOf ty)

Methods

(-) :: CountOf ty -> CountOf ty -> Difference (CountOf ty) Source #

Monoid (CountOf ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods mempty :: CountOf ty Source # mappend :: CountOf ty -> CountOf ty -> CountOf ty Source # mconcat :: [CountOf ty] -> CountOf ty Source #
Semigroup (CountOf ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods (<>) :: CountOf ty -> CountOf ty -> CountOf ty Source # sconcat :: NonEmpty (CountOf ty) -> CountOf ty Source # stimes :: Integral b => b -> CountOf ty -> CountOf ty Source #
Enum (CountOf ty) Source # |

Instance details

Defined in Basement.Types.OffsetSize

Methods

succ :: CountOf ty -> CountOf ty Source #

pred :: CountOf ty -> CountOf ty Source #

toEnum :: Int -> CountOf ty Source #

fromEnum :: CountOf ty -> Int Source #

enumFrom :: CountOf ty -> [CountOf ty] Source #

enumFromThen :: CountOf ty -> CountOf ty -> [CountOf ty] Source #

enumFromTo :: CountOf ty -> CountOf ty -> [CountOf ty] Source #

enumFromThenTo :: CountOf ty -> CountOf ty -> CountOf ty -> [CountOf ty] Source #

Num (CountOf ty) Source # |

Instance details

Defined in Basement.Types.OffsetSize

Methods

(+) :: CountOf ty -> CountOf ty -> CountOf ty Source #

(-) :: CountOf ty -> CountOf ty -> CountOf ty Source #

(*) :: CountOf ty -> CountOf ty -> CountOf ty Source #

negate :: CountOf ty -> CountOf ty Source #

abs :: CountOf ty -> CountOf ty Source #

signum :: CountOf ty -> CountOf ty Source #

fromInteger :: Integer -> CountOf ty Source #

Show (CountOf ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods showsPrec :: Int -> CountOf ty -> ShowS Source # show :: CountOf ty -> String Source # showList :: [CountOf ty] -> ShowS Source #
Eq (CountOf ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods (==) :: CountOf ty -> CountOf ty -> Bool Source # (/=) :: CountOf ty -> CountOf ty -> Bool Source #
Ord (CountOf ty) Source # |

Instance details

Defined in Basement.Types.OffsetSize

Methods

compare :: CountOf ty -> CountOf ty -> Ordering Source #

(<) :: CountOf ty -> CountOf ty -> Bool Source #

(<=) :: CountOf ty -> CountOf ty -> Bool Source #

(>) :: CountOf ty -> CountOf ty -> Bool Source #

(>=) :: CountOf ty -> CountOf ty -> Bool Source #

max :: CountOf ty -> CountOf ty -> CountOf ty Source #

min :: CountOf ty -> CountOf ty -> CountOf ty Source #

From (CountOf ty) Int Source # |
Instance details Defined in Basement.From Methods from :: CountOf ty -> Int Source #
From (CountOf ty) Word Source # |
Instance details Defined in Basement.From Methods from :: CountOf ty -> Word Source #
type NatNumMaxBound (CountOf x) Source # |
Instance details Defined in Basement.Types.OffsetSize type NatNumMaxBound (CountOf x) = NatNumMaxBound Int
type Difference (CountOf ty) Source # |
Instance details Defined in Basement.Types.OffsetSize type Difference (CountOf ty) = Maybe (CountOf ty)

sizeOfE :: CountOf Word8 -> CountOf ty -> CountOf Word8 Source #

csizeOfOffset :: Offset8 -> CSize Source #

csizeOfSize :: CountOf Word8 -> CSize Source #

sizeOfCSSize :: CSsize -> CountOf Word8 Source #

sizeOfCSize :: CSize -> CountOf Word8 Source #

type Countable ty (n :: Nat) = NatWithinBound (CountOf ty) n Source #

type Offsetable ty (n :: Nat) = NatWithinBound (Offset ty) n Source #

natValCountOf :: forall (n :: Nat) ty proxy. (KnownNat n, NatWithinBound (CountOf ty) n) => proxy n -> CountOf ty Source #

natValOffset :: forall (n :: Nat) ty proxy. (KnownNat n, NatWithinBound (Offset ty) n) => proxy n -> Offset ty Source #