Skip to content

Commit

Permalink
Apply final suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Qup42 committed Jul 16, 2024
1 parent 13e3f56 commit 21cfbba
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 110 deletions.
23 changes: 14 additions & 9 deletions src/index/LocatedTriples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ IdTable LocatedTriplesPerBlock::mergeTriples(size_t blockIndex,

// ____________________________________________________________________________
std::vector<LocatedTriples::iterator> LocatedTriplesPerBlock::add(
std::span<const LocatedTriple> locatedTriples,
std::vector<CompressedBlockMetadata> originalMetadata) {
std::span<const LocatedTriple> locatedTriples) {
std::vector<LocatedTriples::iterator> handles;
handles.reserve(locatedTriples.size());
for (auto triple : locatedTriples) {
Expand All @@ -185,15 +184,14 @@ std::vector<LocatedTriples::iterator> LocatedTriplesPerBlock::add(
handles.emplace_back(handle);
}

updateAugmentedMetadata(std::move(originalMetadata));
updateAugmentedMetadata();

return handles;
}

// ____________________________________________________________________________
void LocatedTriplesPerBlock::erase(
size_t blockIndex, LocatedTriples::iterator iter,
std::vector<CompressedBlockMetadata> originalMetadata) {
void LocatedTriplesPerBlock::erase(size_t blockIndex,
LocatedTriples::iterator iter) {
auto blockIter = map_.find(blockIndex);
AD_CONTRACT_CHECK(blockIter != map_.end(), "Block ", blockIndex,
" is not contained.");
Expand All @@ -203,15 +201,22 @@ void LocatedTriplesPerBlock::erase(
if (block.empty()) {
map_.erase(blockIndex);
}
updateAugmentedMetadata(std::move(originalMetadata));
updateAugmentedMetadata();
}

// ____________________________________________________________________________
void LocatedTriplesPerBlock::updateAugmentedMetadata(
void LocatedTriplesPerBlock::setOriginalMetadata(
std::vector<CompressedBlockMetadata> metadata) {
// Copy block metadata to augment it with updated triples.
originalMetadata_ = std::move(metadata);
updateAugmentedMetadata();
}

// ____________________________________________________________________________
void LocatedTriplesPerBlock::updateAugmentedMetadata() {
// TODO<C++23> use view::enumerate
size_t blockIndex = 0;
// Copy to preserve originalMetadata_.
std::vector<CompressedBlockMetadata> metadata(originalMetadata_);
for (auto& blockMetadata : metadata) {
if (hasUpdates(blockIndex)) {
const auto& blockUpdates = map_.at(blockIndex);
Expand Down
18 changes: 9 additions & 9 deletions src/index/LocatedTriples.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class LocatedTriplesPerBlock {
// Stores the block metadata where the block borders have been adjusted for
// the updated triples.
std::optional<std::vector<CompressedBlockMetadata>> augmentedMetadata_;
std::vector<CompressedBlockMetadata> originalMetadata_;
void updateAugmentedMetadata();

public:
// Get upper limits for the number of located triples for the given block. The
Expand Down Expand Up @@ -130,11 +132,9 @@ class LocatedTriplesPerBlock {
// 1. The `locatedTriples` must not already exist in
// `LocatedTriplesPerBlock`.
std::vector<LocatedTriples::iterator> add(
std::span<const LocatedTriple> locatedTriples,
std::vector<CompressedBlockMetadata> originalMetadata);
std::span<const LocatedTriple> locatedTriples);

void erase(size_t blockIndex, LocatedTriples::iterator iter,
std::vector<CompressedBlockMetadata> originalMetadata);
void erase(size_t blockIndex, LocatedTriples::iterator iter);

// Get the total number of `LocatedTriple`s (for all blocks).
size_t numTriples() const { return numTriples_; }
Expand All @@ -143,9 +143,9 @@ class LocatedTriplesPerBlock {
size_t numBlocks() const { return map_.size(); }

// Must be called initially before using the `LocatedTriplesPerBlock` to
// initialize the block metadata that is augmented for updated triples. This
// is currently done in `Permutation::loadFromDisk`.
void updateAugmentedMetadata(std::vector<CompressedBlockMetadata> metadata);
// initialize the original block metadata that is augmented for updated
// triples. This is currently done in `Permutation::loadFromDisk`.
void setOriginalMetadata(std::vector<CompressedBlockMetadata> metadata);

// Returns the block metadata where the block borders have been updated to
// account for the update triples. All triples (both insert and delete) will
Expand All @@ -156,10 +156,10 @@ class LocatedTriplesPerBlock {
};

// Remove all located triples.
void clear(std::vector<CompressedBlockMetadata> metadata) {
void clear() {
map_.clear();
numTriples_ = 0;
augmentedMetadata_ = std::move(metadata);
augmentedMetadata_ = originalMetadata_;
}

// This operator is only for debugging and testing. It returns a
Expand Down
Loading

0 comments on commit 21cfbba

Please sign in to comment.