Module Data.Bits

Fast sets for small integers and enumerations, implemented as bit operations on Long There may be at most 64 elements, due to the bit size of Long.

Imports

Table of Content

Definitions

data BitSet e

Constructors

BitSet {set ∷ Long}

Member Functions

differenceBitSet αBitSet αBitSet α

a `difference` b -- a set with all elements that are members of a and not members of b

differenceEEnum 𝖆 ⇒ BitSet 𝖆𝖆BitSet 𝖆

a `differenceE` e = a `difference` {e}

fromListEnum 𝖆 ⇒ [𝖆]BitSet 𝖆

convert a list to a BitSet

intersectionBitSet αBitSet αBitSet α

a `intersection` b -- a set with all elements that are members of a and members of b

intersectionEEnum 𝖆 ⇒ BitSet 𝖆𝖆BitSet 𝖆

a `intersectionE` e = a `intersection` {e}

memberEnum α ⇒ αBitSet αBool

Predicate to tell if an element is a member of a set

setBitSet 𝖆Long

access field set

singletonEnum α ⇒ αBitSet α

A set with one argument

sizeBitSet 𝖆Int

tell the number of elements in a BitSet

subsetBitSet αBitSet αBool

Predicate that tells if one set is a subset of another

toListEnum α ⇒ BitSet α → [α]

convert a BitSet to a list

unionBitSet αBitSet αBitSet α

a `union` b -- a set with all elements that are members of a or members of b

unionEEnum 𝖆 ⇒ BitSet 𝖆𝖆BitSet 𝖆

a `unionE` e = a `union` {e}

universal ∷ (Enum α, Bounded α) ⇒ BitSet α

The universal set

class (Eq a, Ord a, Num a) ⇒ Bits a

The Bits class defines bitwise operations over integral types.

Bits are numbered from 0 with bit 0 being the least significant bit.

Minimal complete definition: .&., .|., .^., Bits.complement, (Bits.shift or (Bits.shiftL and Bits.shiftR)), (Bits.rotate or (Bits.rotateL and Bits.rotateR)), Bits.bitSize and Bits.isSigned.

Known Instances

Integer, Int, Long

Member Functions

.&.Bits a ⇒ a → a → a
infixl  11

Bitwise \"and\"

.^.Bits a ⇒ a → a → a
infixl  10

Bitwise \"xor\"

.|.Bits a ⇒ a → a → a
infixl  10

Bitwise \"or\"

bitBits a ⇒ Int → a

bit i is a value with the ith bit set

bitCountBits a ⇒ a → Int

Returns the number of one-bits in the two's complement binary representation of the specified value.

Also known as "population count" or "Hamming Weight" of a bit string.

See also Hamming Weight.

bitSizeBits a ⇒ a → Int

Return the number of bits in the type of the argument. The actual value of the argument is ignored. The function Bits.bitSize is undefined for types that do not have a fixed bitsize, like Integer.

clearBitBits a ⇒ a → Int → a

x \`clearBit\` i is the same as x .&. complement (bit i)

complementBits a ⇒ a → a

Reverse all the bits in the argument

complementBitBits a ⇒ a → Int → a

x \`complementBit\` i is the same as x \`.^.\` bit i

isSignedBits a ⇒ a → Bool

Return true if the argument is a signed type. The actual value of the argument is ignored

rotateBits a ⇒ a → Int → a
infixl  12

Bits.rotate x i rotates x left by i bits if i is positive, or right by -i bits otherwise.

For unbounded types like Integer, Bits.rotate is equivalent to Bits.shift.

An instance can define either this unified Bits.rotate or Bits.rotateL and Bits.rotateR, depending on which is more convenient for the type in question.

rotateLBits a ⇒ a → Int → a
infixl  12

Rotate the argument left by the specified number of bits (which must be non-negative).

An instance can define either this and Bits.rotateR or the unified Bits.rotate, depending on which is more convenient for the type in question.

rotateRBits a ⇒ a → Int → a
infixl  12

Rotate the argument right by the specified number of bits (which must be non-negative).

An instance can define either this and Bits.rotateL or the unified Bits.rotate, depending on which is more convenient for the type in question.

setBitBits a ⇒ a → Int → a

x \`setBit\` i is the same as x .|. bit i

shiftBits a ⇒ a → Int → a
infixl  12

Bits.shift x i shifts x left by i bits if i is positive, or right by -i bits otherwise. Right shifts perform sign extension on signed number types; i.e. they fill the top bits with 1 if the x is negative and with 0 otherwise.

An instance can define either this unified Bits.shift or Bits.shiftL and Bits.shiftR, depending on which is more convenient for the type in question.

shiftLBits a ⇒ a → Int → a
infixl  12

Shift the argument left by the specified number of bits (which must be non-negative).

An instance can define either this and Bits.shiftR or the unified Bits.shift, depending on which is more convenient for the type in question.

shiftRBits a ⇒ a → Int → a
infixl  12

Shift the first argument right by the specified number of bits (which must be non-negative). Right shifts perform sign extension on signed number types; i.e. they fill the top bits with 1 if the x is negative and with 0 otherwise.

An instance can define either this and Bits.shiftL or the unified Bits.shift, depending on which is more convenient for the type in question.

testBitBits a ⇒ a → IntBool

Return true if the nth bit of the argument is 1

ushiftRBits a ⇒ a → Int → a
infixl  12

Unsigned shift right

xorBits a ⇒ a → a → a
infixl  10

Haskell compatibility. Same as `.^.`

Instances

instance Bits Int

Member Functions

.&.IntIntInt
pure native &
infixl  11

Computes binary /and/ of two integers. Uses the java &-operator.

.^.IntIntInt
pure native ^
infixl  10

Computes binary /exclusive or/ of two integers. Uses the java ^-operator.

.|.IntIntInt
pure native |
infixl  10

Computes binary /or/ of two integers. Uses the java |-operator.

bitIntInt

inherited from Bits.bit

bitCountIntInt
pure native java.lang.Integer.bitCount
bitSizeIntInt
clearBitIntIntInt

inherited from Bits.clearBit

complementIntInt
pure native ~
complementBitIntIntInt

inherited from Bits.complementBit

isSignedIntBool
rotateIntIntInt
infixl  12

inherited from Bits.rotate

rotateLIntIntInt
pure native java.lang.Integer.rotateLeft
infixl  12

Returns the value obtained by rotating the two's complement binary representation of the specified int value left

by the specified number of bits.

rotateRIntIntInt
pure native java.lang.Integer.rotateRight
infixl  12

Returns the value obtained by rotating the two's complement binary representation of the specified int value

right by the specified number of bits.

setBitIntIntInt

inherited from Bits.setBit

shiftIntIntInt
infixl  12

inherited from Bits.shift

shiftLIntIntInt
pure native <<
infixl  12
shiftRIntIntInt
pure native >>
infixl  12
testBitIntIntBool

inherited from Bits.testBit

ushiftRIntIntInt
pure native >>>
infixl  12

unsigned right shift

xorIntIntInt
infixl  10

inherited from Bits.xor

instance Bits Integer

Member Functions

.&.IntegerIntegerInteger
pure native and
infixl  11
.^.IntegerIntegerInteger
pure native xor
infixl  10
.|.IntegerIntegerInteger
pure native or
infixl  10
bitIntInteger

inherited from Bits.bit

bitCountIntegerInt
pure native bitCount

Returns the number of bits in the two's complement representation of this Integer that differ from its sign bit.

Note that this is slightly different from data types with a fixed bit size!

Best to be used after masking a certain number of bits with some all-1-bit pattern.

bitSizeIntegerInt

Returns the number of bits in the minimal two's-complement representation of this Integer, excluding a sign bit.

clearBitIntegerIntInteger

inherited from Bits.clearBit

complementIntegerInteger
pure native not
complementBitIntegerIntInteger

inherited from Bits.complementBit

isSignedIntegerBool
rotateIntegerIntInteger
infixl  12
rotateLIntegerIntInteger
infixl  12

inherited from Bits.rotateL

rotateRIntegerIntInteger
infixl  12

inherited from Bits.rotateR

setBitIntegerIntInteger

inherited from Bits.setBit

shiftIntegerIntInteger
infixl  12

inherited from Bits.shift

shiftLIntegerIntInteger
pure native shiftLeft
infixl  12
shiftRIntegerIntInteger
pure native shiftRight
infixl  12
testBitIntegerIntBool

inherited from Bits.testBit

ushiftRIntegerIntInteger
infixl  12

unsigned right shift on big integers does not really make sense ...

xorIntegerIntegerInteger
infixl  10

inherited from Bits.xor

instance Bits Long

Member Functions

.&.LongLongLong
pure native &
infixl  11

Computes binary and of two integers. Uses the java &-operator.

.^.LongLongLong
pure native ^
infixl  10

Computes binary exclusive or of two long integers. Uses the java ^-operator.

.|.LongLongLong
pure native |
infixl  10

Computes binary or of two long integers. Uses the java |-operator.

bitIntLong

inherited from Bits.bit

bitCountLongInt
pure native java.lang.Long.bitCount
bitSizeLongInt
clearBitLongIntLong

inherited from Bits.clearBit

complementLongLong
pure native ~
complementBitLongIntLong

inherited from Bits.complementBit

isSignedLongBool
rotateLongIntLong
infixl  12

inherited from Bits.rotate

rotateLLongIntLong
pure native java.lang.Long.rotateLeft
infixl  12

Returns the value obtained by rotating the two's complement binary representation

of the specified long value left by the specified number of bits.

rotateRLongIntLong
pure native java.lang.Long.rotateRight
infixl  12

Returns the value obtained by rotating the two's complement binary representation

of the specified long value right by the specified number of bits.

setBitLongIntLong

inherited from Bits.setBit

shiftLongIntLong
infixl  12

inherited from Bits.shift

shiftLLongIntLong
pure native <<
infixl  12
shiftRLongIntLong
pure native >>
infixl  12
testBitLongIntBool

inherited from Bits.testBit

ushiftRLongIntLong
pure native >>>
infixl  12

unsigned right shift

xorLongLongLong
infixl  10

inherited from Bits.xor

instance Eq (BitSet a)

Member Functions

!=BitSet 𝖆BitSet 𝖆Bool
infix  7

inherited from Eq.!=

==BitSet 𝖆BitSet 𝖆Bool
infix  7
hashCodeBitSet 𝖆Int
instance ListEmpty BitSet

Member Functions

emptyBitSet 𝖆

The empty set

nullBitSet 𝖆Bool

Predicate to tell if the set is empty

instance Monoid (BitSet a)

Member Functions

mappendBitSet 𝖆BitSet 𝖆BitSet 𝖆
infixr  13
mconcat[BitSet 𝖆]BitSet 𝖆

inherited from Monoid.mconcat

memptyBitSet 𝖆
mtimesIntBitSet 𝖆 → BitSet 𝖆

inherited from Monoid.mtimes

sconcat[BitSet 𝖆]BitSet 𝖆

inherited from Semigroup.sconcat

stimesIntBitSet 𝖆 → BitSet 𝖆

inherited from Semigroup.stimes

instance Ord (BitSet a)

Member Functions

<BitSet 𝖆BitSet 𝖆Bool
infix  9

inherited from Ord.<

<=BitSet 𝖆BitSet 𝖆Bool
infix  9

inherited from Ord.<=

<=>BitSet 𝖆BitSet 𝖆Ordering
infix  8
>BitSet 𝖆BitSet 𝖆Bool
infix  9

inherited from Ord.>

>=BitSet 𝖆BitSet 𝖆Bool
infix  9

inherited from Ord.>=

compareBitSet 𝖆BitSet 𝖆Ordering
infix  8

inherited from Ord.compare

maxBitSet 𝖆BitSet 𝖆BitSet 𝖆

inherited from Ord.max

minBitSet 𝖆BitSet 𝖆BitSet 𝖆

inherited from Ord.min

instance (Show a, Enum a) ⇒ Show (BitSet a)

Member Functions

display ∷ (Show 𝖆, Enum 𝖆) ⇒ BitSet 𝖆String

inherited from Show.display

show ∷ (Show 𝖆, Enum 𝖆) ⇒ BitSet 𝖆String
showChars ∷ (Show 𝖆, Enum 𝖆) ⇒ BitSet 𝖆 → [Char]

inherited from Show.showChars

showList ∷ (Show 𝖆, Enum 𝖆) ⇒ [BitSet 𝖆]StringString

inherited from Show.showList

showsPrec ∷ (Show 𝖆, Enum 𝖆) ⇒ IntBitSet 𝖆StringString

inherited from Show.showsPrec

showsub ∷ (Show 𝖆, Enum 𝖆) ⇒ BitSet 𝖆String

inherited from Show.showsub

Functions and Values by Type

IntIntBool

Bits_Int.testBit

IntIntInt

Bits_Int.xor, Bits_Int.shift, Bits_Int.rotate, Bits_Int.complementBit, Bits_Int.clearBit, Bits_Int.setBit

IntBool

Bits_Int.isSigned

IntInt

Bits_Int.bitSize, Bits_Int.bit, Bits_Int.bitCount

IntInteger

Bits_Integer.bit

IntLong

Bits_Long.bit

IntegerIntBool

Bits_Integer.testBit

IntegerIntInteger

Bits_Integer.shift, Bits_Integer.rotateR, Bits_Integer.rotate, Bits_Integer.rotateL, Bits_Integer.setBit, Bits_Integer.clearBit, Bits_Integer.complementBit

IntegerIntegerInteger

Bits_Integer.xor

IntegerBool

Bits_Integer.isSigned

IntegerInt

Bits_Integer.bitSize, Bits_Integer.bitCount

LongIntBool

Bits_Long.testBit

LongIntLong

Bits_Long.shift, Bits_Long.rotate, Bits_Long.complementBit, Bits_Long.clearBit, Bits_Long.setBit

LongLongLong

Bits_Long.xor

LongBool

Bits_Long.isSigned

LongInt

Bits_Long.bitSize, Bits_Long.bitCount

BitSet α → BitSet α → BitSet α

BitSet.union, BitSet.intersection, BitSet.difference

BitSet α → BitSet α → Bool

BitSet.subset

BitSet 𝖆 → BitSet 𝖆 → BitSet 𝖆

Monoid_BitSet.mappend, Ord_BitSet.min, Ord_BitSet.max

BitSet 𝖆 → BitSet 𝖆 → Bool

Eq_BitSet.!=, Eq_BitSet.==, Ord_BitSet.>=, Ord_BitSet.<, Ord_BitSet.<=, Ord_BitSet.>

BitSet 𝖆 → BitSet 𝖆 → Ordering

Ord_BitSet.compare, Ord_BitSet.<=>

BitSet 𝖆 → Bool

ListEmpty_BitSet.null

BitSet 𝖆 → Int

Eq_BitSet.hashCode, BitSet.size

BitSet 𝖆 → Long

BitSet.set

[BitSet 𝖆] → BitSet 𝖆

Monoid_BitSet.sconcat, Monoid_BitSet.mconcat

IntBitSet 𝖆 → BitSet 𝖆

Monoid_BitSet.stimes, Monoid_BitSet.mtimes

LongBitSet e

BitSet.BitSet

𝖆 → Bool

BitSet.has$set

Bits a ⇒ Int → a

Bits.bit

Bits a ⇒ a → IntBool

Bits.testBit

Bits a ⇒ a → Int → a

Bits.ushiftR, Bits.shiftL, Bits.setBit, Bits.rotateR, Bits.shift, Bits.shiftR, Bits.rotate, Bits.clearBit, Bits.complementBit, Bits.rotateL

Bits a ⇒ a → a → a

Bits.xor, Bits..|., Bits..&., Bits..^.

Bits a ⇒ a → Bool

Bits.isSigned

Bits a ⇒ a → Int

Bits.bitCount, Bits.bitSize

Bits a ⇒ a → a

Bits.complement

Enum α ⇒ BitSet α → [α]

BitSet.toList

Enum α ⇒ α → BitSet α → Bool

BitSet.member

Enum α ⇒ α → BitSet α

BitSet.singleton

Enum 𝖆 ⇒ BitSet 𝖆 → 𝖆 → BitSet 𝖆

BitSet.unionE, BitSet.intersectionE, BitSet.differenceE

Enum 𝖆 ⇒ [𝖆] → BitSet 𝖆

BitSet.fromList

(Show 𝖆, Enum 𝖆) ⇒ BitSet 𝖆 → String

Show_BitSet.showsub, Show_BitSet.display, Show_BitSet.show

(Show 𝖆, Enum 𝖆) ⇒ BitSet 𝖆 → [Char]

Show_BitSet.showChars

(Show 𝖆, Enum 𝖆) ⇒ [BitSet 𝖆] → StringString

Show_BitSet.showList

(Show 𝖆, Enum 𝖆) ⇒ IntBitSet 𝖆 → StringString

Show_BitSet.showsPrec

BitSet 𝖆

ListEmpty_BitSet.empty, Monoid_BitSet.mempty

(Enum α, Bounded α) ⇒ BitSet α

BitSet.universal

BitSet 𝖆 → (LongLong) → BitSet 𝖇

BitSet.chg$set

BitSet 𝖆 → LongBitSet 𝖇

BitSet.upd$set

Valid HTML 4.01 Strict