MCPcopy Create free account
hub / github.com/apache/kvrocks / SetBitfield

Method SetBitfield

src/common/bitfield_util.h:255–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253 }
254
255 [[nodiscard]] Status SetBitfield(uint32_t bit_offset, uint32_t bits, uint64_t value) {
256 uint32_t first_byte = bit_offset / 8;
257 uint32_t last_byte = (bit_offset + bits - 1) / 8 + 1;
258 Status bound_status = checkLegalBound(first_byte, last_byte - first_byte);
259 if (!bound_status) {
260 return bound_status;
261 }
262
263 bit_offset -= byte_offset_ * 8;
264 while (bits--) {
265 bool v = (value & (uint64_t(1) << bits)) != 0;
266 uint32_t byte = bit_offset >> 3;
267 uint32_t bit = 7 - (bit_offset & 7);
268 uint32_t byteval = buf_[byte];
269 byteval &= ~(1 << bit);
270 byteval |= int(v) << bit;
271 buf_[byte] = char(byteval);
272 bit_offset++;
273 }
274 return Status::OK();
275 }
276
277 private:
278 // The bit field cannot exceed 64 bits, takes an extra byte when it unaligned.

Callers 2

BitfieldMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected