MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / MakeBitArrayFromInt64

Function MakeBitArrayFromInt64

pkg/util/bitarray/bitarray.go:160–188  ·  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

158// size. The bits from the integer are written to the right of the bit
159// array and the sign bit is extended.
160func MakeBitArrayFromInt64(bitLen uint, val int64, valWidth uint) BitArray {
161 if bitLen == 0 {
162 return BitArray{}
163 }
164 d := MakeZeroBitArray(bitLen)
165 if bitLen < valWidth {
166 // Fast path, no sign extension to compute.
167 d.words[len(d.words)-1] = word(val << (numBitsPerWord - bitLen))
168 return d
169 }
170 if val&(1<<(valWidth-1)) != 0 {
171 // Sign extend, fill ones in every word but the last.
172 for i := 0; i < len(d.words)-1; i++ {
173 d.words[i] = ^word(0)
174 }
175 }
176 // Shift the value to its given number of bits, to position the sign
177 // bit to the left.
178 val = val << (numBitsPerWord - valWidth)
179 // Shift right back with arithmetic shift to extend the sign bit.
180 val = val >> (numBitsPerWord - valWidth)
181 // Store the right part of the value in the last word.
182 d.words[len(d.words)-1] = word(val << (numBitsPerWord - d.lastBitsUsed))
183 // Store the left part in the next-to-last word, if any.
184 if valWidth > uint(d.lastBitsUsed) {
185 d.words[len(d.words)-2] = word(val >> d.lastBitsUsed)
186 }
187 return d
188}
189
190// AsInt64 returns the int constituted from the rightmost bits in the
191// bit array.

Callers 1

NewDBitArrayFromIntFunction · 0.92

Calls 1

MakeZeroBitArrayFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…