Compare commits

...

1 Commits

Author SHA1 Message Date
Andi Skrgat
12eb3686ef Move semantic for vertices iterable 2023-05-08 13:42:48 +02:00
8 changed files with 24 additions and 14 deletions

View File

@@ -122,6 +122,7 @@ class VertexAccessor final {
// It can affect performance if we use std::unique_ptr here.
std::unique_ptr<storage::VertexAccessor> impl_;
explicit VertexAccessor(storage::VertexAccessor *impl) : impl_(impl) {}
explicit VertexAccessor(std::unique_ptr<storage::VertexAccessor> impl) : impl_(std::move(impl)) {}
VertexAccessor(const VertexAccessor &impl) : impl_(impl.impl_->Copy()){};
explicit VertexAccessor(VertexAccessor *impl) : VertexAccessor(*impl) {}
@@ -294,7 +295,8 @@ class VerticesIterable final {
VertexAccessor operator*() const {
return std::visit(
memgraph::utils::Overloaded{
[](storage::VerticesIterable::Iterator it_) { return VertexAccessor((*it_)->Copy()); },
[](storage::VerticesIterable::Iterator it_) { return VertexAccessor(*it_); },
// [](storage::VerticesIterable::Iterator it_) { return VertexAccessor(*it_); },
[](std::unordered_set<VertexAccessor, std::hash<VertexAccessor>, std::equal_to<void>,
utils::Allocator<VertexAccessor>>::iterator it_) { return VertexAccessor(*it_); }},
it_);

View File

@@ -331,6 +331,10 @@ LabelIndex::Iterable::Iterator::Iterator(Iterable *self, utils::SkipList<Entry>:
AdvanceUntilValid();
}
std::unique_ptr<VertexAccessor> LabelIndex::Iterable::Iterator::operator*() {
return std::move(current_vertex_accessor_);
}
LabelIndex::Iterable::Iterator &LabelIndex::Iterable::Iterator::operator++() {
++index_iterator_;
AdvanceUntilValid();
@@ -484,6 +488,10 @@ LabelPropertyIndex::Iterable::Iterator::Iterator(Iterable *self, utils::SkipList
AdvanceUntilValid();
}
std::unique_ptr<VertexAccessor> LabelPropertyIndex::Iterable::Iterator::operator*() {
return std::move(current_vertex_accessor_);
}
LabelPropertyIndex::Iterable::Iterator &LabelPropertyIndex::Iterable::Iterator::operator++() {
++index_iterator_;
AdvanceUntilValid();

View File

@@ -86,7 +86,7 @@ class LabelIndex {
Iterator(Iterator &&other) = default;
~Iterator() = default;
VertexAccessor *operator*() const { return current_vertex_accessor_.get(); }
std::unique_ptr<VertexAccessor> operator*();
bool operator==(const Iterator &other) const { return index_iterator_ == other.index_iterator_; }
bool operator!=(const Iterator &other) const { return index_iterator_ != other.index_iterator_; }
@@ -197,7 +197,7 @@ class LabelPropertyIndex {
Iterator(Iterator &&other) = default;
~Iterator() = default;
VertexAccessor *operator*() const { return current_vertex_accessor_.get(); }
std::unique_ptr<VertexAccessor> operator*();
bool operator==(const Iterator &other) const { return index_iterator_ == other.index_iterator_; }
bool operator!=(const Iterator &other) const { return index_iterator_ != other.index_iterator_; }

View File

@@ -40,7 +40,7 @@ AllVerticesIterable::Iterator::Iterator(AllVerticesIterable *self, utils::SkipLi
it_(AdvanceToVisibleVertex(it, self->vertices_accessor_.end(), self->vertex_, self->transaction_, self->view_,
self->indices_, self_->constraints_, self->config_)) {}
VertexAccessor *AllVerticesIterable::Iterator::operator*() const { return self_->vertex_.get(); }
std::unique_ptr<VertexAccessor> AllVerticesIterable::Iterator::operator*() const { return std::move(self_->vertex_); }
AllVerticesIterable::Iterator &AllVerticesIterable::Iterator::operator++() {
++it_;
@@ -228,7 +228,7 @@ void VerticesIterable::Iterator::Destroy() noexcept {
}
}
VertexAccessor *VerticesIterable::Iterator::operator*() const {
std::unique_ptr<VertexAccessor> VerticesIterable::Iterator::operator*() {
switch (type_) {
case Type::ALL:
return *all_it_;

View File

@@ -58,7 +58,7 @@ class AllVerticesIterable final {
public:
Iterator(AllVerticesIterable *self, utils::SkipList<Vertex>::Iterator it);
VertexAccessor *operator*() const;
std::unique_ptr<VertexAccessor> operator*() const;
Iterator &operator++();
@@ -130,7 +130,7 @@ class VerticesIterable final {
~Iterator();
VertexAccessor *operator*() const;
std::unique_ptr<VertexAccessor> operator*();
Iterator &operator++();

View File

@@ -87,7 +87,7 @@ TEST_F(ConstraintsTest, ExistenceConstraintsCreateFailure1) {
{
auto acc = storage->Access();
for (auto vertex : acc->Vertices(View::OLD)) {
ASSERT_NO_ERROR(acc->DeleteVertex(vertex));
ASSERT_NO_ERROR(acc->DeleteVertex(vertex.get()));
}
ASSERT_NO_ERROR(acc->Commit());
}
@@ -168,7 +168,7 @@ TEST_F(ConstraintsTest, ExistenceConstraintsViolationOnCommit) {
ASSERT_NO_ERROR(vertex->SetProperty(prop1, PropertyValue()));
}
for (auto vertex : acc->Vertices(View::OLD)) {
ASSERT_NO_ERROR(acc->DeleteVertex(vertex));
ASSERT_NO_ERROR(acc->DeleteVertex(vertex.get()));
}
ASSERT_NO_ERROR(acc->Commit());
@@ -247,7 +247,7 @@ TEST_F(ConstraintsTest, UniqueConstraintsCreateFailure1) {
{
auto acc = storage->Access();
for (auto vertex : acc->Vertices(View::OLD)) {
ASSERT_NO_ERROR(acc->DeleteVertex(vertex));
ASSERT_NO_ERROR(acc->DeleteVertex(vertex.get()));
}
ASSERT_NO_ERROR(acc->Commit());
}

View File

@@ -1455,7 +1455,7 @@ TEST_P(DurabilityTest, WalCreateAndRemoveEverything) {
}
auto acc = store->Access();
for (auto vertex : acc->Vertices(memgraph::storage::View::OLD)) {
ASSERT_TRUE(acc->DetachDeleteVertex(vertex).HasValue());
ASSERT_TRUE(acc->DetachDeleteVertex(vertex.get()).HasValue());
}
ASSERT_FALSE(acc->Commit().HasError());
}
@@ -1646,7 +1646,7 @@ TEST_P(DurabilityTest, WalCreateAndRemoveOnlyBaseDataset) {
ASSERT_TRUE(has_indexed.HasValue());
auto has_unindexed = vertex->HasLabel(label_unindexed, memgraph::storage::View::OLD);
if (!*has_indexed && !*has_unindexed) continue;
ASSERT_TRUE(acc->DetachDeleteVertex(vertex).HasValue());
ASSERT_TRUE(acc->DetachDeleteVertex(vertex.get()).HasValue());
}
ASSERT_FALSE(acc->Commit().HasError());
}

View File

@@ -270,7 +270,7 @@ TEST_F(IndexTest, LabelIndexBasic) {
for (auto vertex : acc->Vertices(View::OLD)) {
int64_t id = vertex->GetProperty(prop_id, View::OLD)->ValueInt();
if (id % 2 == 0) {
ASSERT_NO_ERROR(acc->DeleteVertex(vertex));
ASSERT_NO_ERROR(acc->DeleteVertex(vertex.get()));
}
}
@@ -457,7 +457,7 @@ TEST_F(IndexTest, LabelPropertyIndexBasic) {
for (auto vertex : acc->Vertices(View::OLD)) {
int64_t id = vertex->GetProperty(prop_id, View::OLD)->ValueInt();
if (id % 2 == 0) {
ASSERT_NO_ERROR(acc->DeleteVertex(vertex));
ASSERT_NO_ERROR(acc->DeleteVertex(vertex.get()));
}
}