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

Method Format

postgres/parser/utils/bitarray.go:287–311  ·  view source on GitHub ↗

Format prints out the bit array to the buffer.

(buf *bytes.Buffer)

Source from the content-addressed store, hash-verified

285
286// Format prints out the bit array to the buffer.
287func (d BitArray) Format(buf *bytes.Buffer) {
288 bitLen := d.BitLen()
289 buf.Grow(int(bitLen))
290 for i := uint(0); i < bitLen/numBitsPerWord; i++ {
291 w := d.words[i]
292 // Change this loop if numBitsPerWord changes.
293 buf.WriteString(byteReprs[(w>>56)&0xff])
294 buf.WriteString(byteReprs[(w>>48)&0xff])
295 buf.WriteString(byteReprs[(w>>40)&0xff])
296 buf.WriteString(byteReprs[(w>>32)&0xff])
297 buf.WriteString(byteReprs[(w>>24)&0xff])
298 buf.WriteString(byteReprs[(w>>16)&0xff])
299 buf.WriteString(byteReprs[(w>>8)&0xff])
300 buf.WriteString(byteReprs[(w>>0)&0xff])
301 }
302 remainingBits := bitLen % numBitsPerWord
303 if remainingBits > 0 {
304 lastWord := d.words[bitLen/numBitsPerWord]
305 minShift := numBitsPerWord - 1 - remainingBits
306 for i := numBitsPerWord - 1; i > int(minShift); i-- {
307 bitVal := (lastWord >> uint(i)) & 1
308 buf.WriteByte('0' + byte(bitVal))
309 }
310 }
311}
312
313// EncodingPartsForBitLen creates a word backing array and the
314// "last bits used" value given the given total number of bits.

Callers 1

StringMethod · 0.95

Calls 2

BitLenMethod · 0.95
WriteStringMethod · 0.80

Tested by

no test coverage detected