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

Function CopyBitfieldBytesToSegments

src/types/redis_bitmap.cc:788–819  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

786}
787
788static rocksdb::Status CopyBitfieldBytesToSegments(engine::Context &ctx, Bitmap::SegmentCacheStore &store,
789 const ArrayBitfieldBitmap &bitfield, uint32_t byte_offset,
790 uint32_t bytes) {
791 uint32_t segment_index = byte_offset / kBitmapSegmentBytes;
792 auto segment_byte_offset = static_cast<int>(byte_offset % kBitmapSegmentBytes);
793 auto remain_bytes = static_cast<int32_t>(bytes);
794 for (; remain_bytes > 0; ++segment_index) {
795 std::string *cache = nullptr;
796 auto cache_status = store.GetMut(ctx, segment_index, &cache);
797 if (!cache_status.ok()) {
798 return cache_status;
799 }
800
801 auto copy_count = std::min(remain_bytes, static_cast<int32_t>(kBitmapSegmentBytes - segment_byte_offset));
802 if (static_cast<int>(cache->size()) < segment_byte_offset + copy_count) {
803 cache->resize(segment_byte_offset + copy_count);
804 }
805
806 auto dst = reinterpret_cast<uint8_t *>(cache->data()) + segment_byte_offset;
807 auto status = bitfield.Get(byte_offset, copy_count, dst);
808 if (!status) {
809 return rocksdb::Status::InvalidArgument();
810 }
811
812 // next segment will copy from its front.
813 byte_offset = (segment_index + 1) * kBitmapSegmentBytes;
814 // maybe negative, but still correct.
815 remain_bytes -= static_cast<int32_t>(kBitmapSegmentBytes - segment_byte_offset);
816 segment_byte_offset = 0;
817 }
818 return rocksdb::Status::OK();
819}
820
821template <bool ReadOnly>
822rocksdb::Status Bitmap::bitfield(engine::Context &ctx, const Slice &user_key, const std::vector<BitfieldOperation> &ops,

Callers 1

Calls 2

GetMutMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected