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 #

File size in bytes

Constructors

FileSize Word64 |

#### Instances

Instances details

Show FileSize # |
Instance details Defined in Basement.Types.OffsetSize Methods showsPrec :: Int -> FileSize -> ShowS # show :: FileSize -> String # showList :: [FileSize] -> ShowS #
Eq FileSize # |
Instance details Defined in Basement.Types.OffsetSize Methods (==) :: FileSize -> FileSize -> Bool # (/=) :: FileSize -> FileSize -> Bool #
Ord FileSize # |
Instance details Defined in Basement.Types.OffsetSize 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 #

newtype Offset ty #

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) # |
Instance details Defined in Basement.From Methods from :: Word -> Offset ty #
TryFrom Int (Offset ty) # |
Instance details Defined in Basement.From Methods tryFrom :: Int -> Maybe (Offset ty) #
Integral (Offset ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods fromInteger :: Integer -> Offset ty #
NormalForm (Offset a) # |
Instance details Defined in Basement.NormalForm Methods toNormalForm :: Offset a -> () #
Additive (Offset ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods azero :: Offset ty # (+) :: Offset ty -> Offset ty -> Offset ty # scale :: IsNatural n => n -> Offset ty -> Offset ty #
IsIntegral (Offset ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods toInteger :: Offset ty -> Integer #
IsNatural (Offset ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods toNatural :: Offset ty -> Natural #
Subtractive (Offset ty) # |
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) #
Enum (Offset ty) # |
Instance details Defined in Basement.Types.OffsetSize 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] #
Num (Offset ty) # |
Instance details Defined in Basement.Types.OffsetSize 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 #
Show (Offset ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods showsPrec :: Int -> Offset ty -> ShowS # show :: Offset ty -> String # showList :: [Offset ty] -> ShowS #
Eq (Offset ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods (==) :: Offset ty -> Offset ty -> Bool # (/=) :: Offset ty -> Offset ty -> Bool #
Ord (Offset ty) # |
Instance details Defined in Basement.Types.OffsetSize 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 #
type NatNumMaxBound (Offset x) # |
Instance details Defined in Basement.Types.OffsetSize type NatNumMaxBound (Offset x) = NatNumMaxBound Int
type Difference (Offset ty) # |
Instance details Defined in Basement.Types.OffsetSize type Difference (Offset ty) = CountOf ty

type Offset8 = Offset Word8 #

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

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 #

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 #

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 #

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 #

alignment need to be a power of 2

offsetAsSize :: Offset a -> CountOf a #

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

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

newtype CountOf ty #

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) # |
Instance details Defined in Basement.From Methods from :: Word -> CountOf ty #
TryFrom Int (CountOf ty) # |
Instance details Defined in Basement.From Methods tryFrom :: Int -> Maybe (CountOf ty) #
Integral (CountOf ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods fromInteger :: Integer -> CountOf ty #
NormalForm (CountOf a) # |
Instance details Defined in Basement.NormalForm Methods toNormalForm :: CountOf a -> () #
Additive (CountOf ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods azero :: CountOf ty # (+) :: CountOf ty -> CountOf ty -> CountOf ty # scale :: IsNatural n => n -> CountOf ty -> CountOf ty #
IsIntegral (CountOf ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods toInteger :: CountOf ty -> Integer #
IsNatural (CountOf ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods toNatural :: CountOf ty -> Natural #
Subtractive (CountOf ty) # |
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) #
Monoid (CountOf ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods mempty :: CountOf ty # mappend :: CountOf ty -> CountOf ty -> CountOf ty # mconcat :: [CountOf ty] -> CountOf ty #
Semigroup (CountOf ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods (<>) :: CountOf ty -> CountOf ty -> CountOf ty # sconcat :: NonEmpty (CountOf ty) -> CountOf ty # stimes :: Integral b => b -> CountOf ty -> CountOf ty #
Enum (CountOf ty) # |
Instance details Defined in Basement.Types.OffsetSize 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] #
Num (CountOf ty) # |
Instance details Defined in Basement.Types.OffsetSize 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 #
Show (CountOf ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods showsPrec :: Int -> CountOf ty -> ShowS # show :: CountOf ty -> String # showList :: [CountOf ty] -> ShowS #
Eq (CountOf ty) # |
Instance details Defined in Basement.Types.OffsetSize Methods (==) :: CountOf ty -> CountOf ty -> Bool # (/=) :: CountOf ty -> CountOf ty -> Bool #
Ord (CountOf ty) # |
Instance details Defined in Basement.Types.OffsetSize 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 #
From (CountOf ty) Int # |
Instance details Defined in Basement.From Methods from :: CountOf ty -> Int #
From (CountOf ty) Word # |
Instance details Defined in Basement.From Methods from :: CountOf ty -> Word #
type NatNumMaxBound (CountOf x) # |
Instance details Defined in Basement.Types.OffsetSize type NatNumMaxBound (CountOf x) = NatNumMaxBound Int
type Difference (CountOf ty) # |
Instance details Defined in Basement.Types.OffsetSize type Difference (CountOf ty) = Maybe (CountOf ty)

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 #