!D.      !"#$%&'()*+,- (c) 2016 John KyBSD3Safe./808SafeK1bitvecThe number of bits in a 21. A handy constant to have around when defining 2&-based bulk operations on bit vectors.31456789:;<=>?@ABCDEFGHIJKLMNone%2@AFHMV_/h 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 NL (which stores one value per byte), but random writes are slightly 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 R  S", but slightly faster and atomic.!In general there is no reason to ) bit vectors: either you modify it with T (which is T altogether) or with S (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 R  S!, but slightly faster and atomic!In general there is no reason to ) bit vectors: either you modify it with T (which is T altogether) or with S (which is ).?Data.Vector.Unboxed.modify (\v -> flipBit v 1) (read "[1,1,1]")[1,0,1]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]UVWXOPQ None>SXM 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. .Ybitvec%Map a function over a bit vector one 2 at a time (1S bits at a time). The function will be passed the bit index (which will always be 1-aligned) and the current value of the corresponding word. The returned word will be written back to the vector. If there is a partial word at the end of the vector, it will be zero-padded when passed to the function and truncated when the result is written back to the array. 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  " 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  " to operate on immutable vectors.>Data.Vector.Unboxed.modify reverseInPlace (read "[1,1,0,1,0]") [0,1,0,1,1] None%2@AFHMV_v~ 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 NL (which stores one value per byte), but random writes are slightly slower.Zbitvecread 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.[bitvecread 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.\bitvecEwrite 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 R  S, but slightly faster.!In general there is no reason to ) bit vectors: either you modify it with T (which is T altogether) or with S (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 R  S, but slightly faster.!In general there is no reason to ) bit vectors: either you modify it with T (which is T altogether) or with S (which is ).?Data.Vector.Unboxed.modify (\v -> flipBit v 1) (read "[1,1,1]")[1,0,1]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]U]W^Z[\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. ._bitvec%Map a function over a bit vector one 2 at a time (1S bits at a time). The function will be passed the bit index (which will always be 1-aligned) and the current value of the corresponding word. The returned word will be written back to the vector. If there is a partial word at the end of the vector, it will be zero-padded when passed to the function and truncated when the result is written back to the array.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  " 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  " 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 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 much 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 much 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) !"#$%&0(c) 2019 Andrew Lelechenko, 2012-2016 James CookBSD3/Andrew Lelechenko <andrew.lelechenko@gmail.com>None  !"#$%& !"#&$% None>SXV'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 much 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 much 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)'()*+,-0(c) 2019 Andrew Lelechenko, 2012-2016 James CookBSD3/Andrew Lelechenko <andrew.lelechenko@gmail.com>None@'()*+,-'()*-+,` !    " # $ % & !"#$%&  '  '()*+,-./0123456789:;<=>?@ABCDEFGHI,-JKLMNOPNQRNOSTUVWTUXY ZKLMWYZ[%bitvec-1.0.0.0-Ly7QY0QRpGALCQYSwqwuvsData.Bit.ThreadSafeData.BitData.Bit.Select1Data.Bit.UtilsData.Bit.InternalTSData.Vector.Unboxed.Mutable unsafeModifymodifyData.Vector.UnboxedtakeData.Bit.MutableTS castFromWords castToWords cloneToWordszipBits selectBits excludeBitsData.Bit.InternalData.Bit.MutableData.Bit.ImmutableTScastFromWordsM castToWordsM cloneToWordsMzipWith elemIndexData.Bit.ImmutableBitunBit unsafeFlipBitflipBit nthBitIndex countBitslistBits zipInPlace invertInPlaceselectBitsInPlaceexcludeBitsInPlacereverseInPlacebitIndexselect1.>..<.wordSizeghc-prim GHC.TypesWordlg2 lgWordSize wordSizeMask wordSizeMaskC divWordSize modWordSize mulWordSizenWordsnBitsaligned notAlignedalignUp alignDownmaskmaskedisMaskedmeld extractWord spliceWord reverseWordreversePartialWorddiffffs bitsInWord selectWordloMaskhiMaskBool indexWordreadWord writeWordbaseGHC.Baseflip Data.Bits complementid&vector-0.12.0.3-ChzWbiXyvuNAQj0dcU08SgData.Vector.Unboxed.BaseMVectorBitMVecVectorBitVecmapMInPlaceWithIndex