śĪ!“ü8      !"#$%&'()*+,-./01234567 None F289:;<=>?@ABCDE(c) 2016 John KyBSD3SafeūFG8H8None¦IbitvecThe number of bits in a J1. A handy constant to have around when defining J&-based bulk operations on bit vectors.KbitvecJInsert 0 between each consecutive bits of an input. xyzw --> (x0y0, z0w0)ILMNOPQRSTUVWXKYZ[\None%27@AFHMV_'5bitvec-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.^bitvec’$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._bitvec’$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.`bitvec’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 a  b#, but up to 33% faster and atomic.!In general there is no reason to ) bit vectors: either you modify it with c (which is c altogether) or with b (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 a   b#, but up to 33% faster and atomic.!In general there is no reason to  ) bit vectors: either you modify it with c (which is c altogether) or with b (which is ).?Data.Vector.Unboxed.modify (\v -> flipBit v 1) (read "[1,1,1]")[1,0,1]dbitvecThere is only one lawful e instance possible with f = g and h =  . i.jklmno^_` 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.pbitvec’$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.qbitvec’$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.rbitvec’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 a  b, but up to 2x faster.!In general there is no reason to ) bit vectors: either you modify it with c (which is c altogether) or with b (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 a   b, but up to 2x faster.!In general there is no reason to  ) bit vectors: either you modify it with c (which is c altogether) or with b (which is ).?Data.Vector.Unboxed.modify (\v -> flipBit v 1) (read "[1,1,1]")[1,0,1]sbitvecThere is only one lawful e instance possible with f = g and h =   . i.jtluvw pqrNone>SXpš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 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_ēV2bitvec:Binary polynomials of one variable, backed by an unboxed   .EPolynomials are stored normalized, without leading zero coefficients.xW 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 :: F2PolyF2Poly {unF2Poly = [1,0,0,1]}3bitvecConvert 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).ybitvecValid 2& has offset 0 and no trailing garbage.zbitvecNInputs must be valid for wrapping into F2Poly: no trailing garbage is allowed.{bitvecMust be >= 2 * wordSize.|bitvec}* converts a binary polynomial, encoded as 2, to ~ encoding.bitvec3Addition and multiplication are evaluated modulo 2.€ = c and  = ‚ 1.h* converts a binary polynomial, encoded as ~, to 2 encoding.2340(c) 2019 Andrew Lelechenko, 2012-2016 James CookBSD3/Andrew Lelechenko <andrew.lelechenko@gmail.com>Noneé0  !"#$%234!"#$%  234%None 27FMSX_ł]5bitvec:Binary polynomials of one variable, backed by an unboxed    .EPolynomials are stored normalized, without leading zero coefficients.xW 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 :: F2PolyF2Poly {unF2Poly = [1,0,0,1]}6bitvecConvert 5M to a vector of coefficients (first element corresponds to a constant term).7bitvecMake 5M from a list of coefficients (first element corresponds to a constant term).ƒbitvecValid 5& has offset 0 and no trailing garbage.„bitvecNInputs must be valid for wrapping into F2Poly: no trailing garbage is allowed.…bitvecMust be >= 2 * wordSize.†bitvec}* converts a binary polynomial, encoded as 5, to ~ encoding.‡bitvec3Addition and multiplication are evaluated modulo 2.€ = c and  = ‚ 1.h* converts a binary polynomial, encoded as ~, to 5 encoding.5670(c) 2019 Andrew Lelechenko, 2012-2016 James CookBSD3/Andrew Lelechenko <andrew.lelechenko@gmail.com>Noneū7 &'()*+,-./01567 &'()*-./01+,567ˆ&&'()    * + , - .&&'()*+,-.   /01234   /01234567%5%6%789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^JK_`abcdecfgcdhicjkcjlcfmcjncopqrstqr uvv`abituvvJwxyz{|co}~€cj‚cjƒcd„%y%z%{%|%…%bitvec-1.0.1.1-AvYiuucgJYW12KcyiQrlONData.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 countBitslistBitsF2PolyunF2PolytoF2PolympnCom mpnLshift mpnRshiftmpnScan0mpnScan1 mpnPopcountmpnAndNmpnIorNmpnXorNmpnAndnNmpnIornNmpnNandNmpnNiorNmpnXnorNselect1.>..<.wordSizeghc-prim GHC.TypesWord sparseBits 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 WithInternals GHC.ClassesOrd_isValidxorBitskaratsubaThreshold$fIntegralF2Poly toInteger integer-gmpGHC.Integer.TypeInteger $fNumF2Polyabssignumconst