basement-0.0.4: 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
- 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 = NatWithinBound (CountOf ty) n
- type Offsetable ty n = NatWithinBound (Offset ty) n
- natValCountOf :: forall n ty proxy. (KnownNat n, NatWithinBound (CountOf ty) n) => proxy n -> CountOf ty
- natValOffset :: forall n ty proxy. (KnownNat n, NatWithinBound (Offset ty) n) => proxy n -> Offset ty

# Documentation

newtype FileSize Source #

File size in bytes

Constructors

FileSize Word64 |

Instances

Eq FileSize Source # |
Methods (==) :: FileSize -> FileSize -> Bool # (/=) :: FileSize -> FileSize -> Bool #
Ord FileSize Source # |
Methods compare :: FileSize -> FileSize -> Ordering # (<) :: FileSize -> FileSize -> Bool # (<=) :: FileSize -> FileSize -> Bool # (>) :: FileSize -> FileSize -> Bool # (>=) :: FileSize -> FileSize -> Bool # max :: FileSize -> FileSize -> FileSize # min :: FileSize -> FileSize -> FileSize #
Show FileSize Source # |
Methods showsPrec :: Int -> FileSize -> ShowS # show :: FileSize -> String # showList :: [FileSize] -> ShowS #

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

IntegralCast Int (Offset ty) Source # |
Methods integralCast :: Int -> Offset ty Source #
IntegralCast Word (Offset ty) Source # |
Methods integralCast :: Word -> Offset ty Source #
Enum (Offset ty) Source # |
Methods succ :: Offset ty -> Offset ty # pred :: Offset ty -> Offset ty # toEnum :: Int -> Offset ty # fromEnum :: Offset ty -> Int # enumFrom :: Offset ty -> [Offset ty] # enumFromThen :: Offset ty -> Offset ty -> [Offset ty] # enumFromTo :: Offset ty -> Offset ty -> [Offset ty] # enumFromThenTo :: Offset ty -> Offset ty -> Offset ty -> [Offset ty] #
Eq (Offset ty) Source # |
Methods (==) :: Offset ty -> Offset ty -> Bool # (/=) :: Offset ty -> Offset ty -> Bool #
Num (Offset ty) Source # |
Methods (+) :: Offset ty -> Offset ty -> Offset ty # (-) :: Offset ty -> Offset ty -> Offset ty # (*) :: Offset ty -> Offset ty -> Offset ty # negate :: Offset ty -> Offset ty # abs :: Offset ty -> Offset ty # signum :: Offset ty -> Offset ty # fromInteger :: Integer -> Offset ty #
Ord (Offset ty) Source # |
Methods compare :: Offset ty -> Offset ty -> Ordering # (<) :: Offset ty -> Offset ty -> Bool # (<=) :: Offset ty -> Offset ty -> Bool # (>) :: Offset ty -> Offset ty -> Bool # (>=) :: Offset ty -> Offset ty -> Bool # max :: Offset ty -> Offset ty -> Offset ty # min :: Offset ty -> Offset ty -> Offset ty #
Show (Offset ty) Source # |
Methods showsPrec :: Int -> Offset ty -> ShowS # show :: Offset ty -> String # showList :: [Offset ty] -> ShowS #
Integral (Offset ty) Source # |
Methods fromInteger :: Integer -> Offset ty Source #
IsNatural (Offset ty) Source # |
Methods toNatural :: Offset ty -> Natural Source #
IsIntegral (Offset ty) Source # |
Methods toInteger :: Offset ty -> Integer Source #
Additive (Offset ty) Source # |
Methods azero :: Offset ty Source # (+) :: Offset ty -> Offset ty -> Offset ty Source # scale :: IsNatural n => n -> Offset ty -> Offset ty Source #
Subtractive (Offset ty) Source # |
Associated Types type Difference (Offset ty) :: * Source # Methods (-) :: Offset ty -> Offset ty -> Difference (Offset ty) Source #
NormalForm (Offset a) Source # |
Methods toNormalForm :: Offset a -> () Source #
type NatNumMaxBound (Offset x) Source # |
type NatNumMaxBound (Offset x) = NatNumMaxBound Int
type Difference (Offset ty) Source # |
type Difference (Offset ty) = CountOf ty

type Offset8 = Offset Word8 Source #

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

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

IntegralCast Int (CountOf ty) Source # |
Methods integralCast :: Int -> CountOf ty Source #
IntegralCast Word (CountOf ty) Source # |
Methods integralCast :: Word -> CountOf ty Source #
Enum (CountOf ty) Source # |
Methods succ :: CountOf ty -> CountOf ty # pred :: CountOf ty -> CountOf ty # toEnum :: Int -> CountOf ty # fromEnum :: CountOf ty -> Int # enumFrom :: CountOf ty -> [CountOf ty] # enumFromThen :: CountOf ty -> CountOf ty -> [CountOf ty] # enumFromTo :: CountOf ty -> CountOf ty -> [CountOf ty] # enumFromThenTo :: CountOf ty -> CountOf ty -> CountOf ty -> [CountOf ty] #
Eq (CountOf ty) Source # |
Methods (==) :: CountOf ty -> CountOf ty -> Bool # (/=) :: CountOf ty -> CountOf ty -> Bool #
Num (CountOf ty) Source # |
Methods (+) :: CountOf ty -> CountOf ty -> CountOf ty # (-) :: CountOf ty -> CountOf ty -> CountOf ty # (*) :: CountOf ty -> CountOf ty -> CountOf ty # negate :: CountOf ty -> CountOf ty # abs :: CountOf ty -> CountOf ty # signum :: CountOf ty -> CountOf ty # fromInteger :: Integer -> CountOf ty #
Ord (CountOf ty) Source # |
Methods compare :: CountOf ty -> CountOf ty -> Ordering # (<) :: CountOf ty -> CountOf ty -> Bool # (<=) :: CountOf ty -> CountOf ty -> Bool # (>) :: CountOf ty -> CountOf ty -> Bool # (>=) :: CountOf ty -> CountOf ty -> Bool # max :: CountOf ty -> CountOf ty -> CountOf ty # min :: CountOf ty -> CountOf ty -> CountOf ty #
Show (CountOf ty) Source # |
Methods showsPrec :: Int -> CountOf ty -> ShowS # show :: CountOf ty -> String # showList :: [CountOf ty] -> ShowS #
Semigroup (CountOf ty) Source # |
Methods (<>) :: CountOf ty -> CountOf ty -> CountOf ty # sconcat :: NonEmpty (CountOf ty) -> CountOf ty # stimes :: Integral b => b -> CountOf ty -> CountOf ty #
Monoid (CountOf ty) Source # |
Methods mempty :: CountOf ty # mappend :: CountOf ty -> CountOf ty -> CountOf ty # mconcat :: [CountOf ty] -> CountOf ty #
Integral (CountOf ty) Source # |
Methods fromInteger :: Integer -> CountOf ty Source #
IsNatural (CountOf ty) Source # |
Methods toNatural :: CountOf ty -> Natural Source #
IsIntegral (CountOf ty) Source # |
Methods toInteger :: CountOf ty -> Integer Source #
Additive (CountOf ty) Source # |
Methods azero :: CountOf ty Source # (+) :: CountOf ty -> CountOf ty -> CountOf ty Source # scale :: IsNatural n => n -> CountOf ty -> CountOf ty Source #
Subtractive (CountOf ty) Source # |
Associated Types type Difference (CountOf ty) :: * Source # Methods (-) :: CountOf ty -> CountOf ty -> Difference (CountOf ty) Source #
NormalForm (CountOf a) Source # |
Methods toNormalForm :: CountOf a -> () Source #
From (CountOf ty) Word Source # |
Methods from :: CountOf ty -> Word Source #
From (CountOf ty) Int Source # |
Methods from :: CountOf ty -> Int Source #
type NatNumMaxBound (CountOf x) Source # |
type NatNumMaxBound (CountOf x) = NatNumMaxBound Int
type Difference (CountOf ty) Source # |
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 = NatWithinBound (CountOf ty) n Source #

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

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

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