| 437 | */ |
| 438 | template <class TValue, class TContainer, class TSize = size_t> |
| 439 | class TSparseArrayBase final : public TThrRefBase { |
| 440 | static_assert(std::is_integral<TSize>::value); |
| 441 | |
| 442 | public: |
| 443 | using TIndexing = TSparseArrayIndexing<TSize>; |
| 444 | using TIndexingPtr = TIntrusivePtr<TSparseArrayIndexing<TSize>>; |
| 445 | using TIndexingImpl = typename TIndexing::TImpl; |
| 446 | using TNonConstValue = typename std::remove_const<TValue>::type; |
| 447 | |
| 448 | public: |
| 449 | // needed because of IBinSaver |
| 450 | TSparseArrayBase() |
| 451 | : NonDefaultValues(TContainer()) |
| 452 | , DefaultValue(TValue()) |
| 453 | {} |
| 454 | |
| 455 | TSparseArrayBase( |
| 456 | TIndexingPtr indexing, |
| 457 | TContainer&& nonDefaultValues, |
| 458 | TValue&& defaultValue = TValue(0)); |
| 459 | |
| 460 | template <class TIndexingArg> |
| 461 | TSparseArrayBase( |
| 462 | TIndexingArg&& indexing, |
| 463 | TContainer&& nonDefaultValues, |
| 464 | TValue&& defaultValue = TValue(0)); |
| 465 | |
| 466 | int operator&(IBinSaver& binSaver); |
| 467 | |
| 468 | // comparison is strict by default, useful for unit tests |
| 469 | bool operator==(const TSparseArrayBase& rhs) const { |
| 470 | return EqualTo(rhs, true); |
| 471 | } |
| 472 | |
| 473 | // if strict is true compare bit-by-bit, else compare values |
| 474 | bool EqualTo(const TSparseArrayBase& rhs, bool strict = true) const; |
| 475 | |
| 476 | TSize GetNonDefaultSize() const { |
| 477 | return Indexing->GetNonDefaultSize(); |
| 478 | } |
| 479 | |
| 480 | TSize GetDefaultSize() const { |
| 481 | return Indexing->GetDefaultSize(); |
| 482 | } |
| 483 | |
| 484 | TSize GetSize() const { |
| 485 | return Indexing->GetSize(); |
| 486 | } |
| 487 | |
| 488 | const TValue& GetDefaultValue() const { |
| 489 | return DefaultValue; |
| 490 | } |
| 491 | |
| 492 | // f is a visitor function that will be repeatedly called with (index, value) arguments |
| 493 | template <class F> |
| 494 | inline void ForEachNonDefault(F&& f, TSize maxBlockSize = TSize(128)) const; |
| 495 | |
| 496 | // f is a visitor function that will be repeatedly called with (indexBlock, valueBlock) arguments |