Skip to content

Commit

Permalink
Minor changes + TODOs, Johannes's turn next
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannah Bast committed Oct 21, 2024
1 parent 7e2661b commit 6f6641f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/global/IdTriple.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

template <size_t N = 0>
struct IdTriple {
// The triples have actually 4 columns because of the Graph ID.
// A triple has four components: subject, predicate, object, and graph.
static constexpr size_t NumCols = 4;
// The three IDs that define the triple.
std::array<Id, NumCols> ids_;
Expand All @@ -36,7 +36,7 @@ struct IdTriple {
return os;
}

// TODO: default once we drop clang16 with libc++16
// TODO: use `= default` once we drop Clang 16 with `libc++16`.
std::strong_ordering operator<=>(const IdTriple& other) const {
static_assert(NumCols == 4);
return std::tie(ids_[0], ids_[1], ids_[2], ids_[3]) <=>
Expand Down
6 changes: 3 additions & 3 deletions src/index/CompressedRelation.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2021, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Author: Johannes Kalmbach ([email protected])
// Copyright 2021 - 2024, University of Freiburg
// Chair of Algorithms and Data Structures
// Author: Johannes Kalmbach <[email protected]>

#include "CompressedRelation.h"

Expand Down
11 changes: 10 additions & 1 deletion src/index/LocatedTriples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,16 @@ IdTable LocatedTriplesPerBlock::mergeTriplesImpl(size_t blockIndex,
auto locatedTripleIt = locatedTriples.begin();
auto resultIt = result.begin();

auto writeTripleToResult = [&result, &resultIt](auto& locatedTriple) {
// Write the given `locatedTriple` to `result` at position `resultIt` and
// advance.
auto writeTripleToResult = [&result, &resultIt](auto &locatedTriple) {
// Write part from `locatedTriple` that also occurs in the input `block` to
// the result.
//
// TODO: According to `mergeTriples`, `numIndexColumns` can also be 4.
// However, this would crash with the following code, as `ids_[3 -
// numIndexColumns + i]` would access `ids_[-1]`. Either `numIndexColumns`
// cannot be 4 or the following code needs to be adjusted.
for (size_t i = 0; i < numIndexColumns; i++) {
(*resultIt)[i] = locatedTriple.triple_.ids_[3 - numIndexColumns + i];
}
Expand Down
39 changes: 20 additions & 19 deletions src/index/LocatedTriples.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ struct NumAddedAndDeleted {
bool operator<=>(const NumAddedAndDeleted&) const = default;
};

// A triple and its block in a particular permutation.
// For a detailed definition of all border cases, see the definition at
// the end of this file.
// A triple and its block in a particular permutation. For a detailed definition
// of all border cases, see the definition at the end of this file.
struct LocatedTriple {
// The index of the block, according to the definition above.
size_t blockIndex_;
// The `Id`s of the triple in the order of the permutation. For example,
// for an object pertaining to the OPS permutation: `id1` is the object,
// `id2` is the predicate, and `id3` is the subject.
// for an object pertaining to the OPS permutation: `triple_[0]` is the
// object, `triple_[1]` is the predicate, `triple_[2]` is the subject,
// and `triple_[3]` is the graph.
IdTriple<0> triple_;

// Flag that is true if the given triple is inserted and false if it
Expand Down Expand Up @@ -81,7 +81,8 @@ class LocatedTriplesPerBlock {

FRIEND_TEST(LocatedTriplesTest, numTriplesInBlock);

// Impl function to `mergeTriples`.
// Implementation of the `mergeTriples` function (which has `numIndexColumns`
// as a normal argument, and translates it into a template argument).
template <size_t numIndexColumns>
IdTable mergeTriplesImpl(size_t blockIndex, const IdTable& block) const;

Expand All @@ -104,21 +105,21 @@ class LocatedTriplesPerBlock {
// `blockIndex`.
bool hasUpdates(size_t blockIndex) const;

// Merge located triples for `blockIndex_` with the given index `block` and
// write to `result`, starting from position `offsetInResult`. Return the
// number of rows written to `result`.
// Merge located triples for `blockIndex_` (there must be at least one,
// otherwise this function should not be called) with the given input `block`.
// Return the result as an `IdTable`. The result has the same number of
// columns as `block`.
//
// PRECONDITIONS:
//
// 1. `mergeTriples` must always be called with all the index columns in the
// input. So the column indices must be `{0, 1, 2, ...}`.
//
// 2. It is the responsibility of the caller that there is enough space for
// the result of the merge in `result` starting from `offsetInResult`.
// TODO: Adjust the following paragraph after Johannes' changes.
//
// 3. The set of located triples for `blockIndex_` must be non-empty.
// Otherwise, there is no need for merging and this method shouldn't be
// called for efficiency reasons.
// `numIndexColumns` is the number of columns in `block` except payload, that
// is, a number from `{1, 2, 3, 4}`. If `block` has payload columns, the
// value of the merged located triples for these columns is set to UNDEF
// (becuse our located triples currently don't have a payload). For example,

Check failure on line 118 in src/index/LocatedTriples.h

View workflow job for this annotation

GitHub Actions / Check for spelling errors

becuse ==> because
// assume that `block` is from the POSG permutation and has the columns OSG
// and two additional payload columns X and Y, so five columns in total. Then
// `numIndexColumns` is 3 (because only OSG are present in the block), and a
// located tripe in the result would be of the form OSGUU, where U is UNDEF.
IdTable mergeTriples(size_t blockIndex, const IdTable& block,
size_t numIndexColumns) const;

Expand Down
2 changes: 1 addition & 1 deletion test/LocatedTriplesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ TEST_F(LocatedTriplesTest, mergeTriples) {
EXPECT_THAT(merged, testing::ElementsAreArray(resultExpected));
}

// Merge the `LocatesTriples` into a block with 1 index columns.
// Merge the `LocatesTriples` into a block with 1 index column.
{
IdTable block = makeIdTableFromVector({
{10}, // Row 0
Expand Down

0 comments on commit 6f6641f

Please sign in to comment.