úÎ! I:      !"#$%&'()*+,-./0123456789 None FL:;<=>?@ABCDEFG(c) 2016 John KyBSD3SafeHI8J8NoneŔKbitvecThe number of bits in a L1. A handy constant to have around when defining L&-based bulk operations on bit vectors.MbitvecJInsert 0 between each consecutive bits of an input. xyzw --> (x0y0, z0w0)KNOPQRSTUVWXYZ[M\]^_None%27@AFHMV_'Sbitvec-A newtype wrapper with a custom instance of Data.Vector.UnboxedR, which packs booleans as efficient as possible (8 values per byte). Vectors of % use 8x less memory than vectors of `L (which stores one value per byte). but random writes are up to 20% slower.abitvec˙$read a word at the given bit offset in little-endian order (i.e., the LSB will correspond to the bit at the given address, the 2's bit will correspond to the address + 1, etc.). If the offset is such that the word extends past the end of the vector, the result is padded with memory garbage.bbitvec˙$read a word at the given bit offset in little-endian order (i.e., the LSB will correspond to the bit at the given address, the 2's bit will correspond to the address + 1, etc.). If the offset is such that the word extends past the end of the vector, the result is padded with memory garbage.cbitvec˙Ewrite a word at the given bit offset in little-endian order (i.e., the LSB will correspond to the bit at the given address, the 2's bit will correspond to the address + 1, etc.). If the offset is such that the word extends past the end of the vector, the word is truncated and as many low-order bits as possible are written.bitvecTFlip the bit at the given position. No bounds checks are performed. Equivalent to d  e#, but up to 33% faster and atomic.!In general there is no reason to ) bit vectors: either you modify it with f (which is f altogether) or with e (which is ).EData.Vector.Unboxed.modify (\v -> unsafeFlipBit v 1) (read "[1,1,1]")[1,0,1]bitvec3Flip the bit at the given position. Equivalent to d   e#, but up to 33% faster and atomic.!In general there is no reason to  ) bit vectors: either you modify it with f (which is f altogether) or with e (which is ).?Data.Vector.Unboxed.modify (\v -> flipBit v 1) (read "[1,1,1]")[1,0,1]gbitvecThere is only one lawful h instance possible with i = j and k =  . l.mnopqrabsc None>SX<łbitvec1Cast a vector of words to a vector of bits. Cf.  .bitveceTry to cast a vector of bits to a vector of words. It succeeds if a vector of bits is aligned. Use  otherwise. Cf.  .bitvecClone a vector of bits to a new unboxed vector of words. If the bits don't completely fill the words, the last word will be zero-padded. Cf.  .bitvecZZip two vectors with the given function. rewriting contents of the second argument. Cf. .import Data.Bits;modify (zipInPlace (.&.) (read "[1,1,0]")) (read "[0,1,1]")[0,1,0]Warningo: if the immutable vector is shorter than the mutable one, it is a caller's responsibility to trim the result:import Data.BitsAmodify (zipInPlace (.&.) (read "[1,1,0]")) (read "[0,1,1,1,1,1]")&[0,1,0,1,1,1] -- note trailing garbage bitvec Invert (flip) all bits in-place.=Data.Vector.Unboxed.modify invertInPlace (read "[0,1,0,1,0]") [1,0,1,0,1] bitvecSame as Š, but deposit selected bits in-place. Returns a number of selected bits. It is caller's resposibility to trim the result to this number. bitvecSame as Š, but deposit excluded bits in-place. Returns a number of excluded bits. It is caller's resposibility to trim the result to this number. bitvec#Reverse the order of bits in-place.>Data.Vector.Unboxed.modify reverseInPlace (read "[1,1,0,1,0]") [0,1,0,1,1] None%27@AFHMV_[ś bitvec-A newtype wrapper with a custom instance of Data.Vector.UnboxedR, which packs booleans as efficient as possible (8 values per byte). Vectors of  % use 8x less memory than vectors of `L (which stores one value per byte). but random writes are up to 10% slower.tbitvec˙$read a word at the given bit offset in little-endian order (i.e., the LSB will correspond to the bit at the given address, the 2's bit will correspond to the address + 1, etc.). If the offset is such that the word extends past the end of the vector, the result is padded with memory garbage.ubitvec˙$read a word at the given bit offset in little-endian order (i.e., the LSB will correspond to the bit at the given address, the 2's bit will correspond to the address + 1, etc.). If the offset is such that the word extends past the end of the vector, the result is padded with memory garbage.vbitvec˙Ewrite a word at the given bit offset in little-endian order (i.e., the LSB will correspond to the bit at the given address, the 2's bit will correspond to the address + 1, etc.). If the offset is such that the word extends past the end of the vector, the word is truncated and as many low-order bits as possible are written.bitvecTFlip the bit at the given position. No bounds checks are performed. Equivalent to d  e, but up to 2x faster.!In general there is no reason to ) bit vectors: either you modify it with f (which is f altogether) or with e (which is ).EData.Vector.Unboxed.modify (\v -> unsafeFlipBit v 1) (read "[1,1,1]")[1,0,1]bitvec3Flip the bit at the given position. Equivalent to d   e, but up to 2x faster.!In general there is no reason to  ) bit vectors: either you modify it with f (which is f altogether) or with e (which is ).?Data.Vector.Unboxed.modify (\v -> flipBit v 1) (read "[1,1,1]")[1,0,1]wbitvecThere is only one lawful h instance possible with i = j and k =   . l.mxoyz{ tu|vNone>SXqbitvec1Cast a vector of words to a vector of bits. Cf.  .bitveceTry to cast a vector of bits to a vector of words. It succeeds if a vector of bits is aligned. Use  otherwise. Cf.  .bitvecClone a vector of bits to a new unboxed vector of words. If the bits don't completely fill the words, the last word will be zero-padded. Cf.  .bitvecZZip two vectors with the given function. rewriting contents of the second argument. Cf. .import Data.Bits;modify (zipInPlace (.&.) (read "[1,1,0]")) (read "[0,1,1]")[0,1,0]Warningo: if the immutable vector is shorter than the mutable one, it is a caller's responsibility to trim the result:import Data.BitsAmodify (zipInPlace (.&.) (read "[1,1,0]")) (read "[0,1,1,1,1,1]")&[0,1,0,1,1,1] -- note trailing garbagebitvec Invert (flip) all bits in-place.=Data.Vector.Unboxed.modify invertInPlace (read "[0,1,0,1,0]") [1,0,1,0,1]bitvecSame as Š, but deposit selected bits in-place. Returns a number of selected bits. It is caller's resposibility to trim the result to this number.bitvecSame as Š, but deposit excluded bits in-place. Returns a number of excluded bits. It is caller's resposibility to trim the result to this number.bitvec#Reverse the order of bits in-place.>Data.Vector.Unboxed.modify reverseInPlace (read "[1,1,0,1,0]") [0,1,0,1,1]None>SX¤‚ bitvec1Cast a vector of words to a vector of bits. Cf. .1castFromWords (Data.Vector.Unboxed.singleton 123)[1,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]bitveceTry to cast a vector of bits to a vector of words. It succeeds if a vector of bits is aligned. Use  otherwise. Cf. .'castToWords (castFromWords v) == Just vbitvecClone a vector of bits to a new unboxed vector of words. If the bits don't completely fill the words, the last word will be zero-padded. Cf. .'cloneToWords (read "[1,1,0,1,1,1,1,0]")[123]bitvec5Zip two vectors with the given function. Similar to , but up to 1000x (!) faster.6For sufficiently dense sets, represented as bitmaps,  is up to 32x faster than , , etc.import Data.Bits?zipBits (.&.) (read "[1,1,0]") (read "[0,1,1]") -- intersection[0,1,0]8zipBits (.|.) (read "[1,1,0]") (read "[0,1,1]") -- union[1,1,1]TzipBits (\x y -> x .&. complement y) (read "[1,1,0]") (read "[0,1,1]") -- difference[1,0,0]EzipBits xor (read "[1,1,0]") (read "[0,1,1]") -- symmetric difference[1,0,1]bitvecInvert (flip) all bits.invertBits (read "[0,1,0,1,0]") [1,0,1,0,1]bitvecĄFor each set bit of the first argument, deposit the corresponding bit of the second argument to the result. Similar to the parallel deposit instruction (PDEP).4selectBits (read "[0,1,0,1,1]") (read "[1,1,0,0,1]")[1,0,1].Here is a reference (but slow) implementation: rimport qualified Data.Vector.Unboxed as U selectBits mask ws == U.map snd (U.filter (unBit . fst) (U.zip mask ws)) bitvecoFor each unset bit of the first argument, deposit the corresponding bit of the second argument to the result.5excludeBits (read "[0,1,0,1,1]") (read "[1,1,0,0,1]")[1,0].Here is a reference (but slow) implementation: yimport qualified Data.Vector.Unboxed as U excludeBits mask ws == U.map snd (U.filter (not . unBit . fst) (U.zip mask ws))!bitvecReverse the order of bits. reverseBits (read "[1,1,0,1,0]") [0,1,0,1,1]"bitvec_Return the index of the first bit in the vector with the specified value, if any. Similar to , but up to 64x faster.(bitIndex (Bit True) (read "[0,0,1,0,1]")Just 2(bitIndex (Bit True) (read "[0,0,0,0,0]")Nothing!bitIndex bit == nthBitIndex bit 1GOne can also use it to reduce a vector with disjunction or conjunction:import Data.Maybe/isAnyBitSet = isJust . bitIndex (Bit True)0areAllBitsSet = isNothing . bitIndex (Bit False)#bitvecReturn the index of the n?-th bit in the vector with the specified value, if any. Here n4 is 1-based and the index is 0-based. Non-positive n results in an error.1nthBitIndex (Bit True) 2 (read "[0,1,0,1,1,1,0]")Just 31nthBitIndex (Bit True) 5 (read "[0,1,0,1,1,1,0]")Nothing One can use # to implement to implement  select{0,1} queries for  5https://en.wikipedia.org/wiki/Succinct_data_structuresuccinct dictionaries.$bitvecGReturn the number of set bits in a vector (population count, popcount). countBits (read "[1,1,0,1,0,1]")4One can combine $ with  to implement  rank{0,1} queries for  5https://en.wikipedia.org/wiki/Succinct_data_structuresuccinct dictionaries.%bitvec+Return the indices of set bits in a vector.listBits (read "[1,1,0,1,0,1]") [0,1,3,5]  !"#$%None>SX×ţ &bitvec1Cast a vector of words to a vector of bits. Cf. .1castFromWords (Data.Vector.Unboxed.singleton 123)[1,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]'bitveceTry to cast a vector of bits to a vector of words. It succeeds if a vector of bits is aligned. Use ( otherwise. Cf. .'castToWords (castFromWords v) == Just v(bitvecClone a vector of bits to a new unboxed vector of words. If the bits don't completely fill the words, the last word will be zero-padded. Cf. .'cloneToWords (read "[1,1,0,1,1,1,1,0]")[123])bitvec5Zip two vectors with the given function. Similar to , but up to 1000x (!) faster.6For sufficiently dense sets, represented as bitmaps, ) is up to 32x faster than , , etc.import Data.Bits?zipBits (.&.) (read "[1,1,0]") (read "[0,1,1]") -- intersection[0,1,0]8zipBits (.|.) (read "[1,1,0]") (read "[0,1,1]") -- union[1,1,1]TzipBits (\x y -> x .&. complement y) (read "[1,1,0]") (read "[0,1,1]") -- difference[1,0,0]EzipBits xor (read "[1,1,0]") (read "[0,1,1]") -- symmetric difference[1,0,1]*bitvecInvert (flip) all bits.invertBits (read "[0,1,0,1,0]") [1,0,1,0,1]+bitvecĄFor each set bit of the first argument, deposit the corresponding bit of the second argument to the result. Similar to the parallel deposit instruction (PDEP).4selectBits (read "[0,1,0,1,1]") (read "[1,1,0,0,1]")[1,0,1].Here is a reference (but slow) implementation: rimport qualified Data.Vector.Unboxed as U selectBits mask ws == U.map snd (U.filter (unBit . fst) (U.zip mask ws)),bitvecoFor each unset bit of the first argument, deposit the corresponding bit of the second argument to the result.5excludeBits (read "[0,1,0,1,1]") (read "[1,1,0,0,1]")[1,0].Here is a reference (but slow) implementation: yimport qualified Data.Vector.Unboxed as U excludeBits mask ws == U.map snd (U.filter (not . unBit . fst) (U.zip mask ws))-bitvecReverse the order of bits. reverseBits (read "[1,1,0,1,0]") [0,1,0,1,1].bitvec_Return the index of the first bit in the vector with the specified value, if any. Similar to , but up to 64x faster.(bitIndex (Bit True) (read "[0,0,1,0,1]")Just 2(bitIndex (Bit True) (read "[0,0,0,0,0]")Nothing!bitIndex bit == nthBitIndex bit 1GOne can also use it to reduce a vector with disjunction or conjunction:import Data.Maybe/isAnyBitSet = isJust . bitIndex (Bit True)0areAllBitsSet = isNothing . bitIndex (Bit False)/bitvecReturn the index of the n?-th bit in the vector with the specified value, if any. Here n4 is 1-based and the index is 0-based. Non-positive n results in an error.1nthBitIndex (Bit True) 2 (read "[0,1,0,1,1,1,0]")Just 31nthBitIndex (Bit True) 5 (read "[0,1,0,1,1,1,0]")Nothing One can use / to implement to implement  select{0,1} queries for  5https://en.wikipedia.org/wiki/Succinct_data_structuresuccinct dictionaries.0bitvecGReturn the number of set bits in a vector (population count, popcount). countBits (read "[1,1,0,1,0,1]")4One can combine 0 with  to implement  rank{0,1} queries for  5https://en.wikipedia.org/wiki/Succinct_data_structuresuccinct dictionaries.1bitvec+Return the indices of set bits in a vector.listBits (read "[1,1,0,1,0,1]") [0,1,3,5] &'()*+,-./01None 27FMSX_ët 2bitvec:Binary polynomials of one variable, backed by an unboxed   .EPolynomials are stored normalized, without leading zero coefficients.}W instance does not make much sense mathematically, it is defined only for the sake of !", #$, etc.:set -XBinaryLiterals*-- (1 + x) (1 + x + x^2) = 1 + x^3 (mod 2)0b11 * 0b111 :: F2Poly0b10013bitvecConvert 2M to a vector of coefficients (first element corresponds to a constant term).4bitvecMake 2M from a list of coefficients (first element corresponds to a constant term).~bitvecValid 2& has offset 0 and no trailing garbage.bitvecNInputs must be valid for wrapping into F2Poly: no trailing garbage is allowed.€bitvecMust be >= 2 * wordSize.5bitvec;Execute the extended Euclidean algorithm. For polynomials a and b/, compute their unique greatest common divisor g( and the unique coefficient polynomial s satisfying  as + bt = g.:set -XBinaryLiteralsgcdExt 0b101 0b0101 (0b101,0b0)gcdExt 0b11 0b111 (0b1,0b10)bitvec‚* converts a binary polynomial, encoded as 2, to ƒ encoding.„bitvec3Addition and multiplication are evaluated modulo 2.… = f and † = ‡ 1.k* converts a binary polynomial, encoded as ƒ, to 2 encoding.23450(c) 2019 Andrew Lelechenko, 2012-2016 James CookBSD3/Andrew Lelechenko <andrew.lelechenko@gmail.com>NoneíR  !"#$%2345!"#$%  2345%None 27FMSX_ 6bitvec:Binary polynomials of one variable, backed by an unboxed    .EPolynomials are stored normalized, without leading zero coefficients.}W instance does not make much sense mathematically, it is defined only for the sake of !", #$, etc.:set -XBinaryLiterals*-- (1 + x) (1 + x + x^2) = 1 + x^3 (mod 2)0b11 * 0b111 :: F2Poly0b10017bitvecConvert 6M to a vector of coefficients (first element corresponds to a constant term).8bitvecMake 6M from a list of coefficients (first element corresponds to a constant term).ˆbitvecValid 6& has offset 0 and no trailing garbage.‰bitvecNInputs must be valid for wrapping into F2Poly: no trailing garbage is allowed.ŠbitvecMust be >= 2 * wordSize.9bitvec;Execute the extended Euclidean algorithm. For polynomials a and b/, compute their unique greatest common divisor g( and the unique coefficient polynomial s satisfying  as + bt = g.:set -XBinaryLiteralsgcdExt 0b101 0b0101 (0b101,0b0)gcdExt 0b11 0b111 (0b1,0b10)‹bitvec‚* converts a binary polynomial, encoded as 6, to ƒ encoding.Œbitvec3Addition and multiplication are evaluated modulo 2.… = f and † = ‡ 1.k* converts a binary polynomial, encoded as ƒ, to 6 encoding.67890(c) 2019 Andrew Lelechenko, 2012-2016 James CookBSD3/Andrew Lelechenko <andrew.lelechenko@gmail.com>None] &'()*+,-./016789 &'()*-./01+,6789&&'()    * + , - .&&'()*+,-.   /01234   /012345678%5%6%7%89:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`KLabcdefgehiefjkelmelnehoelpeqrstuvst wxxybcdkvwxxyKz{|}~eq€‚ƒ„el…el†ef‡%|%}%~%%„ˆ%bitvec-1.0.2.0-A9ZZBIBzISzGxGoxqq24z5Data.Bit.ThreadSafeData.Bit Data.Bit.GmpData.Bit.Select1Data.Bit.UtilsData.Bit.InternalTSData.Vector.Unboxed.Mutable unsafeModifymodifyData.Bit.MutableTS castFromWords castToWords cloneToWordszipBits selectBits excludeBitsData.Bit.InternalData.Bit.MutableData.Bit.ImmutableTScastFromWordsM castToWordsM cloneToWordsMData.Vector.UnboxedzipWith Data.IntSetunion intersection elemIndextakeData.Bit.ImmutableData.Bit.F2PolyTSVectorData.SetSetData.MapMapData.Bit.F2PolyBitunBit unsafeFlipBitflipBit zipInPlace invertInPlaceselectBitsInPlaceexcludeBitsInPlacereverseInPlace invertBits reverseBitsbitIndex nthBitIndex countBitslistBitsF2PolyunF2PolytoF2PolygcdExtmpnCom mpnLshift mpnRshiftmpnScan0mpnScan1 mpnPopcountmpnAndNmpnIorNmpnXorNmpnAndnNmpnIornNmpnNandNmpnNiorNmpnXnorNselect1.>..<.wordSizeghc-prim GHC.TypesWord sparseBits lgWordSize divWordSize modWordSize mulWordSizenWords wordsToBytesalignedalignUpmaskedmeld reverseWordreversePartialWordffs selectWordloMaskhiMaskfromPrimVector toPrimVectorBool indexWordreadWord writeWordbaseGHC.Baseflip Data.Bits complementid$fNumBitGHC.NumNum+xor fromIntegerGHC.Realodd&vector-0.12.0.3-ChzWbiXyvuNAQj0dcU08SgData.Vector.Unboxed.BaseMVectorBitMVecBitVec WithInternalsmodifyByteArray GHC.ClassesOrd_isValidxorBitskaratsubaThreshold$fIntegralF2Poly toInteger integer-gmpGHC.Integer.TypeInteger $fNumF2Polyabssignumconst