MCPcopy Create free account
hub / github.com/dolthub/doltgresql / BitArray

Struct BitArray

postgres/parser/utils/bitarray.go:57–88  ·  view source on GitHub ↗

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 fa

Source from the content-addressed store, hash-verified

55// For portability, the size of the backing word is guaranteed to be 64
56// bits.
57type BitArray struct {
58 // words is the backing array.
59 //
60 // The leftmost bits in the literal representation are placed in the
61 // MSB of each word.
62 //
63 // The last word contain the rightmost bits in the literal
64 // representation, right-padded. For example if there are 3 bits
65 // to store, the 3 MSB bits of the last word will be set and the
66 // remaining LSB bits will be set to zero.
67 //
68 // The number of stored bits is actually:
69 // 0 if lastBitsUsed = 0 or len(word) == 0
70 // otherwise, (len(words)-1)*numBitsPerWord + lastBitsUsed
71 //
72 // TODO(jutin, nathan): consider using the trick in bytes.Buffer of
73 // keeping a static [1]word which word can initially point to to
74 // avoid heap allocations in the common case of small arrays.
75 words []word
76
77 // lastBitsUsed is the number of bits in the last word that
78 // participate in the value stored. It can only be zero
79 // for empty bit arrays; otherwise it's always between 1 and
80 // numBitsPerWord.
81 //
82 // For example:
83 // - 0 bits in array: len(words) == 0, lastBitsUsed = 0
84 // - 1 bits in array: len(words) == 1, lastBitsUsed = 1
85 // - 64 bits in array: len(words) == 1, lastBitsUsed = 64
86 // - 65 bits in array: len(words) == 2, lastBitsUsed = 1
87 lastBitsUsed uint8
88}
89
90type word = uint64
91

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected