| 238 | |
| 239 | |
| 240 | class TMaybeOwnedBitMap { |
| 241 | public: |
| 242 | // non-owning |
| 243 | explicit TMaybeOwnedBitMap( |
| 244 | const ui8* data, |
| 245 | ui32 beginOffsetInData, |
| 246 | ui32 size, |
| 247 | TIntrusivePtr<IResourceHolder> resourceHolder |
| 248 | ) |
| 249 | : Data_( |
| 250 | TMaybeOwningConstArrayHolder<const ui8>::CreateOwning( |
| 251 | { |
| 252 | data + beginOffsetInData / CHAR_BIT, |
| 253 | CeilDiv<size_t>(beginOffsetInData % CHAR_BIT + size, CHAR_BIT) |
| 254 | }, |
| 255 | std::move(resourceHolder) |
| 256 | ) |
| 257 | ) |
| 258 | , BeginOffsetInData_(beginOffsetInData % CHAR_BIT) |
| 259 | , Size_(size) |
| 260 | { |
| 261 | } |
| 262 | |
| 263 | int operator&(IBinSaver& binSaver) { |
| 264 | binSaver.Add(0, &Data_); |
| 265 | binSaver.Add(1, &BeginOffsetInData_); |
| 266 | binSaver.Add(1, &Size_); |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | bool operator==(const TMaybeOwnedBitMap& rhs) const { |
| 271 | if (Size_ != rhs.Size_) { |
| 272 | return false; |
| 273 | } |
| 274 | // could be optimized for some cases but this operation is not performance-critical right now |
| 275 | for (auto i : xrange(Size_)) { |
| 276 | if ((*this)[i] != rhs[i]) { |
| 277 | return false; |
| 278 | } |
| 279 | } |
| 280 | return true; |
| 281 | } |
| 282 | |
| 283 | bool operator[](size_t idx) const { |
| 284 | Y_ASSERT(idx < Size_); |
| 285 | size_t offsetInData = BeginOffsetInData_ + idx; |
| 286 | return (Data_[offsetInData / CHAR_BIT] >> (offsetInData % CHAR_BIT)) & 1; |
| 287 | } |
| 288 | |
| 289 | ui32 GetSize() const { |
| 290 | return Size_; |
| 291 | } |
| 292 | |
| 293 | TMaybeOwnedBitMap Slice(size_t offset, size_t size) const { |
| 294 | return TMaybeOwnedBitMap( |
| 295 | Data_.data(), |
| 296 | BeginOffsetInData_ + offset, |
| 297 | size, |
no outgoing calls
no test coverage detected