{"modulePath":"github.com/cockroachdb/cockroachdb-parser","version":"v0.25.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package bitarray\n\n## Functions\n\n```go\nfunc Compare(lhs, rhs BitArray) int\n```\nCompare compares two bit arrays. They can have mixed sizes.\n\n```go\nfunc EncodingPartsForBitLen(bitLen uint) ([]uint64, uint64)\n```\nEncodingPartsForBitLen creates a word backing array and the \"last bits used\" value given the given total number of bits.\n\n```go\nfunc SizesForBitLen(bitLen uint) (uint, uint64)\n```\nSizesForBitLen computes the number of words and last bits used for the requested bit array size.\n\n## Types\n\n```go\ntype BitArray struct {\n\t// contains filtered or unexported fields\n}\n```\nBitArray implements a bit string of arbitrary length.\n\nThis uses a packed encoding (i.e. groups of 64 bits at a time) for memory efficiency and speed of bitwise operations (enables use of full machine registers for comparisons and logical operations), akin to the big.nat type.\n\nThere is something fancy needed to handle sorting values properly: the last group of bits must be padded right (start on the MSB) inside its word to compare properly according to pg semantics.\n\nThis type is designed for immutable instances. The functions and methods defined below never write to a bit array in-place. Of note, the ToWidth() and Next() functions will share the backing array between their operand and their result in some cases.\n\nFor portability, the size of the backing word is guaranteed to be 64 bits.\n\n```go\nfunc And(lhs, rhs BitArray) BitArray\n```\nAnd computes the logical AND of two bit arrays. The caller must ensure they have the same bit size.\n\n```go\nfunc Concat(lhs, rhs BitArray) BitArray\n```\nConcat concatenates two bit arrays.\n\n```go\nfunc FromEncodingParts(words []uint64, lastBitsUsed uint64) (BitArray, error)\n```\nFromEncodingParts creates a bit array from the encoding parts.\n\n```go\nfunc MakeBitArrayFromInt64(bitLen uint, val int64, valWidth uint) BitArray\n```\nMakeBitArrayFromInt64 creates a bit array with the specified size. The bits from the integer are written to the right of the bit array and the sign bit is extended.\n\n```go\nfunc MakeZeroBitArray(bitLen uint) BitArray\n```\nMakeZeroBitArray creates a bit array with the specified bit size.\n\n```go\nfunc Next(d BitArray) BitArray\n```\nNext returns the next possible bit array in lexicographic order. The backing array of words is shared if possible.\n\n```go\nfunc Not(d BitArray) BitArray\n```\nNot computes the complement of a bit array.\n\n```go\nfunc Or(lhs, rhs BitArray) BitArray\n```\nOr computes the logical OR of two bit arrays. The caller must ensure they have the same bit size.\n\n```go\nfunc Parse(s string) (res BitArray, err error)\n```\nParse parses a bit array from the specified string.\n\n```go\nfunc Rand(rng *rand.Rand, bitLen uint) BitArray\n```\nRand generates a random bit array of the specified length.\n\n```go\nfunc Xor(lhs, rhs BitArray) BitArray\n```\nXor computes the logical XOR of two bit arrays. The caller must ensure they have the same bit size.\n\n```go\nfunc (d BitArray) AsInt64(nbits uint) int64\n```\nAsInt64 returns the int constituted from the rightmost bits in the bit array.\n\n```go\nfunc (d *BitArray) AsUInt64() uint64\n```\nAsUInt64 returns the uint64 constituted from the rightmost bits in the bit array.\n\n```go\nfunc (d BitArray) BitLen() uint\n```\nBitLen returns the number of bits stored.\n\n```go\nfunc (d BitArray) Clone() BitArray\n```\nClone makes a copy of the bit array.\n\n```go\nfunc (d BitArray) EncodingParts() ([]uint64, uint64)\n```\nEncodingParts retrieves the encoding bits from the bit array. The words are presented in big-endian order, with the leftmost bits of the bitarray (MSB) in the MSB of each word.\n\n```go\nfunc (d BitArray) Format(buf *bytes.Buffer)\n```\nFormat prints out the bit array to the buffer.\n\n```go\nfunc (d BitArray) GetBitAtIndex(index int) (int, error)\n```\nGetBitAtIndex extract bit at given index in the BitArray.\n\n```go\nfunc (d BitArray) IsEmpty() bool\n```\nIsEmpty returns true iff the array is empty.\n\n```go\nfunc (d BitArray) LeftShiftAny(n int64) BitArray\n```\nLeftShiftAny performs a logical left shift, with a possible negative count. The number of bits to shift can be arbitrarily large (i.e. possibly larger than 64 in absolute value).\n\n```go\nfunc (d BitArray) SetBitAtIndex(index, toSet int) (BitArray, error)\n```\nSetBitAtIndex returns the BitArray with an updated bit at a given index.\n\n```go\nfunc (d BitArray) Sizeof() uintptr\n```\nSizeof returns the size in bytes of the bit array and its components.\n\n```go\nfunc (d BitArray) String() string\n```\nString implements the fmt.Stringer interface.\n\n```go\nfunc (d BitArray) ToWidth(desiredLen uint) BitArray\n```\nToWidth resizes the bit array to the specified size. If the specified width is shorter, bits on the right are truncated away. If the specified width is larger, zero bits are added on the right.\n\n","path":"github.com/cockroachdb/cockroachdb-parser/pkg/util/bitarray","name":"bitarray","synopsis":"","isRedistributable":true}
