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

Function insert_newwords

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

* insert_newwords() -- insert a buffer of new words into a given buffer of * words at a specified position. * * The new words will be inserted into the positions starting from * 'insertPos'(>=0). The original words from 'insertPos' will be shifted * to the right. If the given array does not have enough space to * hold all words, the last '(*numWordsP+numNewWords-maxNumWords)' words * will

Source from the content-addressed store, hash-verified

503 * This function assumes that the number of new words is not greater than BM_HRL_WORD_SIZE.
504 */
505static void
506insert_newwords(BMTIDBuffer* words, uint32 insertPos,
507 BMTIDBuffer* new_words, BMTIDBuffer* words_left)
508{
509 int32 wordNo;
510 uint16 bitLoc;
511
512 Assert(new_words->curword <= BM_HRL_WORD_SIZE);
513 Assert(insertPos <= words->num_cwords);
514
515 words_left->curword = 0;
516
517 /* if there are no words in the original buffer, we simply copy the new words. */
518 if (words->curword == 0)
519 {
520 memcpy(words->cwords, new_words->cwords, new_words->curword*sizeof(BM_HRL_WORD));
521 memcpy(words->hwords, new_words->hwords,
522 BM_CALC_H_WORDS(new_words->curword) * sizeof(BM_HRL_WORD));
523 words->curword = new_words->curword;
524
525 return;
526 }
527
528 /*
529 * if insertPos is pointing to the position after the maximum position
530 * in this word, we simply copy the new words to leftContentWords.
531 */
532 if (insertPos == words->num_cwords)
533 {
534 memcpy(words_left->cwords, new_words->cwords,
535 new_words->curword * sizeof(BM_HRL_WORD));
536 memcpy(words_left->hwords, new_words->hwords,
537 BM_CALC_H_WORDS(new_words->curword) * sizeof(BM_HRL_WORD));
538 words_left->curword = new_words->curword;
539
540 return;
541 }
542
543 Assert(words->curword > 0);
544
545 /* Calculate how many words left after this insert. */
546 if (words->curword + new_words->curword > words->num_cwords)
547 words_left->curword = words->curword + new_words->curword - words->num_cwords;
548 MemSet(words_left->hwords, 0, BM_NUM_OF_HEADER_WORDS * sizeof(BM_HRL_WORD));
549
550 /*
551 * Walk from the last word in the array back to 'insertPos'.
552 * If the word no + new_words->curword is greater than words->num_cwords,
553 * we store these words in words_left.
554 */
555 for (wordNo=words->curword-1; wordNo>=0 && wordNo>=insertPos; wordNo--)
556 {
557 if (wordNo + new_words->curword >= words->num_cwords)
558 {
559 words_left->cwords[wordNo+new_words->curword-words->num_cwords] =
560 words->cwords[wordNo];
561 if (IS_FILL_WORD(words->hwords, wordNo))
562 {

Callers 1

updatesetbit_inpageFunction · 0.85

Calls 2

IS_FILL_WORDFunction · 0.85
shift_header_bitsFunction · 0.85

Tested by

no test coverage detected