diff --git a/CMakeLists.txt b/CMakeLists.txt index 37c2a2e74..c2d91e246 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -454,8 +454,6 @@ set(memgraph_src_files ${src_dir}/storage/record_accessor.cpp ) -set(barrier_src_files - ${src_dir}/barrier/barrier.cpp) # STATIC library used by memgraph executables add_library(memgraph STATIC ${memgraph_src_files}) @@ -464,7 +462,6 @@ add_library(memgraph STATIC ${memgraph_src_files}) add_library(memgraph_pic STATIC ${memgraph_src_files}) set_property(TARGET memgraph_pic PROPERTY POSITION_INDEPENDENT_CODE TRUE) -add_library(barrier STATIC ${barrier_src_files}) # tests if (TESTS) diff --git a/include/barrier/barrier.hpp b/include/barrier/barrier.hpp index e66676b30..d8c088db4 100644 --- a/include/barrier/barrier.hpp +++ b/include/barrier/barrier.hpp @@ -14,44 +14,47 @@ namespace barrier // barrier class defined here. // ************ Here should be forward declarations of Sized barrier classes -class DbAccessor; // DONE // .cpp +// ACCESSORS +class DbAccessor; +class VertexAccessor; +class EdgeAccessor; -class VertexAccessor; // DONE // .cpp -class EdgeAccessor; // DONE // .cpp +// GENERIC ITERATORS +class VertexIterator; +class EdgeIterator; -class VertexIterator; // DONE // .cpp -class EdgeIterator; // DONE // .cpp - -class VertexAccessIterator; // DONE // .cpp -class OutEdgesIterator; // DONE // .cpp -class InEdgesIterator; // DONE // .cpp - -class VertexPropertyKey; // DONE // .cpp -class EdgePropertyKey; // DONE // .cpp +// TYPED ITERATORS +class VertexAccessIterator; +class OutEdgesIterator; +class InEdgesIterator; +// PROPERTY +class VertexPropertyKey; +class EdgePropertyKey; template -class VertexPropertyType; // DONE // .cpp - +class VertexPropertyType; template -class EdgePropertyType; // DONE // .cpp +class EdgePropertyType; +// BOLT template -class BoltSerializer; // DONE // .cpp +class BoltSerializer; // ************ Here should be forward declarations of Unsized barrier classes -class Label; // DONE // .cpp -class EdgeType; // DONE // .cpp - -class Db; // DONE // .cpp - -class VertexPropertyFamily; // DONE // .cpp -class EdgePropertyFamily; // DONE // .cpp +// COMMON +class Db; +class Label; +class EdgeType; +// GENERIC INDEXES template -class VertexIndex; // DONE // .cpp - +class VertexIndex; template -class EdgeIndex; // DONE // .cpp +class EdgeIndex; + +// PROPERTY +class VertexPropertyFamily; +class EdgePropertyFamily; // ************* Here should be defined usings using label_ref_t = ReferenceWrapper; @@ -64,7 +67,6 @@ using label_ref_t = ReferenceWrapper; // class class_name: Sized // --Sized template arguments must be hardcoded numbers equal to sizeof(T) and // alignof(T) where T is original class. -// --It should have friends barrier classes which are permitted to construct it. // --It should have undefined public constructor which is specialized in .cpp // Blueprint: // public: @@ -78,28 +80,11 @@ using label_ref_t = ReferenceWrapper; // class_name &operator=(const class_name &other); // class_name &operator=(class_name &&other); // --It should specify public methods which can be called on the original class. -// An example of such Sized barrier class: -// -// class Accessor : private Sized<16, 8> -// { -// public:// -// template -// Accessor(T &&d); -// -// Accessor(const Accessor &other); -// Accessor(Accessor &&other); -// ~Accessor(); -// -// Accessor &operator=(const Accessor &other); -// Accessor &operator=(Accessor &&other); -// -// int get_prop(Name &name); -// }; // // Blueprint: // class class_name : private Sized<,> // { -// public:// +// public: // template // class_name(T &&d); // @@ -476,14 +461,6 @@ public: // --Inherit Unsized class from common.hpp as protected. Blueprint: // class class_name: protected Unsized // --It should specify public methods which can be called on the original class. -// An example of such Unsized barrier class: -// -// class Db : protected Unsized -// { -// public: -// Accessor access(); -// Name &get_name(const char *str); -// }; // // Blueprint: // class class_name : protected Unsized diff --git a/include/barrier/trans.hpp b/include/barrier/trans.hpp index 9caa9e202..44bba845a 100644 --- a/include/barrier/trans.hpp +++ b/include/barrier/trans.hpp @@ -8,21 +8,10 @@ #include "storage/edge_type/edge_type.hpp" #include "storage/label/label.hpp" -// This is the place for imports from memgraph .cpp -// #include "database/db_accessor.cpp" -#include "storage/vertex_accessor.cpp" - -// TODO: Extract trans functions to other hpp for easy including into other -// code. - // **************************** HELPER DEFINES *******************************// -// returns transformed pointer -#define THIS (trans(this)) -// Performs call x on transformed border class. -#define HALF_CALL(x) (THIS->x) -// Performs call x on transformed border class and returns transformed output. -#define CALL(x) trans(HALF_CALL(x)) - +// Creates 8 functions for transformation of refereces between types x and y. +// Where x is a border type. +// DANGEROUS #define TRANSFORM_REF(x, y) \ x &trans(y &l) { return ref_as(l); } \ x const &trans(y const &l) { return ref_as(l); } \ @@ -33,6 +22,9 @@ y *trans(x *l) { return ptr_as(l); } \ y const *trans(x const *l) { return ptr_as(l); } +// Creates 8 functions for transformation of refereces between types x and y. +// Where both x and y are templates over T. Where x is a border type. +// DANGEROUS #define TRANSFORM_REF_TEMPLATED(x, y) \ x &trans(y &l) { return ref_as(l); } \ template \ @@ -70,71 +62,60 @@ { \ return ptr_as(l); \ } -#define DESTRUCTOR(x, y) \ - x::~x() { HALF_CALL(~y()); } -#define COPY_CONSTRUCTOR_MUT(x, y) \ - x::x(x &other) : Sized(y(trans(other))) {} -#define COPY_CONSTRUCTOR(x, y) \ - x::x(const x &other) : Sized(y(trans(other))) {} -#define MOVE_CONSTRUCTOR(x) \ - x::x(x &&other) : Sized(trans(std::move(other))) {} -#define MOVE_CONST_CONSTRUCTOR(x) \ - x::x(x const &&other) : Sized(trans(std::move(other))) {} // For certain classes trans evaluates into ref which doesnt work for Sized -// constructor. This Move forces type. +// constructor. This Move forces type y. +// DANGEROUS #define MOVE_CONSTRUCTOR_FORCED(x, y) \ x::x(x &&other) : Sized(value_as(std::move(other))) {} -#define COPY_OPERATOR(x) \ - x &x::operator=(const x &other) \ - { \ - HALF_CALL(operator=(trans(other))); \ - return *this; \ - } -#define MOVE_OPERATOR(x) \ - x &x::operator=(x &&other) \ - { \ - HALF_CALL(operator=(trans(std::move(other)))); \ - return *this; \ - } - +// Creates constructor x(y) where x is border type and y shpuld be his original +// type. +// DANGEROUS #define VALID_CONSTRUCTION(x, y) \ template <> \ barrier::x::x(y &&d) : Sized(std::move(d)) \ { \ } +// Creates const constructor x(y) where x is border type and y shpuld be his +// original type. +// DANGEROUS #define VALID_CONSTRUCTION_CONST(x, y) \ template <> \ barrier::x::x(y const &&d) : Sized(std::move(d)) \ { \ } -// Generates transformation function from original class to border class. +// Creates value transformation function from original type y to border type x. +// DANGEROUS #define TRANSFORM_VALUE_ONE_RAW(x, y) \ x trans(y &&d) { return x(std::move(d)); } -// Generates transformation function from original class to border class. +// Creates value transformation function and constructor from original type y to +// border type x. +// DANGEROUS #define TRANSFORM_VALUE_ONE(x, y) \ VALID_CONSTRUCTION(x, y) \ x trans(y &&d) { return x(std::move(d)); } -// Generates transformation functions between border class x and original class -// y by value. Only mutable values. +// Creates value transformation functions and constructor between border type x +// and original type y. Only mutable values. +// DANGEROUS #define TRANSFORM_VALUE_MUT(x, y) \ TRANSFORM_VALUE_ONE(x, y) \ y trans(x &&d) { return value_as(std::move(d)); } -// Generates transformation functions between border class x and original class -// y by value. +// Creates value transformation functions and constructors between border type x +// and original type y. +// DANGEROUS #define TRANSFORM_VALUE(x, y) \ TRANSFORM_VALUE_MUT(x, y) \ VALID_CONSTRUCTION_CONST(x, y) \ const x trans(const y &&d) { return x(std::move(d)); } \ const y trans(const x &&d) { return value_as(std::move(d)); } -// Duplicates given first name to call second given with name and ::name +// Duplicates given x to call y with x and ::x #define DUP(x, y) y(x, ::x) // ********************** TYPES OF AUTO @@ -147,17 +128,6 @@ using out_edge_iterator_t = using in_edge_iterator_t = decltype(((::VertexAccessor *)(std::nullptr_t()))->in()); -// This file should contain all implementations of methods from barrier classes -// defined in barrier.hpp. -// Implementations should follow the form: -// border_return_type border_class::method_name(arguments){ -// return -// CALL(method_name(trans(arguments)))/HALF_CALL(method_name(trans(arguments))); -// } - -// ********************** ALL VALID CONVERSIONS ***************************** // -// Implementations must use exclusivly trans functions to cast between types. - // ******************** OVERLOADED trans FUNCTIONS. // This enclosure is the only dangerous part of barrier except of Sized class in // common.hpp @@ -240,7 +210,7 @@ TRANSFORM_VALUE_ONE_RAW(EdgePropertyType, template TRANSFORM_VALUE_ONE_RAW(BoltSerializer, ::bolt::BoltSerializer) -// ********************* SPECIAL SIZED CONSTRUCTORS +// ********************* SPECIAL CONSTRUCTORS #define VertexPropertyType_constructor(x) \ template <> \ template <> \ diff --git a/include/communication/bolt/v1/serialization/bolt_serializer.hpp b/include/communication/bolt/v1/serialization/bolt_serializer.hpp index 12859de83..0f8ee6b2e 100644 --- a/include/communication/bolt/v1/serialization/bolt_serializer.hpp +++ b/include/communication/bolt/v1/serialization/bolt_serializer.hpp @@ -4,6 +4,7 @@ #include "communication/bolt/v1/transport/bolt_encoder.hpp" #include "storage/edge_accessor.hpp" +#include "storage/edge_x_vertex.hpp" #include "storage/vertex_accessor.hpp" #include "storage/model/properties/all.hpp" diff --git a/include/storage/edge_accessor.hpp b/include/storage/edge_accessor.hpp index 92bd1270d..2070e5dec 100644 --- a/include/storage/edge_accessor.hpp +++ b/include/storage/edge_accessor.hpp @@ -3,7 +3,6 @@ #include "storage/edge.hpp" #include "storage/edge_record.hpp" #include "storage/record_accessor.hpp" -#include "storage/vertex_accessor.hpp" #include "utils/assert.hpp" #include "utils/reference_wrapper.hpp" @@ -12,6 +11,7 @@ using edge_type_ref_t = ReferenceWrapper; class Edges; +// There exists circular dependecy with VertexAccessor. class EdgeAccessor : public RecordAccessor { public: @@ -23,7 +23,7 @@ public: const EdgeType &edge_type() const; - const VertexAccessor from() const; + const auto from() const; - const VertexAccessor to() const; + const auto to() const; }; diff --git a/include/storage/edge_x_vertex.hpp b/include/storage/edge_x_vertex.hpp new file mode 100644 index 000000000..f364ec0c4 --- /dev/null +++ b/include/storage/edge_x_vertex.hpp @@ -0,0 +1,30 @@ +#pragma once + +// There exists circular dependecy with EdgeAccessor. This file serves to break +// that circularity. +#include "storage/edge_accessor.hpp" +#include "storage/vertex_accessor.hpp" + +const auto EdgeAccessor::from() const +{ + return VertexAccessor(this->vlist->from(), this->db); +} + +const auto EdgeAccessor::to() const +{ + return VertexAccessor(this->vlist->to(), this->db); +} + +auto VertexAccessor::out() const +{ + DbTransaction &t = this->db; + return iter::make_map(iter::make_iter_ref(record->data.out), + [&](auto e) -> auto { return EdgeAccessor(*e, t); }); +} + +auto VertexAccessor::in() const +{ + DbTransaction &t = this->db; + return iter::make_map(iter::make_iter_ref(record->data.in), + [&](auto e) -> auto { return EdgeAccessor(e, t); }); +} diff --git a/include/storage/vertex_accessor.hpp b/include/storage/vertex_accessor.hpp index 2bfd693b4..4927117e3 100644 --- a/include/storage/vertex_accessor.hpp +++ b/include/storage/vertex_accessor.hpp @@ -1,12 +1,12 @@ #pragma once -// #include "storage/edge_accessor.hpp" #include "storage/record_accessor.hpp" #include "storage/vertex.hpp" -// #include "utils/iterator/iterator.hpp" +#include "utils/iterator/iterator.hpp" class Vertices; +// There exists circular dependecy with EdgeAccessor. class VertexAccessor : public RecordAccessor { public: diff --git a/poc/CMakeLists.txt b/poc/CMakeLists.txt index ca14301e7..6a4ad8add 100644 --- a/poc/CMakeLists.txt +++ b/poc/CMakeLists.txt @@ -2,8 +2,10 @@ cmake_minimum_required(VERSION 3.1) project(memgraph_poc) + include_directories(${CMAKE_SOURCE_DIR}/poc) + add_executable(poc_astar astar.cpp) target_link_libraries(poc_astar memgraph) target_link_libraries(poc_astar Threads::Threads) @@ -11,16 +13,15 @@ target_link_libraries(poc_astar ${fmt_static_lib}) add_executable(profile profile.cpp) target_link_libraries(profile memgraph) -target_link_libraries(profile barrier) target_link_libraries(profile Threads::Threads) target_link_libraries(profile ${fmt_static_lib}) - - -add_executable(isolation isolation.cpp isolation/header.cpp) -target_link_libraries(isolation ${fmt_static_lib}) - add_executable(size_aligment size_aligment.cpp) target_link_libraries(size_aligment memgraph) target_link_libraries(size_aligment Threads::Threads) target_link_libraries(size_aligment ${fmt_static_lib}) + + + +add_executable(isolation isolation.cpp isolation/header.cpp) +target_link_libraries(isolation ${fmt_static_lib}) diff --git a/poc/astar.cpp b/poc/astar.cpp index 6a87a638b..0655294c3 100644 --- a/poc/astar.cpp +++ b/poc/astar.cpp @@ -14,12 +14,13 @@ #include "database/db_accessor.cpp" #include "database/db_accessor.hpp" #include "import/csv_import.hpp" +#include "storage/edge_x_vertex.hpp" #include "storage/edges.cpp" #include "storage/edges.hpp" #include "storage/indexes/impl/nonunique_unordered_index.cpp" #include "storage/model/properties/properties.cpp" #include "storage/record_accessor.cpp" -#include "storage/vertex_accessor.cpp" +// #include "storage/vertex_accessor.cpp" #include "storage/vertex_accessor.hpp" #include "storage/vertices.cpp" #include "storage/vertices.hpp" diff --git a/poc/profile.cpp b/poc/profile.cpp index 90a6a3bd5..4faecf66f 100644 --- a/poc/profile.cpp +++ b/poc/profile.cpp @@ -11,15 +11,8 @@ #include #include #include "import/csv_import.hpp" -// #include "storage/indexes/impl/nonunique_unordered_index.cpp" -// #include "storage/model/properties/properties.cpp" -// #include "storage/record_accessor.cpp" -// #include "storage/vertex_accessor.cpp" #include "utils/command_line/arguments.hpp" -// #include "barrier/trans.hpp" -// #include "barrier/barrier.cpp" - using namespace std; int main(int argc, char **argv) diff --git a/poc/size_aligment.cpp b/poc/size_aligment.cpp index 4593c9105..fd65a6eff 100644 --- a/poc/size_aligment.cpp +++ b/poc/size_aligment.cpp @@ -8,10 +8,11 @@ #include #include "database/db_accessor.cpp" #include "import/csv_import.hpp" +#include "storage/edge_x_vertex.hpp" #include "storage/indexes/impl/nonunique_unordered_index.cpp" #include "storage/model/properties/properties.cpp" -#include "storage/record_accessor.cpp" -#include "storage/vertex_accessor.cpp" +// #include "storage/record_accessor.cpp" +// #include "storage/vertex_accessor.cpp" #include "utils/command_line/arguments.hpp" using namespace std; diff --git a/src/barrier/barrier.cpp b/src/barrier/barrier.cpp index ce9b99d39..dfb3e9513 100644 --- a/src/barrier/barrier.cpp +++ b/src/barrier/barrier.cpp @@ -2,6 +2,60 @@ #include "barrier/trans.hpp" // ************************* Implementations +// This file should contain all implementations of methods from barrier classes +// defined in barrier.hpp. +// Implementations should follow the form: +// border_return_type border_class::method_name(arguments){ +// return +// CALL(method_name(trans(arguments)))/HALF_CALL(method_name(trans(arguments))); +// } + +// **************************** HELPER DEFINES *******************************// +// returns transformed pointer +#define THIS (trans(this)) +// Performs call x on transformed border class. +#define HALF_CALL(x) (THIS->x) +// Performs call x on transformed border class and returns transformed output. +#define CALL(x) trans(HALF_CALL(x)) + +// Creates destructor for border type x which is original type y. +#define DESTRUCTOR(x, y) \ + x::~x() { HALF_CALL(~y()); } + +// Creates copy constructor for mutable ref to border class x which is original +// class y. +#define COPY_CONSTRUCTOR_MUT(x, y) \ + x::x(x &other) : Sized(y(trans(other))) {} + +// Creates copy constructor for const ref to border class x which is original +// class y. +#define COPY_CONSTRUCTOR(x, y) \ + x::x(const x &other) : Sized(y(trans(other))) {} + +// Creates move constructor for mutable border type x. +#define MOVE_CONSTRUCTOR(x) \ + x::x(x &&other) : Sized(trans(std::move(other))) {} + +// Creates move constructor for const border type x. +#define MOVE_CONST_CONSTRUCTOR(x) \ + x::x(x const &&other) : Sized(trans(std::move(other))) {} + +// Creates copy operator for border type x. +#define COPY_OPERATOR(x) \ + x &x::operator=(const x &other) \ + { \ + HALF_CALL(operator=(trans(other))); \ + return *this; \ + } + +// Creates move operator for border type x. +#define MOVE_OPERATOR(x) \ + x &x::operator=(x &&other) \ + { \ + HALF_CALL(operator=(trans(std::move(other)))); \ + return *this; \ + } + namespace barrier { @@ -549,9 +603,4 @@ const>(barrier::VertexAccessor const&&)' description: Move constructor VertexAccessor(VertexAccessor const&&) isn't defined. - - - - - */ diff --git a/src/database/db_accessor.cpp b/src/database/db_accessor.cpp index 1ae6c628a..36c572724 100644 --- a/src/database/db_accessor.cpp +++ b/src/database/db_accessor.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "database/db.hpp" #include "database/db_accessor.hpp" #include "utils/iterator/iterator.hpp" diff --git a/src/storage/edge_accessor.cpp b/src/storage/edge_accessor.cpp index b1b175837..5bbd2f823 100644 --- a/src/storage/edge_accessor.cpp +++ b/src/storage/edge_accessor.cpp @@ -10,13 +10,3 @@ const EdgeType &EdgeAccessor::edge_type() const runtime_assert(this->record->data.edge_type != nullptr, "EdgeType is null"); return *this->record->data.edge_type; } - -const VertexAccessor EdgeAccessor::from() const -{ - return VertexAccessor(this->vlist->from(), this->db); -} - -const VertexAccessor EdgeAccessor::to() const -{ - return VertexAccessor(this->vlist->to(), this->db); -} diff --git a/src/storage/vertex_accessor.cpp b/src/storage/vertex_accessor.cpp index 6fcd32fc8..83795ec0c 100644 --- a/src/storage/vertex_accessor.cpp +++ b/src/storage/vertex_accessor.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "storage/vertex_accessor.hpp" #include "database/db.hpp" @@ -41,22 +39,6 @@ const std::vector &VertexAccessor::labels() const return this->record->data.labels(); } -// Returns unfilled accessors -auto VertexAccessor::out() const -{ - DbTransaction &t = this->db; - return iter::make_map(iter::make_iter_ref(record->data.out), - [&](auto e) -> auto { return EdgeAccessor(*e, t); }); -} - -// Returns unfilled accessors -auto VertexAccessor::in() const -{ - DbTransaction &t = this->db; - return iter::make_map(iter::make_iter_ref(record->data.in), - [&](auto e) -> auto { return EdgeAccessor(e, t); }); -} - bool VertexAccessor::in_contains(VertexAccessor const &other) const { return record->data.in.contains(other.vlist);