MCPcopy Create free account
hub / github.com/apache/cloudberry / shift_header_bits

Function shift_header_bits

src/backend/access/bitmap/bitmapinsert.c:415–483  ·  view source on GitHub ↗

* shift_header_bits() -- right-shift bits after 'startLoc' for * 'numofShiftingBits' bits. * * These bits are stored in an array of words with the word size of * BM_HRL_WORD_SIZE. This shift is done in-place. The maximum number of * words in this array is given. If the shifting causes the array not to * have enough space for all bits, the right-most overflow bits will be * discarded. The v

Source from the content-addressed store, hash-verified

413 * discarded. The value 'startLoc' starts with 0.
414 */
415static void
416shift_header_bits(BM_HRL_WORD* words, uint32 numOfBits,
417 uint32 maxNumOfWords, uint32 startLoc,
418 uint32 numOfShiftingBits)
419{
420 uint32 startWordNo;
421 uint32 endWordNo;
422 uint32 wordNo;
423 uint32 numOfFinalShiftingBits;
424 BM_HRL_WORD tmpWord;
425
426 Assert(startLoc <= numOfBits);
427 Assert((numOfBits-1)/BM_HRL_WORD_SIZE < maxNumOfWords);
428
429 startWordNo = startLoc/BM_HRL_WORD_SIZE;
430 endWordNo = (numOfBits-1)/BM_HRL_WORD_SIZE;
431
432 for (wordNo = endWordNo; wordNo > startWordNo; wordNo--)
433 {
434 /*
435 * obtain the last 'numOfShiftingBits' bits in the words[wordNo],
436 * and store them in the high-end of a word.
437 */
438 tmpWord = (((BM_HRL_WORD)words[wordNo])<<
439 (BM_HRL_WORD_SIZE-numOfShiftingBits));
440
441 /* right-shift the original word 'numOfShiftingBits' bits. */
442 words[wordNo] = (((BM_HRL_WORD)words[wordNo])>>numOfShiftingBits);
443
444 /* OR those shifted bits into the next word in the array. */
445 if (wordNo < maxNumOfWords-1)
446 words[wordNo + 1] |= tmpWord;
447
448 }
449
450 /* obtain bits after 'startLoc'.*/
451 tmpWord = ((BM_HRL_WORD)(words[startWordNo]<<
452 (startLoc%BM_HRL_WORD_SIZE)))>>(startLoc%BM_HRL_WORD_SIZE);
453
454 /*
455 * When startLoc%BM_HRL_WORD_SIZE is 0, we want to shift all 64 bits.
456 * There is no way to use the bit-shifting to shift all 64 bits out
457 * of a 64-bit integer. So just simply set the word to 0.
458 * Otherwise, use bit-shifting to shift out the bits after 'startLoc'.
459 */
460 if (startLoc%BM_HRL_WORD_SIZE > 0)
461 {
462 words[startWordNo] = ((BM_HRL_WORD)(words[startWordNo]>>
463 (BM_HRL_WORD_SIZE-startLoc%BM_HRL_WORD_SIZE)))<<
464 (BM_HRL_WORD_SIZE-startLoc%BM_HRL_WORD_SIZE);
465 }
466 else
467 {
468 words[startWordNo] = 0;
469 }
470
471 numOfFinalShiftingBits = numOfShiftingBits;
472 if (BM_HRL_WORD_SIZE - startLoc % BM_HRL_WORD_SIZE < numOfShiftingBits)

Callers 1

insert_newwordsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected