Expose BlobReader::Keys()

PiperOrigin-RevId: 694166186
This commit is contained in:
Paul Chang 2024-11-07 10:27:57 -08:00 committed by Copybara-Service
parent 868b01601f
commit d4050a2917
3 changed files with 16 additions and 0 deletions

View File

@ -201,6 +201,10 @@ class BlobStore {
return false;
}
hwy::Span<const hwy::uint128_t> Keys() const {
return hwy::Span<const hwy::uint128_t>(keys_, num_blobs_);
}
private:
uint32_t magic_;
uint32_t num_blobs_; // never 0
@ -303,6 +307,10 @@ BlobError BlobReader::ReadOne(hwy::uint128_t key, void* data,
return 0;
}
hwy::Span<const hwy::uint128_t> BlobReader::Keys() const {
return blob_store_->Keys();
}
BlobError BlobWriter::WriteAll(hwy::ThreadPool& pool, const Path& filename) {
HWY_ASSERT(keys_.size() == blobs_.size());

View File

@ -84,6 +84,9 @@ class BlobReader {
// Reads one blob directly.
BlobError ReadOne(hwy::uint128_t key, void* data, size_t size) const;
// Returns all available blob keys.
hwy::Span<const hwy::uint128_t> Keys() const;
private:
BlobStorePtr blob_store_; // holds header, not the entire file
std::vector<BlobIO> requests_;

View File

@ -70,6 +70,11 @@ TEST(BlobStoreTest, TestReadWrite) {
HWY_ASSERT_STRING_EQ("DATA", buffer.data());
}
const hwy::Span<const hwy::uint128_t> keys = reader.Keys();
HWY_ASSERT_EQ(keys.size(), 2);
HWY_ASSERT_EQ(keys[0], keyA);
HWY_ASSERT_EQ(keys[1], keyB);
close(fd);
unlink(path_str);
}