Basement.Bits

basement-0.0.16: 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 :: forall (n :: Nat). SizeValid n => Natural -> Bits n
- allOne :: forall (n :: Nat). SizeValid n => Bits n

# Documentation

class BitOps bits where #

operation over bits

Minimal complete definition

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

Methods

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

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

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

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

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

bit :: Offset Bool -> bits #

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

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

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

test the bit at the given index is set

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

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

set the bit at the given index

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

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

clear the bit at the given index

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

#### Instances

Instances details

BitOps Int16 # |
Instance details Defined in Basement.Bits Methods (.&.) :: Int16 -> Int16 -> Int16 # (.|.) :: Int16 -> Int16 -> Int16 # (.^.) :: Int16 -> Int16 -> Int16 # (.<<.) :: Int16 -> CountOf Bool -> Int16 # (.>>.) :: Int16 -> CountOf Bool -> Int16 # bit :: Offset Bool -> Int16 # isBitSet :: Int16 -> Offset Bool -> Bool # setBit :: Int16 -> Offset Bool -> Int16 # clearBit :: Int16 -> Offset Bool -> Int16 #
BitOps Int32 # |
Instance details Defined in Basement.Bits Methods (.&.) :: Int32 -> Int32 -> Int32 # (.|.) :: Int32 -> Int32 -> Int32 # (.^.) :: Int32 -> Int32 -> Int32 # (.<<.) :: Int32 -> CountOf Bool -> Int32 # (.>>.) :: Int32 -> CountOf Bool -> Int32 # bit :: Offset Bool -> Int32 # isBitSet :: Int32 -> Offset Bool -> Bool # setBit :: Int32 -> Offset Bool -> Int32 # clearBit :: Int32 -> Offset Bool -> Int32 #
BitOps Int64 # |
Instance details Defined in Basement.Bits Methods (.&.) :: Int64 -> Int64 -> Int64 # (.|.) :: Int64 -> Int64 -> Int64 # (.^.) :: Int64 -> Int64 -> Int64 # (.<<.) :: Int64 -> CountOf Bool -> Int64 # (.>>.) :: Int64 -> CountOf Bool -> Int64 # bit :: Offset Bool -> Int64 # isBitSet :: Int64 -> Offset Bool -> Bool # setBit :: Int64 -> Offset Bool -> Int64 # clearBit :: Int64 -> Offset Bool -> Int64 #
BitOps Int8 # |
Instance details Defined in Basement.Bits Methods (.&.) :: Int8 -> Int8 -> Int8 # (.|.) :: Int8 -> Int8 -> Int8 # (.^.) :: Int8 -> Int8 -> Int8 # (.<<.) :: Int8 -> CountOf Bool -> Int8 # (.>>.) :: Int8 -> CountOf Bool -> Int8 # bit :: Offset Bool -> Int8 # isBitSet :: Int8 -> Offset Bool -> Bool # setBit :: Int8 -> Offset Bool -> Int8 # clearBit :: Int8 -> Offset Bool -> Int8 #
BitOps Word16 # |
Instance details Defined in Basement.Bits Methods (.&.) :: Word16 -> Word16 -> Word16 # (.|.) :: Word16 -> Word16 -> Word16 # (.^.) :: Word16 -> Word16 -> Word16 # (.<<.) :: Word16 -> CountOf Bool -> Word16 # (.>>.) :: Word16 -> CountOf Bool -> Word16 # bit :: Offset Bool -> Word16 # isBitSet :: Word16 -> Offset Bool -> Bool # setBit :: Word16 -> Offset Bool -> Word16 # clearBit :: Word16 -> Offset Bool -> Word16 #
BitOps Word32 # |
Instance details Defined in Basement.Bits Methods (.&.) :: Word32 -> Word32 -> Word32 # (.|.) :: Word32 -> Word32 -> Word32 # (.^.) :: Word32 -> Word32 -> Word32 # (.<<.) :: Word32 -> CountOf Bool -> Word32 # (.>>.) :: Word32 -> CountOf Bool -> Word32 # bit :: Offset Bool -> Word32 # isBitSet :: Word32 -> Offset Bool -> Bool # setBit :: Word32 -> Offset Bool -> Word32 # clearBit :: Word32 -> Offset Bool -> Word32 #
BitOps Word64 # |
Instance details Defined in Basement.Bits Methods (.&.) :: Word64 -> Word64 -> Word64 # (.|.) :: Word64 -> Word64 -> Word64 # (.^.) :: Word64 -> Word64 -> Word64 # (.<<.) :: Word64 -> CountOf Bool -> Word64 # (.>>.) :: Word64 -> CountOf Bool -> Word64 # bit :: Offset Bool -> Word64 # isBitSet :: Word64 -> Offset Bool -> Bool # setBit :: Word64 -> Offset Bool -> Word64 # clearBit :: Word64 -> Offset Bool -> Word64 #
BitOps Word8 # |
Instance details Defined in Basement.Bits Methods (.&.) :: Word8 -> Word8 -> Word8 # (.|.) :: Word8 -> Word8 -> Word8 # (.^.) :: Word8 -> Word8 -> Word8 # (.<<.) :: Word8 -> CountOf Bool -> Word8 # (.>>.) :: Word8 -> CountOf Bool -> Word8 # bit :: Offset Bool -> Word8 # isBitSet :: Word8 -> Offset Bool -> Bool # setBit :: Word8 -> Offset Bool -> Word8 # clearBit :: Word8 -> Offset Bool -> Word8 #
BitOps Word128 # |
Instance details Defined in Basement.Bits Methods (.&.) :: Word128 -> Word128 -> Word128 # (.|.) :: Word128 -> Word128 -> Word128 # (.^.) :: Word128 -> Word128 -> Word128 # (.<<.) :: Word128 -> CountOf Bool -> Word128 # (.>>.) :: Word128 -> CountOf Bool -> Word128 # bit :: Offset Bool -> Word128 # isBitSet :: Word128 -> Offset Bool -> Bool # setBit :: Word128 -> Offset Bool -> Word128 # clearBit :: Word128 -> Offset Bool -> Word128 #
BitOps Word256 # |
Instance details Defined in Basement.Bits Methods (.&.) :: Word256 -> Word256 -> Word256 # (.|.) :: Word256 -> Word256 -> Word256 # (.^.) :: Word256 -> Word256 -> Word256 # (.<<.) :: Word256 -> CountOf Bool -> Word256 # (.>>.) :: Word256 -> CountOf Bool -> Word256 # bit :: Offset Bool -> Word256 # isBitSet :: Word256 -> Offset Bool -> Bool # setBit :: Word256 -> Offset Bool -> Word256 # clearBit :: Word256 -> Offset Bool -> Word256 #
BitOps Bool # |
Instance details Defined in Basement.Bits Methods (.&.) :: Bool -> Bool -> Bool # (.|.) :: Bool -> Bool -> Bool # (.^.) :: Bool -> Bool -> Bool # (.<<.) :: Bool -> CountOf Bool -> Bool # (.>>.) :: Bool -> CountOf Bool -> Bool # bit :: Offset Bool -> Bool # isBitSet :: Bool -> Offset Bool -> Bool # setBit :: Bool -> Offset Bool -> Bool # clearBit :: Bool -> Offset Bool -> Bool #
BitOps Word # |
Instance details Defined in Basement.Bits Methods (.&.) :: Word -> Word -> Word # (.|.) :: Word -> Word -> Word # (.^.) :: Word -> Word -> Word # (.<<.) :: Word -> CountOf Bool -> Word # (.>>.) :: Word -> CountOf Bool -> Word # bit :: Offset Bool -> Word # isBitSet :: Word -> Offset Bool -> Bool # setBit :: Word -> Offset Bool -> Word # clearBit :: Word -> Offset Bool -> Word #
SizeValid n => BitOps (Bits n) # |
Instance details Defined in Basement.Bits Methods (.&.) :: Bits n -> Bits n -> Bits n # (.|.) :: Bits n -> Bits n -> Bits n # (.^.) :: Bits n -> Bits n -> Bits n # (.<<.) :: Bits n -> CountOf Bool -> Bits n # (.>>.) :: Bits n -> CountOf Bool -> Bits n # bit :: Offset Bool -> Bits n # isBitSet :: Bits n -> Offset Bool -> Bool # setBit :: Bits n -> Offset Bool -> Bits n # clearBit :: Bits n -> Offset Bool -> Bits n #

class FiniteBitsOps bits where #

operation over finite bits

Minimal complete definition

numberOfBits, rotateL, rotateR, popCount, bitFlip

Methods

numberOfBits :: bits -> CountOf Bool #

get the number of bits in the given object

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

rotate the given bit set.

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

rotate the given bit set.

popCount :: bits -> CountOf Bool #

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

bitFlip :: bits -> bits #

reverse all bits in the argument

countLeadingZeros :: bits -> CountOf Bool #

count of the number of leading zeros

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

countTrailingZeros :: bits -> CountOf Bool #

count of the number of trailing zeros

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

#### Instances

Instances details

FiniteBitsOps Int16 # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Int16 -> CountOf Bool # rotateL :: Int16 -> CountOf Bool -> Int16 # rotateR :: Int16 -> CountOf Bool -> Int16 # popCount :: Int16 -> CountOf Bool # bitFlip :: Int16 -> Int16 # countLeadingZeros :: Int16 -> CountOf Bool # countTrailingZeros :: Int16 -> CountOf Bool #
FiniteBitsOps Int32 # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Int32 -> CountOf Bool # rotateL :: Int32 -> CountOf Bool -> Int32 # rotateR :: Int32 -> CountOf Bool -> Int32 # popCount :: Int32 -> CountOf Bool # bitFlip :: Int32 -> Int32 # countLeadingZeros :: Int32 -> CountOf Bool # countTrailingZeros :: Int32 -> CountOf Bool #
FiniteBitsOps Int64 # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Int64 -> CountOf Bool # rotateL :: Int64 -> CountOf Bool -> Int64 # rotateR :: Int64 -> CountOf Bool -> Int64 # popCount :: Int64 -> CountOf Bool # bitFlip :: Int64 -> Int64 # countLeadingZeros :: Int64 -> CountOf Bool # countTrailingZeros :: Int64 -> CountOf Bool #
FiniteBitsOps Int8 # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Int8 -> CountOf Bool # rotateL :: Int8 -> CountOf Bool -> Int8 # rotateR :: Int8 -> CountOf Bool -> Int8 # popCount :: Int8 -> CountOf Bool # bitFlip :: Int8 -> Int8 # countLeadingZeros :: Int8 -> CountOf Bool # countTrailingZeros :: Int8 -> CountOf Bool #
FiniteBitsOps Word16 # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Word16 -> CountOf Bool # rotateL :: Word16 -> CountOf Bool -> Word16 # rotateR :: Word16 -> CountOf Bool -> Word16 # popCount :: Word16 -> CountOf Bool # bitFlip :: Word16 -> Word16 # countLeadingZeros :: Word16 -> CountOf Bool # countTrailingZeros :: Word16 -> CountOf Bool #
FiniteBitsOps Word32 # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Word32 -> CountOf Bool # rotateL :: Word32 -> CountOf Bool -> Word32 # rotateR :: Word32 -> CountOf Bool -> Word32 # popCount :: Word32 -> CountOf Bool # bitFlip :: Word32 -> Word32 # countLeadingZeros :: Word32 -> CountOf Bool # countTrailingZeros :: Word32 -> CountOf Bool #
FiniteBitsOps Word64 # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Word64 -> CountOf Bool # rotateL :: Word64 -> CountOf Bool -> Word64 # rotateR :: Word64 -> CountOf Bool -> Word64 # popCount :: Word64 -> CountOf Bool # bitFlip :: Word64 -> Word64 # countLeadingZeros :: Word64 -> CountOf Bool # countTrailingZeros :: Word64 -> CountOf Bool #
FiniteBitsOps Word8 # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Word8 -> CountOf Bool # rotateL :: Word8 -> CountOf Bool -> Word8 # rotateR :: Word8 -> CountOf Bool -> Word8 # popCount :: Word8 -> CountOf Bool # bitFlip :: Word8 -> Word8 # countLeadingZeros :: Word8 -> CountOf Bool # countTrailingZeros :: Word8 -> CountOf Bool #
FiniteBitsOps Word128 # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Word128 -> CountOf Bool # rotateL :: Word128 -> CountOf Bool -> Word128 # rotateR :: Word128 -> CountOf Bool -> Word128 # popCount :: Word128 -> CountOf Bool # bitFlip :: Word128 -> Word128 # countLeadingZeros :: Word128 -> CountOf Bool # countTrailingZeros :: Word128 -> CountOf Bool #
FiniteBitsOps Word256 # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Word256 -> CountOf Bool # rotateL :: Word256 -> CountOf Bool -> Word256 # rotateR :: Word256 -> CountOf Bool -> Word256 # popCount :: Word256 -> CountOf Bool # bitFlip :: Word256 -> Word256 # countLeadingZeros :: Word256 -> CountOf Bool # countTrailingZeros :: Word256 -> CountOf Bool #
FiniteBitsOps Bool # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Bool -> CountOf Bool # rotateL :: Bool -> CountOf Bool -> Bool # rotateR :: Bool -> CountOf Bool -> Bool # popCount :: Bool -> CountOf Bool # bitFlip :: Bool -> Bool # countLeadingZeros :: Bool -> CountOf Bool # countTrailingZeros :: Bool -> CountOf Bool #
FiniteBitsOps Word # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Word -> CountOf Bool # rotateL :: Word -> CountOf Bool -> Word # rotateR :: Word -> CountOf Bool -> Word # popCount :: Word -> CountOf Bool # bitFlip :: Word -> Word # countLeadingZeros :: Word -> CountOf Bool # countTrailingZeros :: Word -> CountOf Bool #
(SizeValid n, NatWithinBound (CountOf Bool) n) => FiniteBitsOps (Bits n) # |
Instance details Defined in Basement.Bits Methods numberOfBits :: Bits n -> CountOf Bool # rotateL :: Bits n -> CountOf Bool -> Bits n # rotateR :: Bits n -> CountOf Bool -> Bits n # popCount :: Bits n -> CountOf Bool # bitFlip :: Bits n -> Bits n # countLeadingZeros :: Bits n -> CountOf Bool # countTrailingZeros :: Bits n -> CountOf Bool #

data Bits (n :: Nat) #

Bool set of `n` bits.

#### Instances

Instances details

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

toBits :: forall (n :: Nat). SizeValid n => Natural -> Bits n #

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 :: Nat). SizeValid n => Bits n #

construct a `Bits` with all bits set.

this function is equivalet to `maxBound`