diff --git a/packages/storage/include/storage/SequentialCache.h b/packages/storage/include/storage/SequentialCache.h index 3968112..c5035bc 100644 --- a/packages/storage/include/storage/SequentialCache.h +++ b/packages/storage/include/storage/SequentialCache.h @@ -18,6 +18,9 @@ namespace l::filecache { int32_t GetClampedPosition(int32_t position, int32_t blockWidth); + int32_t GetClampedPositionOffset(int32_t position, int32_t blockWidth); + int32_t GetClampedIndex(int32_t position, int32_t blockWidth, int32_t numBlockEntries); + std::string GetCacheBlockName( std::string_view prefix, int32_t blockWidth, diff --git a/packages/storage/source/common/SequentialCache.cpp b/packages/storage/source/common/SequentialCache.cpp index 203f875..8d9422a 100644 --- a/packages/storage/source/common/SequentialCache.cpp +++ b/packages/storage/source/common/SequentialCache.cpp @@ -7,6 +7,16 @@ namespace l::filecache { return blockWidth * (position / blockWidth); } + int32_t GetClampedPositionOffset(int32_t position, int32_t blockWidth) { + return position - blockWidth * (position / blockWidth); + } + + int32_t GetClampedIndex(int32_t position, int32_t blockWidth, int32_t numBlockEntries) { + auto clampPosition = GetClampedPosition(position, blockWidth); + auto clampedOffset = position - clampPosition; + return numBlockEntries * clampedOffset / blockWidth; + } + std::string GetCacheBlockName(std::string_view prefix, int32_t blockWidth, int32_t clampedPos) { std::stringstream name; name << prefix.data();