cockroach: Index | Files

package bitarray

import ""


Package Files


func Compare Uses

func Compare(lhs, rhs BitArray) int

Compare compares two bit arrays. They can have mixed sizes.

func EncodingPartsForBitLen Uses

func EncodingPartsForBitLen(bitLen uint) ([]uint64, uint64)

EncodingPartsForBitLen creates a word backing array and the "last bits used" value given the given total number of bits.

func SizesForBitLen Uses

func SizesForBitLen(bitLen uint) (uint, uint64)

SizesForBitLen computes the number of words and last bits used for the requested bit array size.

type BitArray Uses

type BitArray struct {
    // contains filtered or unexported fields

BitArray implements a bit string of arbitrary length.

This 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.

There 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.

This 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.

For portability, the size of the backing word is guaranteed to be 64 bits.

func And Uses

func And(lhs, rhs BitArray) BitArray

And computes the logical AND of two bit arrays. The caller must ensure they have the same bit size.

func Concat Uses

func Concat(lhs, rhs BitArray) BitArray

Concat concatenates two bit arrays.

func FromEncodingParts Uses

func FromEncodingParts(words []uint64, lastBitsUsed uint64) (BitArray, error)

FromEncodingParts creates a bit array from the encoding parts.

func MakeBitArrayFromInt64 Uses

func MakeBitArrayFromInt64(bitLen uint, val int64, valWidth uint) BitArray

MakeBitArrayFromInt64 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.

func MakeZeroBitArray Uses

func MakeZeroBitArray(bitLen uint) BitArray

MakeZeroBitArray creates a bit array with the specified bit size.

func Next Uses

func Next(d BitArray) BitArray

Next returns the next possible bit array in lexicographic order. The backing array of words is shared if possible.

func Not Uses

func Not(d BitArray) BitArray

Not computes the complement of a bit array.

func Or Uses

func Or(lhs, rhs BitArray) BitArray

Or computes the logical OR of two bit arrays. The caller must ensure they have the same bit size.

func Parse Uses

func Parse(s string) (res BitArray, err error)

Parse parses a bit array from the specified string.

func Rand Uses

func Rand(rng *rand.Rand, bitLen uint) BitArray

Rand generates a random bit array of the specified length.

func Xor Uses

func Xor(lhs, rhs BitArray) BitArray

Xor computes the logical XOR of two bit arrays. The caller must ensure they have the same bit size.

func (BitArray) AsInt64 Uses

func (d BitArray) AsInt64(nbits uint) int64

AsInt64 returns the int constituted from the rightmost bits in the bit array.

func (BitArray) BitLen Uses

func (d BitArray) BitLen() uint

BitLen returns the number of bits stored.

func (BitArray) Clone Uses

func (d BitArray) Clone() BitArray

Clone makes a copy of the bit array.

func (BitArray) EncodingParts Uses

func (d BitArray) EncodingParts() ([]uint64, uint64)

EncodingParts 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.

func (BitArray) Format Uses

func (d BitArray) Format(buf *bytes.Buffer)

Format prints out the bit array to the buffer.

func (BitArray) IsEmpty Uses

func (d BitArray) IsEmpty() bool

IsEmpty returns true iff the array is empty.

func (BitArray) LeftShiftAny Uses

func (d BitArray) LeftShiftAny(n int64) BitArray

LeftShiftAny 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).

func (BitArray) Sizeof Uses

func (d BitArray) Sizeof() uintptr

Sizeof returns the size in bytes of the bit array and its components.

func (BitArray) String Uses

func (d BitArray) String() string

String implements the fmt.Stringer interface.

func (BitArray) ToWidth Uses

func (d BitArray) ToWidth(desiredLen uint) BitArray

ToWidth 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.

Package bitarray imports 7 packages (graph) and is imported by 16 packages. Updated 2019-07-20. Refresh now. Tools for package owners.