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

Function Concat

pkg/util/bitarray/bitarray.go:398–441  ·  view source on GitHub ↗

Concat concatenates two bit arrays.

(lhs, rhs BitArray)

Source from the content-addressed store, hash-verified

396
397// Concat concatenates two bit arrays.
398func Concat(lhs, rhs BitArray) BitArray {
399 if lhs.lastBitsUsed == 0 {
400 return rhs
401 }
402 if rhs.lastBitsUsed == 0 {
403 return lhs
404 }
405 words := make([]word, (lhs.nonEmptyBitLen()+rhs.nonEmptyBitLen()+numBitsPerWord-1)/numBitsPerWord)
406
407 // The first bits come from the lhs unchanged.
408 copy(words, lhs.words)
409 var lastBitsUsed uint8
410 if lhs.lastBitsUsed == numBitsPerWord {
411 // Fast path. Just concatenate.
412 copy(words[len(lhs.words):], rhs.words)
413 lastBitsUsed = rhs.lastBitsUsed
414 } else {
415 // We need to shift all the words in the RHS
416 // by the lastBitsUsed of the LHS.
417 rhsShift := lhs.lastBitsUsed
418 targetWordIdx := len(lhs.words) - 1
419 trailingBits := words[targetWordIdx]
420 for _, w := range rhs.words {
421 headingBits := w >> rhsShift
422 combinedBits := trailingBits | headingBits
423 words[targetWordIdx] = combinedBits
424 targetWordIdx++
425 trailingBits = w << (numBitsPerWord - rhsShift)
426 }
427 lastBitsUsed = lhs.lastBitsUsed + rhs.lastBitsUsed
428 if lastBitsUsed > numBitsPerWord {
429 // Some bits from the RHS didn't fill a
430 // word, we need to fit them in the last word.
431 words[targetWordIdx] = trailingBits
432 }
433
434 // Compute the final thing.
435 lastBitsUsed %= numBitsPerWord
436 if lastBitsUsed == 0 {
437 lastBitsUsed = numBitsPerWord
438 }
439 }
440 return BitArray{words: words, lastBitsUsed: lastBitsUsed}
441}
442
443// Not computes the complement of a bit array.
444func Not(d BitArray) BitArray {

Callers

nothing calls this directly

Calls 1

nonEmptyBitLenMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…