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

Function MakeBitArrayFromInt64

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

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