basement-0.0.11: Foundation scrap box of array & string

License | BSD-style
Maintainer | Haskell Foundation
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Basement.Bits

Description

Synopsis

- class BitOps bits where
  - (.&.) :: bits -> bits -> bits
  - (.|.) :: bits -> bits -> bits
  - (.^.) :: bits -> bits -> bits
  - (.<<.) :: bits -> CountOf Bool -> bits
  - (.>>.) :: bits -> CountOf Bool -> bits
  - bit :: Offset Bool -> bits
  - isBitSet :: bits -> Offset Bool -> Bool
  - setBit :: bits -> Offset Bool -> bits
  - clearBit :: bits -> Offset Bool -> bits
- class FiniteBitsOps bits where
  - numberOfBits :: bits -> CountOf Bool
  - rotateL :: bits -> CountOf Bool -> bits
  - rotateR :: bits -> CountOf Bool -> bits
  - popCount :: bits -> CountOf Bool
  - bitFlip :: bits -> bits
  - countLeadingZeros :: bits -> CountOf Bool
  - countTrailingZeros :: bits -> CountOf Bool
- data Bits (n :: Nat)
- toBits :: SizeValid n => Natural -> Bits n
- allOne :: forall n. SizeValid n => Bits n

# Documentation

class BitOps bits where Source #

operation over bits

Minimal complete definition

(.&.), (.|.), (.^.), (.<<.), (.>>.)

Methods

(.&.) :: bits -> bits -> bits infixl 7 Source #

(.|.) :: bits -> bits -> bits infixl 5 Source #

(.^.) :: bits -> bits -> bits infixl 6 Source #

(.<<.) :: bits -> CountOf Bool -> bits infixl 8 Source #

(.>>.) :: bits -> CountOf Bool -> bits infixl 8 Source #

bit :: Offset Bool -> bits Source #

construct a bit set with the bit at the given index set.

default bit :: Integral bits => Offset Bool -> bits Source #

isBitSet :: bits -> Offset Bool -> Bool Source #

test the bit at the given index is set

default isBitSet :: (Integral bits, Eq bits) => bits -> Offset Bool -> Bool Source #

setBit :: bits -> Offset Bool -> bits Source #

set the bit at the given index

default setBit :: Integral bits => bits -> Offset Bool -> bits Source #

clearBit :: bits -> Offset Bool -> bits Source #

clear the bit at the given index

default clearBit :: FiniteBitsOps bits => bits -> Offset Bool -> bits Source #

#### Instances

Instances details

BitOps Bool Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Bool -> Bool -> Bool Source #

(.|.) :: Bool -> Bool -> Bool Source #

(.^.) :: Bool -> Bool -> Bool Source #

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

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

bit :: Offset Bool -> Bool Source #

isBitSet :: Bool -> Offset Bool -> Bool Source #

setBit :: Bool -> Offset Bool -> Bool Source #

clearBit :: Bool -> Offset Bool -> Bool Source #

BitOps Int8 Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Int8 -> Int8 -> Int8 Source #

(.|.) :: Int8 -> Int8 -> Int8 Source #

(.^.) :: Int8 -> Int8 -> Int8 Source #

(.<<.) :: Int8 -> CountOf Bool -> Int8 Source #

(.>>.) :: Int8 -> CountOf Bool -> Int8 Source #

bit :: Offset Bool -> Int8 Source #

isBitSet :: Int8 -> Offset Bool -> Bool Source #

setBit :: Int8 -> Offset Bool -> Int8 Source #

clearBit :: Int8 -> Offset Bool -> Int8 Source #

BitOps Int16 Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Int16 -> Int16 -> Int16 Source #

(.|.) :: Int16 -> Int16 -> Int16 Source #

(.^.) :: Int16 -> Int16 -> Int16 Source #

(.<<.) :: Int16 -> CountOf Bool -> Int16 Source #

(.>>.) :: Int16 -> CountOf Bool -> Int16 Source #

bit :: Offset Bool -> Int16 Source #

isBitSet :: Int16 -> Offset Bool -> Bool Source #

setBit :: Int16 -> Offset Bool -> Int16 Source #

clearBit :: Int16 -> Offset Bool -> Int16 Source #

BitOps Int32 Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Int32 -> Int32 -> Int32 Source #

(.|.) :: Int32 -> Int32 -> Int32 Source #

(.^.) :: Int32 -> Int32 -> Int32 Source #

(.<<.) :: Int32 -> CountOf Bool -> Int32 Source #

(.>>.) :: Int32 -> CountOf Bool -> Int32 Source #

bit :: Offset Bool -> Int32 Source #

isBitSet :: Int32 -> Offset Bool -> Bool Source #

setBit :: Int32 -> Offset Bool -> Int32 Source #

clearBit :: Int32 -> Offset Bool -> Int32 Source #

BitOps Int64 Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Int64 -> Int64 -> Int64 Source #

(.|.) :: Int64 -> Int64 -> Int64 Source #

(.^.) :: Int64 -> Int64 -> Int64 Source #

(.<<.) :: Int64 -> CountOf Bool -> Int64 Source #

(.>>.) :: Int64 -> CountOf Bool -> Int64 Source #

bit :: Offset Bool -> Int64 Source #

isBitSet :: Int64 -> Offset Bool -> Bool Source #

setBit :: Int64 -> Offset Bool -> Int64 Source #

clearBit :: Int64 -> Offset Bool -> Int64 Source #

BitOps Word Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Word -> Word -> Word Source #

(.|.) :: Word -> Word -> Word Source #

(.^.) :: Word -> Word -> Word Source #

(.<<.) :: Word -> CountOf Bool -> Word Source #

(.>>.) :: Word -> CountOf Bool -> Word Source #

bit :: Offset Bool -> Word Source #

isBitSet :: Word -> Offset Bool -> Bool Source #

setBit :: Word -> Offset Bool -> Word Source #

clearBit :: Word -> Offset Bool -> Word Source #

BitOps Word8 Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Word8 -> Word8 -> Word8 Source #

(.|.) :: Word8 -> Word8 -> Word8 Source #

(.^.) :: Word8 -> Word8 -> Word8 Source #

(.<<.) :: Word8 -> CountOf Bool -> Word8 Source #

(.>>.) :: Word8 -> CountOf Bool -> Word8 Source #

bit :: Offset Bool -> Word8 Source #

isBitSet :: Word8 -> Offset Bool -> Bool Source #

setBit :: Word8 -> Offset Bool -> Word8 Source #

clearBit :: Word8 -> Offset Bool -> Word8 Source #

BitOps Word16 Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Word16 -> Word16 -> Word16 Source #

(.|.) :: Word16 -> Word16 -> Word16 Source #

(.^.) :: Word16 -> Word16 -> Word16 Source #

(.<<.) :: Word16 -> CountOf Bool -> Word16 Source #

(.>>.) :: Word16 -> CountOf Bool -> Word16 Source #

bit :: Offset Bool -> Word16 Source #

isBitSet :: Word16 -> Offset Bool -> Bool Source #

setBit :: Word16 -> Offset Bool -> Word16 Source #

clearBit :: Word16 -> Offset Bool -> Word16 Source #

BitOps Word32 Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Word32 -> Word32 -> Word32 Source #

(.|.) :: Word32 -> Word32 -> Word32 Source #

(.^.) :: Word32 -> Word32 -> Word32 Source #

(.<<.) :: Word32 -> CountOf Bool -> Word32 Source #

(.>>.) :: Word32 -> CountOf Bool -> Word32 Source #

bit :: Offset Bool -> Word32 Source #

isBitSet :: Word32 -> Offset Bool -> Bool Source #

setBit :: Word32 -> Offset Bool -> Word32 Source #

clearBit :: Word32 -> Offset Bool -> Word32 Source #

BitOps Word64 Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Word64 -> Word64 -> Word64 Source #

(.|.) :: Word64 -> Word64 -> Word64 Source #

(.^.) :: Word64 -> Word64 -> Word64 Source #

(.<<.) :: Word64 -> CountOf Bool -> Word64 Source #

(.>>.) :: Word64 -> CountOf Bool -> Word64 Source #

bit :: Offset Bool -> Word64 Source #

isBitSet :: Word64 -> Offset Bool -> Bool Source #

setBit :: Word64 -> Offset Bool -> Word64 Source #

clearBit :: Word64 -> Offset Bool -> Word64 Source #

BitOps Word128 Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Word128 -> Word128 -> Word128 Source #

(.|.) :: Word128 -> Word128 -> Word128 Source #

(.^.) :: Word128 -> Word128 -> Word128 Source #

(.<<.) :: Word128 -> CountOf Bool -> Word128 Source #

(.>>.) :: Word128 -> CountOf Bool -> Word128 Source #

bit :: Offset Bool -> Word128 Source #

isBitSet :: Word128 -> Offset Bool -> Bool Source #

setBit :: Word128 -> Offset Bool -> Word128 Source #

clearBit :: Word128 -> Offset Bool -> Word128 Source #

BitOps Word256 Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Word256 -> Word256 -> Word256 Source #

(.|.) :: Word256 -> Word256 -> Word256 Source #

(.^.) :: Word256 -> Word256 -> Word256 Source #

(.<<.) :: Word256 -> CountOf Bool -> Word256 Source #

(.>>.) :: Word256 -> CountOf Bool -> Word256 Source #

bit :: Offset Bool -> Word256 Source #

isBitSet :: Word256 -> Offset Bool -> Bool Source #

setBit :: Word256 -> Offset Bool -> Word256 Source #

clearBit :: Word256 -> Offset Bool -> Word256 Source #

SizeValid n => BitOps (Bits n) Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Bits n -> Bits n -> Bits n Source #

(.|.) :: Bits n -> Bits n -> Bits n Source #

(.^.) :: Bits n -> Bits n -> Bits n Source #

(.<<.) :: Bits n -> CountOf Bool -> Bits n Source #

(.>>.) :: Bits n -> CountOf Bool -> Bits n Source #

bit :: Offset Bool -> Bits n Source #

isBitSet :: Bits n -> Offset Bool -> Bool Source #

setBit :: Bits n -> Offset Bool -> Bits n Source #

clearBit :: Bits n -> Offset Bool -> Bits n Source #

class FiniteBitsOps bits where Source #

operation over finite bits

Minimal complete definition

numberOfBits, rotateL, rotateR, popCount, bitFlip

Methods

numberOfBits :: bits -> CountOf Bool Source #

get the number of bits in the given object

rotateL :: bits -> CountOf Bool -> bits infixl 8 Source #

rotate the given bit set.

rotateR :: bits -> CountOf Bool -> bits infixl 8 Source #

rotate the given bit set.

popCount :: bits -> CountOf Bool Source #

count of number of bit set to 1 in the given bit set.

bitFlip :: bits -> bits Source #

reverse all bits in the argument

countLeadingZeros :: bits -> CountOf Bool Source #

count of the number of leading zeros

default countLeadingZeros :: BitOps bits => bits -> CountOf Bool Source #

countTrailingZeros :: bits -> CountOf Bool Source #

count of the number of trailing zeros

default countTrailingZeros :: BitOps bits => bits -> CountOf Bool Source #

#### Instances

Instances details

FiniteBitsOps Bool Source # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Bool -> CountOf Bool Source # rotateL :: Bool -> CountOf Bool -> Bool Source # rotateR :: Bool -> CountOf Bool -> Bool Source # popCount :: Bool -> CountOf Bool Source # bitFlip :: Bool -> Bool Source # countLeadingZeros :: Bool -> CountOf Bool Source # countTrailingZeros :: Bool -> CountOf Bool Source #
FiniteBitsOps Int8 Source # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Int8 -> CountOf Bool Source # rotateL :: Int8 -> CountOf Bool -> Int8 Source # rotateR :: Int8 -> CountOf Bool -> Int8 Source # popCount :: Int8 -> CountOf Bool Source # bitFlip :: Int8 -> Int8 Source # countLeadingZeros :: Int8 -> CountOf Bool Source # countTrailingZeros :: Int8 -> CountOf Bool Source #
FiniteBitsOps Int16 Source # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Int16 -> CountOf Bool Source # rotateL :: Int16 -> CountOf Bool -> Int16 Source # rotateR :: Int16 -> CountOf Bool -> Int16 Source # popCount :: Int16 -> CountOf Bool Source # bitFlip :: Int16 -> Int16 Source # countLeadingZeros :: Int16 -> CountOf Bool Source # countTrailingZeros :: Int16 -> CountOf Bool Source #
FiniteBitsOps Int32 Source # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Int32 -> CountOf Bool Source # rotateL :: Int32 -> CountOf Bool -> Int32 Source # rotateR :: Int32 -> CountOf Bool -> Int32 Source # popCount :: Int32 -> CountOf Bool Source # bitFlip :: Int32 -> Int32 Source # countLeadingZeros :: Int32 -> CountOf Bool Source # countTrailingZeros :: Int32 -> CountOf Bool Source #
FiniteBitsOps Int64 Source # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Int64 -> CountOf Bool Source # rotateL :: Int64 -> CountOf Bool -> Int64 Source # rotateR :: Int64 -> CountOf Bool -> Int64 Source # popCount :: Int64 -> CountOf Bool Source # bitFlip :: Int64 -> Int64 Source # countLeadingZeros :: Int64 -> CountOf Bool Source # countTrailingZeros :: Int64 -> CountOf Bool Source #
FiniteBitsOps Word Source # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Word -> CountOf Bool Source # rotateL :: Word -> CountOf Bool -> Word Source # rotateR :: Word -> CountOf Bool -> Word Source # popCount :: Word -> CountOf Bool Source # bitFlip :: Word -> Word Source # countLeadingZeros :: Word -> CountOf Bool Source # countTrailingZeros :: Word -> CountOf Bool Source #
FiniteBitsOps Word8 Source # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Word8 -> CountOf Bool Source # rotateL :: Word8 -> CountOf Bool -> Word8 Source # rotateR :: Word8 -> CountOf Bool -> Word8 Source # popCount :: Word8 -> CountOf Bool Source # bitFlip :: Word8 -> Word8 Source # countLeadingZeros :: Word8 -> CountOf Bool Source # countTrailingZeros :: Word8 -> CountOf Bool Source #
FiniteBitsOps Word16 Source # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Word16 -> CountOf Bool Source # rotateL :: Word16 -> CountOf Bool -> Word16 Source # rotateR :: Word16 -> CountOf Bool -> Word16 Source # popCount :: Word16 -> CountOf Bool Source # bitFlip :: Word16 -> Word16 Source # countLeadingZeros :: Word16 -> CountOf Bool Source # countTrailingZeros :: Word16 -> CountOf Bool Source #
FiniteBitsOps Word32 Source # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Word32 -> CountOf Bool Source # rotateL :: Word32 -> CountOf Bool -> Word32 Source # rotateR :: Word32 -> CountOf Bool -> Word32 Source # popCount :: Word32 -> CountOf Bool Source # bitFlip :: Word32 -> Word32 Source # countLeadingZeros :: Word32 -> CountOf Bool Source # countTrailingZeros :: Word32 -> CountOf Bool Source #
FiniteBitsOps Word64 Source # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Word64 -> CountOf Bool Source # rotateL :: Word64 -> CountOf Bool -> Word64 Source # rotateR :: Word64 -> CountOf Bool -> Word64 Source # popCount :: Word64 -> CountOf Bool Source # bitFlip :: Word64 -> Word64 Source # countLeadingZeros :: Word64 -> CountOf Bool Source # countTrailingZeros :: Word64 -> CountOf Bool Source #
FiniteBitsOps Word128 Source # |

Instance details

Defined in Basement.Bits

Methods

numberOfBits :: Word128 -> CountOf Bool Source #

rotateL :: Word128 -> CountOf Bool -> Word128 Source #

rotateR :: Word128 -> CountOf Bool -> Word128 Source #

popCount :: Word128 -> CountOf Bool Source #

bitFlip :: Word128 -> Word128 Source #

countLeadingZeros :: Word128 -> CountOf Bool Source #

countTrailingZeros :: Word128 -> CountOf Bool Source #

FiniteBitsOps Word256 Source # |

Instance details

Defined in Basement.Bits

Methods

numberOfBits :: Word256 -> CountOf Bool Source #

rotateL :: Word256 -> CountOf Bool -> Word256 Source #

rotateR :: Word256 -> CountOf Bool -> Word256 Source #

popCount :: Word256 -> CountOf Bool Source #

bitFlip :: Word256 -> Word256 Source #

countLeadingZeros :: Word256 -> CountOf Bool Source #

countTrailingZeros :: Word256 -> CountOf Bool Source #

(SizeValid n, NatWithinBound (CountOf Bool) n) => FiniteBitsOps (Bits n) Source # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Bits n -> CountOf Bool Source # rotateL :: Bits n -> CountOf Bool -> Bits n Source # rotateR :: Bits n -> CountOf Bool -> Bits n Source # popCount :: Bits n -> CountOf Bool Source # bitFlip :: Bits n -> Bits n Source # countLeadingZeros :: Bits n -> CountOf Bool Source # countTrailingZeros :: Bits n -> CountOf Bool Source #

data Bits (n :: Nat) Source #

Bool set of `n` bits.

#### Instances

Instances details

SizeValid n => Bounded (Bits n) Source # |
Instance details Defined in Basement.Bits Methods minBound :: Bits n Source # maxBound :: Bits n Source #
SizeValid n => Enum (Bits n) Source # |
Instance details Defined in Basement.Bits Methods succ :: Bits n -> Bits n Source # pred :: Bits n -> Bits n Source # toEnum :: Int -> Bits n Source # fromEnum :: Bits n -> Int Source # enumFrom :: Bits n -> [Bits n] Source # enumFromThen :: Bits n -> Bits n -> [Bits n] Source # enumFromTo :: Bits n -> Bits n -> [Bits n] Source # enumFromThenTo :: Bits n -> Bits n -> Bits n -> [Bits n] Source #
Eq (Bits n) Source # |
Instance details Defined in Basement.Bits Methods (==) :: Bits n -> Bits n -> Bool Source # (/=) :: Bits n -> Bits n -> Bool Source #
Ord (Bits n) Source # |
Instance details Defined in Basement.Bits Methods compare :: Bits n -> Bits n -> Ordering Source # (<) :: Bits n -> Bits n -> Bool Source # (<=) :: Bits n -> Bits n -> Bool Source # (>) :: Bits n -> Bits n -> Bool Source # (>=) :: Bits n -> Bits n -> Bool Source # max :: Bits n -> Bits n -> Bits n Source # min :: Bits n -> Bits n -> Bits n Source #
Show (Bits n) Source # |
Instance details Defined in Basement.Bits Methods showsPrec :: Int -> Bits n -> ShowS Source # show :: Bits n -> String Source # showList :: [Bits n] -> ShowS Source #
SizeValid n => Subtractive (Bits n) Source # |
Instance details Defined in Basement.Bits Associated Types type Difference (Bits n) Source # Methods (-) :: Bits n -> Bits n -> Difference (Bits n) Source #
SizeValid n => Additive (Bits n) Source # |
Instance details Defined in Basement.Bits Methods azero :: Bits n Source # (+) :: Bits n -> Bits n -> Bits n Source # scale :: IsNatural n0 => n0 -> Bits n -> Bits n Source #
SizeValid n => IDivisible (Bits n) Source # |
Instance details Defined in Basement.Bits Methods div :: Bits n -> Bits n -> Bits n Source # mod :: Bits n -> Bits n -> Bits n Source # divMod :: Bits n -> Bits n -> (Bits n, Bits n) Source #
SizeValid n => Multiplicative (Bits n) Source # |
Instance details Defined in Basement.Bits Methods midentity :: Bits n Source # (*) :: Bits n -> Bits n -> Bits n Source # (^) :: (IsNatural n0, Enum n0, IDivisible n0) => Bits n -> n0 -> Bits n Source #
SizeValid n => BitOps (Bits n) Source # |

Instance details

Defined in Basement.Bits

Methods

(.&.) :: Bits n -> Bits n -> Bits n Source #

(.|.) :: Bits n -> Bits n -> Bits n Source #

(.^.) :: Bits n -> Bits n -> Bits n Source #

(.<<.) :: Bits n -> CountOf Bool -> Bits n Source #

(.>>.) :: Bits n -> CountOf Bool -> Bits n Source #

bit :: Offset Bool -> Bits n Source #

isBitSet :: Bits n -> Offset Bool -> Bool Source #

setBit :: Bits n -> Offset Bool -> Bits n Source #

clearBit :: Bits n -> Offset Bool -> Bits n Source #

(SizeValid n, NatWithinBound (CountOf Bool) n) => FiniteBitsOps (Bits n) Source # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Bits n -> CountOf Bool Source # rotateL :: Bits n -> CountOf Bool -> Bits n Source # rotateR :: Bits n -> CountOf Bool -> Bits n Source # popCount :: Bits n -> CountOf Bool Source # bitFlip :: Bits n -> Bits n Source # countLeadingZeros :: Bits n -> CountOf Bool Source # countTrailingZeros :: Bits n -> CountOf Bool Source #
type Difference (Bits n) Source # |
Instance details Defined in Basement.Bits type Difference (Bits n) = Bits n

toBits :: SizeValid n => Natural -> Bits n Source #

convert the given `Natural` into a `Bits` of size `n`

if bits that are not within the boundaries of the 'Bits n' will be truncated.

allOne :: forall n. SizeValid n => Bits n Source #

construct a `Bits` with all bits set.

this function is equivalet to `maxBound`