| 354 | |
| 355 | template <typename PtrType, typename AllocatorT, typename CompressedPtrType> |
| 356 | class PtrCompressor { |
| 357 | public: |
| 358 | explicit PtrCompressor(const AllocatorT& allocator) noexcept |
| 359 | : allocator_(allocator) {} |
| 360 | |
| 361 | const CompressedPtrType compress(const PtrType* uncompressed) const { |
| 362 | return allocator_.template compress<CompressedPtrType>( |
| 363 | uncompressed, false /* isMultiTiered */); |
| 364 | } |
| 365 | |
| 366 | PtrType* unCompress(const CompressedPtrType& compressed) const { |
| 367 | return static_cast<PtrType*>( |
| 368 | allocator_.template unCompress<CompressedPtrType>( |
| 369 | compressed, false /* isMultiTiered */)); |
| 370 | } |
| 371 | |
| 372 | bool operator==(const PtrCompressor& rhs) const noexcept { |
| 373 | return &allocator_ == &rhs.allocator_; |
| 374 | } |
| 375 | |
| 376 | bool operator!=(const PtrCompressor& rhs) const noexcept { |
| 377 | return !(*this == rhs); |
| 378 | } |
| 379 | |
| 380 | private: |
| 381 | // memory allocator that does the pointer compression. |
| 382 | const AllocatorT& allocator_; |
| 383 | }; |
| 384 | } // namespace cachelib |
| 385 | } // namespace facebook |