diff --git a/mvcc/mvcc.hpp b/mvcc/record.hpp similarity index 100% rename from mvcc/mvcc.hpp rename to mvcc/record.hpp diff --git a/storage/edge.hpp b/storage/edge.hpp index 535be028e..24311c3aa 100644 --- a/storage/edge.hpp +++ b/storage/edge.hpp @@ -1,16 +1,23 @@ -#ifndef MEMGRAPH_STORAGE_EDGE_HPP -#define MEMGRAPH_STORAGE_EDGE_HPP +#pragma once -#include +#include "model/properties/jsonwriter.hpp" +#include "model/edge_model.hpp" +#include "mvcc/record.hpp" -#include "model/record.hpp" +class Edge; -struct Vertex; - -struct Edge : public Record +class Edge : public mvcc::Record { - Vertex* from; - Vertex* to; -}; +public: + Edge() = default; + Edge(const EdgeModel& data) : data(data) {} + Edge(EdgeModel&& data) : data(std::move(data)) {} -#endif + Edge(const Edge&) = delete; + Edge(Edge&&) = delete; + + Edge& operator=(const Edge&) = delete; + Edge& operator=(Edge&&) = delete; + + EdgeModel data; +}; diff --git a/storage/model/edge_list.hpp b/storage/model/edge_list.hpp new file mode 100644 index 000000000..fccafa7b4 --- /dev/null +++ b/storage/model/edge_list.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include +#include "mvcc/version_list.hpp" + +class EdgeList +{ +public: + auto begin() { return edges.begin(); } + auto begin() const { return edges.begin(); } + auto cbegin() const { return edges.begin(); } + + auto end() { return edges.end(); } + auto end() const { return edges.end(); } + auto cend() const { return edges.end(); } + + void add(EdgeRecord* edge) + { + edges.push_back(edge); + } + + size_t degree() const + { + return edges.size(); + } + + void remove(EdgeRecord* edge) + { + edges.erase(std::remove(edges.begin(), edges.end(), edge), edges.end()); + } + + void clear() + { + edges.clear(); + } + +private: + std::vector edges; +}; diff --git a/storage/model/edge_model.hpp b/storage/model/edge_model.hpp new file mode 100644 index 000000000..00c23833a --- /dev/null +++ b/storage/model/edge_model.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "property_model.hpp" +#include "edge_type.hpp" +#include "mvcc/version_list.hpp" + +class EdgeModel : public PropertyModel +{ +public: + VertexRecord* from; + VertexRecord* to; + + EdgeType edge_type; +}; diff --git a/storage/model/edge_type.hpp b/storage/model/edge_type.hpp new file mode 100644 index 000000000..df7a511a8 --- /dev/null +++ b/storage/model/edge_type.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include +#include +#include "utils/total_ordering.hpp" + +class EdgeType : public TotalOrdering +{ +public: + EdgeType(const std::string& id) : id(id) {} + EdgeType(std::string&& id) : id(std::move(id)) {} + + friend bool operator<(const EdgeType& lhs, const EdgeType& rhs) + { + return lhs.id < rhs.id; + } + + friend bool operator==(const EdgeType& lhs, const EdgeType& rhs) + { + return lhs.id == rhs.id; + } + + friend std::ostream& operator<<(std::ostream& stream, const EdgeType& type) + { + return stream << type.id; + } + + operator const std::string&() const + { + return id; + } + +private: + std::string id; +}; diff --git a/storage/model/label.hpp b/storage/model/label.hpp new file mode 100644 index 000000000..46ffdcb83 --- /dev/null +++ b/storage/model/label.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include +#include +#include "utils/total_ordering.hpp" + +class Label : public TotalOrdering