Skip to content

Commit

Permalink
There were unstaged changes...
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Kalmbach <[email protected]>
  • Loading branch information
joka921 committed Oct 22, 2024
1 parent dc7a710 commit 95bbbeb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
19 changes: 7 additions & 12 deletions src/index/CompressedRelation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,18 +869,13 @@ void CompressedRelationWriter::compressAndWriteBlock(
AD_CORRECTNESS_CHECK(lastCol0Id == last[0]);

auto [hasDuplicates, graphInfo] = getGraphInfo(block);
// The blocks are written in parallel and possibly out of order. We thus
// can't set the proper block indices here. The proper block indices are set
// in the `getFinishedBlocks` function.
static constexpr size_t blockIndexNotYetSet = 111333555;
blockBuffer_.wlock()->push_back(
CompressedBlockMetadata{std::move(offsets),
numRows,
{first[0], first[1], first[2], first[3]},
{last[0], last[1], last[2], last[3]},
std::move(graphInfo),
hasDuplicates,
blockIndexNotYetSet});
blockBuffer_.wlock()->emplace_back(CompressedBlockMetadataNoBlockIndex{
std::move(offsets),
numRows,
{first[0], first[1], first[2], first[3]},
{last[0], last[1], last[2], last[3]},
std::move(graphInfo),
hasDuplicates});
if (invokeCallback && smallBlocksCallback_) {
std::invoke(smallBlocksCallback_, std::move(block));
}
Expand Down
32 changes: 20 additions & 12 deletions src/index/CompressedRelation.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct DecompressedBlockSizeGetter {
using CompressedBlock = std::vector<std::vector<char>>;

// The metadata of a compressed block of ID triples in an index permutation.
struct CompressedBlockMetadata {
struct CompressedBlockMetadataNoBlockIndex {
// Since we have column-based indices, the two columns of each block are
// stored separately (but adjacently).
struct OffsetAndCompressedSize {
Expand Down Expand Up @@ -104,13 +104,16 @@ struct CompressedBlockMetadata {
// blocks.
bool containsDuplicatesWithDifferentGraphs_;

// Two of these are equal if all members are equal.
bool operator==(const CompressedBlockMetadataNoBlockIndex&) const = default;
};

// The same as the above struct, but this block additionally knows its index.
struct CompressedBlockMetadata : CompressedBlockMetadataNoBlockIndex {
// The index of this block in the permutation. This is required to find
// the corresponding block from the `LocatedTriples` when only a subset of
// blocks is being used.
size_t blockIndex_;

// Two of these are equal if all members are equal.
bool operator==(const CompressedBlockMetadata&) const = default;
std::optional<size_t> blockIndex_;
};

// Serialization of the `OffsetAndcompressedSize` subclass.
Expand Down Expand Up @@ -174,7 +177,8 @@ AD_SERIALIZE_FUNCTION(CompressedRelationMetadata) {
class CompressedRelationWriter {
private:
ad_utility::Synchronized<ad_utility::File> outfile_;
ad_utility::Synchronized<std::vector<CompressedBlockMetadata>> blockBuffer_;
ad_utility::Synchronized<std::vector<CompressedBlockMetadataNoBlockIndex>>
blockBuffer_;
// If multiple small relations are stored in the same block, keep track of the
// first and last `col0Id`.
Id currentBlockFirstCol0_ = Id::makeUndefined();
Expand Down Expand Up @@ -260,15 +264,19 @@ class CompressedRelationWriter {
std::vector<CompressedBlockMetadata> getFinishedBlocks() && {
finish();
auto blocks = std::move(*(blockBuffer_.wlock()));
std::ranges::sort(blocks, {}, [](const CompressedBlockMetadata& bl) {
return std::tie(bl.firstTriple_.col0Id_, bl.firstTriple_.col1Id_,
bl.firstTriple_.col2Id_);
});
std::ranges::sort(
blocks, {}, [](const CompressedBlockMetadataNoBlockIndex& bl) {
return std::tie(bl.firstTriple_.col0Id_, bl.firstTriple_.col1Id_,
bl.firstTriple_.col2Id_);
});

std::vector<CompressedBlockMetadata> result;
result.reserve(blocks.size());
// Write the correct block indices
for (size_t i : ad_utility::integerRange(blocks.size())) {
blocks.at(i).blockIndex_ = i;
result.emplace_back(std::move(blocks.at(i)), i);
}
return blocks;
return result;
}

// Compute the multiplicity of given the number of elements and the number of
Expand Down

0 comments on commit 95bbbeb

Please sign in to comment.