basement-0.0.7: Foundation scrap box of array & string

LicenseBSD-style
MaintainerHaskell Foundation
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Basement.Bits

Description

 

Synopsis

Documentation

class BitOps bits where Source #

operation over bits

Minimal complete definition

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

Methods

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

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

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

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

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

bit :: Offset Bool -> bits Source #

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

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

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

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

test the bit at the given index is set

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

test the bit at the given index is set

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

set the bit at the given index

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

set the bit at the given index

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

clear the bit at the given index

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

clear the bit at the given index

Instances

BitOps Bool Source # 
BitOps Int8 Source # 
BitOps Int16 Source # 
BitOps Int32 Source # 
BitOps Int64 Source # 
BitOps Word8 Source # 
BitOps Word16 Source # 
BitOps Word32 Source # 
BitOps Word64 Source # 
BitOps Word128 Source # 
BitOps Word256 Source # 
SizeValid n => BitOps (Bits n) Source # 

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 finit 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 Source #

rotate the given bit set.

rotateR :: bits -> CountOf Bool -> bits 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

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

count of the number of leading zeros

countTrailingZeros :: bits -> CountOf Bool Source #

count of the number of trailing zeros

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

count of the number of trailing zeros

Instances

FiniteBitsOps Bool Source # 
FiniteBitsOps Int8 Source # 
FiniteBitsOps Int16 Source # 
FiniteBitsOps Int32 Source # 
FiniteBitsOps Int64 Source # 
FiniteBitsOps Word8 Source # 
FiniteBitsOps Word16 Source # 
FiniteBitsOps Word32 Source # 
FiniteBitsOps Word64 Source # 
FiniteBitsOps Word128 Source # 
FiniteBitsOps Word256 Source # 
(SizeValid n, NatWithinBound (CountOf Bool) n) => FiniteBitsOps (Bits n) Source # 

data Bits (n :: Nat) Source #

Bool set of n bits.

Instances

SizeValid n => Bounded (Bits n) Source # 

Methods

minBound :: Bits n #

maxBound :: Bits n #

SizeValid n => Enum (Bits n) Source # 

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] #

Eq (Bits n) Source # 

Methods

(==) :: Bits n -> Bits n -> Bool #

(/=) :: Bits n -> Bits n -> Bool #

Ord (Bits n) Source # 

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 #

Show (Bits n) Source # 

Methods

showsPrec :: Int -> Bits n -> ShowS #

show :: Bits n -> String #

showList :: [Bits n] -> ShowS #

SizeValid n => Subtractive (Bits n) Source # 

Associated Types

type Difference (Bits n) :: * Source #

Methods

(-) :: Bits n -> Bits n -> Difference (Bits n) Source #

SizeValid n => Additive (Bits n) Source # 

Methods

azero :: Bits n Source #

(+) :: Bits n -> Bits n -> Bits n Source #

scale :: IsNatural n => n -> Bits n -> Bits n Source #

SizeValid n => IDivisible (Bits n) Source # 

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 # 

Methods

midentity :: Bits n Source #

(*) :: Bits n -> Bits n -> Bits n Source #

(^) :: (IsNatural n, IDivisible n) => Bits n -> n -> Bits n Source #

SizeValid n => BitOps (Bits n) Source # 

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 # 
type Difference (Bits n) Source # 
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