Skip to content

Commit

Permalink
rename seg::Decompressor decoder to decompressor
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr committed Oct 17, 2024
1 parent 5a53475 commit ef02247
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
26 changes: 13 additions & 13 deletions silkworm/db/datastore/snapshots/index_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,34 @@ static IndexInputDataQuery::Iterator::value_type decompressor_index_query_entry(
}

IndexInputDataQuery::Iterator DecompressorIndexInputDataQuery::begin() {
auto decoder = std::make_shared<seg::Decompressor>(segment_path_.path(), segment_region_);
decoder->open();
auto decompressor = std::make_shared<seg::Decompressor>(segment_path_.path(), segment_region_);
decompressor->open();

auto impl_it = std::make_shared<IteratorImpl>(IteratorImpl{decoder, decoder->begin()});
auto impl_it = std::make_shared<IteratorImpl>(IteratorImpl{decompressor, decompressor->begin()});
return IndexInputDataQuery::Iterator{this, impl_it, decompressor_index_query_entry(impl_it->it)};
}

IndexInputDataQuery::Iterator DecompressorIndexInputDataQuery::end() {
auto decoder = std::make_shared<seg::Decompressor>(segment_path_.path(), segment_region_);
auto decompressor = std::make_shared<seg::Decompressor>(segment_path_.path(), segment_region_);

auto impl_it = std::make_shared<IteratorImpl>(IteratorImpl{{}, decoder->end()});
auto impl_it = std::make_shared<IteratorImpl>(IteratorImpl{{}, decompressor->end()});
return IndexInputDataQuery::Iterator{this, impl_it, decompressor_index_query_entry(impl_it->it)};
}

size_t DecompressorIndexInputDataQuery::keys_count() {
seg::Decompressor decoder{segment_path_.path(), segment_region_};
decoder.open();
return decoder.words_count();
seg::Decompressor decompressor{segment_path_.path(), segment_region_};
decompressor.open();
return decompressor.words_count();
}

std::pair<std::shared_ptr<void>, IndexInputDataQuery::Iterator::value_type>
DecompressorIndexInputDataQuery::next_iterator(std::shared_ptr<void> it_impl) {
auto& it_impl_ref = *reinterpret_cast<IteratorImpl*>(it_impl.get());
// check if not already at the end
if (it_impl_ref.decoder) {
if (it_impl_ref.decompressor) {
++it_impl_ref.it;
if (it_impl_ref.it == it_impl_ref.decoder->end()) {
it_impl_ref.decoder.reset();
if (it_impl_ref.it == it_impl_ref.decompressor->end()) {
it_impl_ref.decompressor.reset();
}
}
return {it_impl, decompressor_index_query_entry(it_impl_ref.it)};
Expand All @@ -84,8 +84,8 @@ bool DecompressorIndexInputDataQuery::equal_iterators(
std::shared_ptr<void> rhs_it_impl) const {
auto lhs = reinterpret_cast<IteratorImpl*>(lhs_it_impl.get());
auto rhs = reinterpret_cast<IteratorImpl*>(rhs_it_impl.get());
return (lhs->decoder == rhs->decoder) &&
(!lhs->decoder || (lhs->it == rhs->it));
return (lhs->decompressor == rhs->decompressor) &&
(!lhs->decompressor || (lhs->it == rhs->it));
}

void IndexBuilder::build() {
Expand Down
2 changes: 1 addition & 1 deletion silkworm/db/datastore/snapshots/index_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class DecompressorIndexInputDataQuery : public IndexInputDataQuery {

private:
struct IteratorImpl {
std::shared_ptr<seg::Decompressor> decoder;
std::shared_ptr<seg::Decompressor> decompressor;
seg::Decompressor::Iterator it;
};

Expand Down
22 changes: 11 additions & 11 deletions silkworm/db/datastore/snapshots/segment/segment_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ SegmentFileReader::SegmentFileReader(
SnapshotPath path,
std::optional<MemoryMappedRegion> segment_region)
: path_(std::move(path)),
decoder_{path_.path(), segment_region} {}
decompressor_{path_.path(), segment_region} {}

SegmentFileReader::~SegmentFileReader() {
close();
}

MemoryMappedRegion SegmentFileReader::memory_file_region() const {
const auto memory_file{decoder_.memory_file()};
const auto memory_file{decompressor_.memory_file()};
if (!memory_file) return MemoryMappedRegion{};
return memory_file->region();
}
Expand All @@ -43,7 +43,7 @@ void SegmentFileReader::reopen_segment() {
close();

// Open decompressor that opens the mapped file in turns
decoder_.open();
decompressor_.open();
}

SegmentFileReader::Iterator& SegmentFileReader::Iterator::operator++() {
Expand Down Expand Up @@ -76,8 +76,8 @@ bool operator==(const SegmentFileReader::Iterator& lhs, const SegmentFileReader:
}

SegmentFileReader::Iterator SegmentFileReader::begin(std::shared_ptr<Decoder> decoder) const {
auto it = decoder_.begin();
if (it == decoder_.end()) {
auto it = decompressor_.begin();
if (it == decompressor_.end()) {
return end();
}
decoder->decode_word(*it);
Expand All @@ -86,16 +86,16 @@ SegmentFileReader::Iterator SegmentFileReader::begin(std::shared_ptr<Decoder> de
}

SegmentFileReader::Iterator SegmentFileReader::end() const {
return SegmentFileReader::Iterator{decoder_.end(), {}, path()};
return SegmentFileReader::Iterator{decompressor_.end(), {}, path()};
}

seg::Decompressor::Iterator SegmentFileReader::seek_decoder(uint64_t offset, std::optional<Hash> hash_prefix) const {
return decoder_.seek(offset, hash_prefix ? ByteView{hash_prefix->bytes, 1} : ByteView{});
seg::Decompressor::Iterator SegmentFileReader::seek_decompressor(uint64_t offset, std::optional<Hash> hash_prefix) const {
return decompressor_.seek(offset, hash_prefix ? ByteView{hash_prefix->bytes, 1} : ByteView{});
}

SegmentFileReader::Iterator SegmentFileReader::seek(uint64_t offset, std::optional<Hash> hash_prefix, std::shared_ptr<Decoder> decoder) const {
auto it = seek_decoder(offset, hash_prefix);
if (it == decoder_.end()) {
auto it = seek_decompressor(offset, hash_prefix);
if (it == decompressor_.end()) {
return end();
}
try {
Expand All @@ -109,7 +109,7 @@ SegmentFileReader::Iterator SegmentFileReader::seek(uint64_t offset, std::option

void SegmentFileReader::close() {
// Close decompressor that closes the mapped file in turns
decoder_.close();
decompressor_.close();
}

} // namespace silkworm::snapshots
6 changes: 3 additions & 3 deletions silkworm/db/datastore/snapshots/segment/segment_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class SegmentFileReader {
std::filesystem::path fs_path() const { return path_.path(); }

bool empty() const { return item_count() == 0; }
size_t item_count() const { return decoder_.words_count(); }
size_t item_count() const { return decompressor_.words_count(); }

MemoryMappedRegion memory_file_region() const;

Expand All @@ -104,12 +104,12 @@ class SegmentFileReader {
Iterator seek(uint64_t offset, std::optional<Hash> hash_prefix, std::shared_ptr<Decoder> decoder) const;

private:
seg::Decompressor::Iterator seek_decoder(uint64_t offset, std::optional<Hash> hash_prefix) const;
seg::Decompressor::Iterator seek_decompressor(uint64_t offset, std::optional<Hash> hash_prefix) const;

//! The path of the segment file for this snapshot
SnapshotPath path_;

seg::Decompressor decoder_;
seg::Decompressor decompressor_;
};

template <DecoderConcept TDecoder>
Expand Down

0 comments on commit ef02247

Please sign in to comment.