From 6f6641f1dbcf70b23ab515ca8862bdd9e350be8a Mon Sep 17 00:00:00 2001 From: Hannah Bast Date: Mon, 21 Oct 2024 20:30:36 +0200 Subject: [PATCH] Minor changes + TODOs, Johannes's turn next --- src/global/IdTriple.h | 4 ++-- src/index/CompressedRelation.cpp | 6 ++--- src/index/LocatedTriples.cpp | 11 ++++++++- src/index/LocatedTriples.h | 39 ++++++++++++++++---------------- test/LocatedTriplesTest.cpp | 2 +- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/global/IdTriple.h b/src/global/IdTriple.h index 54dd7ee61..b349743f9 100644 --- a/src/global/IdTriple.h +++ b/src/global/IdTriple.h @@ -14,7 +14,7 @@ template 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 ids_; @@ -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]) <=> diff --git a/src/index/CompressedRelation.cpp b/src/index/CompressedRelation.cpp index 087a71edb..60a7aa1c9 100644 --- a/src/index/CompressedRelation.cpp +++ b/src/index/CompressedRelation.cpp @@ -1,6 +1,6 @@ -// Copyright 2021, University of Freiburg, -// Chair of Algorithms and Data Structures. -// Author: Johannes Kalmbach (kalmbach@cs.uni-freiburg.de) +// Copyright 2021 - 2024, University of Freiburg +// Chair of Algorithms and Data Structures +// Author: Johannes Kalmbach #include "CompressedRelation.h" diff --git a/src/index/LocatedTriples.cpp b/src/index/LocatedTriples.cpp index 1898c1b49..783fa70ad 100644 --- a/src/index/LocatedTriples.cpp +++ b/src/index/LocatedTriples.cpp @@ -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]; } diff --git a/src/index/LocatedTriples.h b/src/index/LocatedTriples.h index a254bd87b..cb725b56d 100644 --- a/src/index/LocatedTriples.h +++ b/src/index/LocatedTriples.h @@ -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 @@ -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 IdTable mergeTriplesImpl(size_t blockIndex, const IdTable& block) const; @@ -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, + // 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; diff --git a/test/LocatedTriplesTest.cpp b/test/LocatedTriplesTest.cpp index be3644819..ed080ff88 100644 --- a/test/LocatedTriplesTest.cpp +++ b/test/LocatedTriplesTest.cpp @@ -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