Skip to content

Commit

Permalink
Add utility functions to find correct sequential cache entries.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Oct 12, 2024
1 parent 1815c4b commit c71ded5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/storage/include/storage/SequentialCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions packages/storage/source/common/SequentialCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c71ded5

Please sign in to comment.