!\Ӡ.      !"#$%&'()*+,- (c) 2016 John KyBSD3Safe./808SafeS1bitvecThe number of bits in a 21. A handy constant to have around when defining 2&-based bulk operations on bit vectors.13456789:;<=>?@ANone%2@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 BL (which stores one value per byte). but random writes are up to 20% slower.Cbitvecread 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 zero-padded.Dbitvecread 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 zero-padded.EbitvecEwrite 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 F  G#, but up to 33% faster and atomic.!In general there is no reason to ) bit vectors: either you modify it with H (which is H altogether) or with G (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 F  G#, but up to 33% faster and atomic.!In general there is no reason to ) bit vectors: either you modify it with H (which is H altogether) or with G (which is ).?Data.Vector.Unboxed.modify (\v -> flipBit v 1) (read "[1,1,1]")[1,0,1]IJKLMNCDE 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.  .bitvecClone 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. Combine with  or simply resort to  G" to operate on immutable vectors.=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. Combine with  or simply resort to " to operate on immutable vectors.>Data.Vector.Unboxed.modify reverseInPlace (read "[1,1,0,1,0]") [0,1,0,1,1] None%2@AFHMV_W 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 BL (which stores one value per byte). but random writes are up to 10% slower.Obitvecread 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 zero-padded.Pbitvecread 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 zero-padded.QbitvecEwrite 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 F  G, but up to 2x faster.!In general there is no reason to ) bit vectors: either you modify it with H (which is H altogether) or with G (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 F  G, but up to 2x faster.!In general there is no reason to ) bit vectors: either you modify it with H (which is H altogether) or with G (which is ).?Data.Vector.Unboxed.modify (\v -> flipBit v 1) (read "[1,1,1]")[1,0,1]IRKSTU OPQNone>SXobitvec1Cast 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.  .bitvecClone 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. Combine with  or simply resort to  G" to operate on immutable vectors.=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. Combine with  or simply resort to " to operate on immutable vectors.>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 vbitvecClone 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 16x faster.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]bitvecFor 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)) 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]  !"#0(c) 2019 Andrew Lelechenko, 2012-2016 James CookBSD3/Andrew Lelechenko <andrew.lelechenko@gmail.com>None  !"# !"#  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&bitvecClone 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 16x faster.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](bitvecFor 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))*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] $%&'()*+,-0(c) 2019 Andrew Lelechenko, 2012-2016 James CookBSD3/Andrew Lelechenko <andrew.lelechenko@gmail.com>None $%&'()*+,- $%&'*+,-()V    ! " # $ % !"#$%    &'()    &'()*+,-./0123456789:;<=>?./@ABCDEFDGHDEIJKLMJKNOPPABCMOPPQ%bitvec-1.0.0.1-67fPkJN057v12WQYNvNTmnData.Bit.ThreadSafeData.BitData.Bit.Select1Data.Bit.UtilsData.Bit.InternalTSData.Vector.Unboxed.Mutable unsafeModifymodifyData.Bit.MutableTS castFromWords castToWords cloneToWordszipBitsData.Vector.Unboxedmap selectBits excludeBitsreverseData.Bit.InternalData.Bit.MutableData.Bit.ImmutableTScastFromWordsM castToWordsM cloneToWordsMzipWith elemIndextakeData.Bit.ImmutableBitunBit unsafeFlipBitflipBit zipInPlace invertInPlaceselectBitsInPlaceexcludeBitsInPlacereverseInPlacebitIndex nthBitIndex countBitslistBitsselect1.>..<.wordSizeghc-prim GHC.TypesWord divWordSize modWordSize mulWordSizenWords wordsToBytesalignedalignUpmaskedmeld reverseWordreversePartialWordffs selectWordloMaskhiMaskBool indexWordreadWord writeWordbaseGHC.Baseflip Data.Bits complementid&vector-0.12.0.3-ChzWbiXyvuNAQj0dcU08SgData.Vector.Unboxed.BaseMVectorBitMVecVectorBitVec WithInternals