Resize the segment to makes its new length at least min_bytes, new bytes will be set to 0. min_bytes can not more than kBitmapSegmentBytes
| 72 | // Resize the segment to makes its new length at least min_bytes, new bytes will be set to 0. |
| 73 | // min_bytes can not more than kBitmapSegmentBytes |
| 74 | void ExpandBitmapSegment(std::string *segment, size_t min_bytes) { |
| 75 | assert(min_bytes <= kBitmapSegmentBytes); |
| 76 | |
| 77 | auto old_size = segment->size(); |
| 78 | if (min_bytes > old_size) { |
| 79 | size_t new_size = 0; |
| 80 | if (min_bytes > old_size * 2) { |
| 81 | new_size = min_bytes; |
| 82 | } else if (old_size * 2 > kBitmapSegmentBytes) { |
| 83 | new_size = kBitmapSegmentBytes; |
| 84 | } else { |
| 85 | new_size = old_size * 2; |
| 86 | } |
| 87 | segment->resize(new_size, 0); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // Constructing sub-key index, see: |
| 92 | // https://kvrocks.apache.org/community/data-structure-on-rocksdb#bitmap-sub-keys-values |