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

Function MakeBitArrayFromInt64

postgres/parser/utils/bitarray.go:174–202  ·  view source on GitHub ↗

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.

(bitLen uint, val int64, valWidth uint)

Source from the content-addressed store, hash-verified

172// size. The bits from the integer are written to the right of the bit
173// array and the sign bit is extended.
174func MakeBitArrayFromInt64(bitLen uint, val int64, valWidth uint) BitArray {
175 if bitLen == 0 {
176 return BitArray{}
177 }
178 d := MakeZeroBitArray(bitLen)
179 if bitLen < valWidth {
180 // Fast path, no sign extension to compute.
181 d.words[len(d.words)-1] = word(val << (numBitsPerWord - bitLen))
182 return d
183 }
184 if val&(1<<(valWidth-1)) != 0 {
185 // Sign extend, fill ones in every word but the last.
186 for i := 0; i < len(d.words)-1; i++ {
187 d.words[i] = ^word(0)
188 }
189 }
190 // Shift the value to its given number of bits, to position the sign
191 // bit to the left.
192 val = val << (numBitsPerWord - valWidth)
193 // Shift right back with arithmetic shift to extend the sign bit.
194 val = val >> (numBitsPerWord - valWidth)
195 // Store the right part of the value in the last word.
196 d.words[len(d.words)-1] = word(val << (numBitsPerWord - d.lastBitsUsed))
197 // Store the left part in the next-to-last word, if any.
198 if valWidth > uint(d.lastBitsUsed) {
199 d.words[len(d.words)-2] = word(val >> d.lastBitsUsed)
200 }
201 return d
202}
203
204// AsInt64 returns the int constituted from the rightmost bits in the
205// bit array.

Callers 1

NewDBitArrayFromIntFunction · 0.92

Calls 1

MakeZeroBitArrayFunction · 0.85

Tested by

no test coverage detected