Fix bitmap load_from_array

This commit is contained in:
DengzhiLiu
2022-11-23 07:41:36 +00:00
committed by wangzelin.wzl
parent 204a76baf6
commit b0bb9e7653
2 changed files with 15 additions and 4 deletions

View File

@ -140,6 +140,7 @@ int ObBitmap::load_blocks_from_array(size_type *block_data, size_type num_bits)
walk_ptr = walk_ptr->next_; walk_ptr = walk_ptr->next_;
} }
// Set bits in the same block after @valid_bits_ to false // Set bits in the same block after @valid_bits_ to false
if (0 != (valid_bits_ & BLOCK_MOD_MASK)) {
size_type inner_pos = valid_bits_; size_type inner_pos = valid_bits_;
walk_ptr = find_block(valid_bits_, inner_pos); walk_ptr = find_block(valid_bits_, inner_pos);
for (size_type i = bit_index(inner_pos); i < BITS_PER_BLOCK; ++i) { for (size_type i = bit_index(inner_pos); i < BITS_PER_BLOCK; ++i) {
@ -147,6 +148,7 @@ int ObBitmap::load_blocks_from_array(size_type *block_data, size_type num_bits)
} }
} }
} }
}
return ret; return ret;
} }

View File

@ -142,6 +142,15 @@ TEST_F(TestObBitmap, load_from_array)
EXPECT_EQ(OB_SUCCESS, bitmap.load_blocks_from_array(data, 64 * 5)); EXPECT_EQ(OB_SUCCESS, bitmap.load_blocks_from_array(data, 64 * 5));
EXPECT_EQ(64 * 5, bitmap.size()); EXPECT_EQ(64 * 5, bitmap.size());
EXPECT_EQ(3 * 5, bitmap.popcnt()); EXPECT_EQ(3 * 5, bitmap.popcnt());
bitmap.expand_size(4096);
ObBitmap::size_type data2[64];
for (int64_t i = 0; i < 64; i++) {
data2[i] = 7;
}
EXPECT_EQ(OB_SUCCESS, bitmap.load_blocks_from_array(data2, 64 * 64));
EXPECT_EQ(64 * 64, bitmap.size());
EXPECT_EQ(3 * 64, bitmap.popcnt());
} }
} // end of namespace unittest } // end of namespace unittest