diff options
| author | Per Larsson <[email protected]> | 2021-11-09 13:20:00 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-11-09 13:20:00 +0100 |
| commit | e0d54396fa3ba0f5466a4ea1f2810721c18fa55f (patch) | |
| tree | 4ab63a83dac7e1e9245d62be1918d12f4a55ae8d /zenserver/cache/cachekey.h | |
| parent | Added batched get chunk(s). (diff) | |
| download | zen-e0d54396fa3ba0f5466a4ea1f2810721c18fa55f.tar.xz zen-e0d54396fa3ba0f5466a4ea1f2810721c18fa55f.zip | |
Sort cache keys when resolving payload ID's.
Diffstat (limited to 'zenserver/cache/cachekey.h')
| -rw-r--r-- | zenserver/cache/cachekey.h | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/zenserver/cache/cachekey.h b/zenserver/cache/cachekey.h index 012a01292..5b67b0261 100644 --- a/zenserver/cache/cachekey.h +++ b/zenserver/cache/cachekey.h @@ -44,15 +44,67 @@ struct CacheKey static CacheKey Create(std::string_view Bucket, const IoHash& Hash) { return {.Bucket = ToLower(Bucket), .Hash = Hash}; } - static CacheKey None; + static const CacheKey Empty; }; -struct CacheChunk +inline bool +operator==(const CacheKey& A, const CacheKey& B) { - CacheKey Key; - IoHash Id; - uint64_t RawOffset = 0ull; - uint64_t RawSize = ~uint64_t(0); + return A.Bucket == B.Bucket && A.Hash == B.Hash; +} + +inline bool +operator!=(const CacheKey& A, const CacheKey& B) +{ + return A.Bucket != B.Bucket || A.Hash != B.Hash; +} + +inline bool +operator<(const CacheKey& A, const CacheKey& B) +{ + const std::string& BucketA = A.Bucket; + const std::string& BucketB = B.Bucket; + return BucketA == BucketB ? A.Hash < B.Hash : BucketA < BucketB; +} + +struct CacheChunkRequest +{ + CacheKey Key; + IoHash ChunkId; + Oid PayloadId; + uint64_t RawOffset = 0ull; + uint64_t RawSize = ~uint64_t(0); + CachePolicy Policy = CachePolicy::Default; }; +inline bool +operator<(const CacheChunkRequest& A, const CacheChunkRequest& B) +{ + if (A.Key < B.Key) + { + return true; + } + if (B.Key < A.Key) + { + return false; + } + if (A.ChunkId < B.ChunkId) + { + return true; + } + if (B.ChunkId < A.ChunkId) + { + return false; + } + if (A.PayloadId < B.PayloadId) + { + return true; + } + if (B.PayloadId < A.PayloadId) + { + return false; + } + return A.RawOffset < B.RawOffset; +} + } // namespace zen |