#pragma once #include #include "mvcc/atom.hpp" #include "mvcc/store.hpp" #include "mvcc/mvcc_error.hpp" #include "vertex.hpp" #include "edge.hpp" using VertexStore = mvcc::MvccStore; using EdgeStore = mvcc::MvccStore; class Graph { public: Graph() {} mvcc::Atom* connect(mvcc::Atom& atom_a, Vertex& a, mvcc::Atom& atom_b, Vertex& b, const tx::Transaction& t) { // try to lock A auto guard_a = atom_a.acquire_unique(); if(a.tx.max()) throw mvcc::MvccError("can't serialize due to\ concurrent operation(s)"); auto guard_b = atom_b.acquire_unique(); if(b.tx.max()) throw mvcc::MvccError("can't serialize due to\ concurrent operation(s)"); return edges.insert(t); } // TODO: this should probably return mvcc::Atom* Vertex* find_vertex(const Id& id) { // get atom iterator auto atom_it = vertices.begin(); // find the right atom // TODO: better implementation while (true) { if (id == atom_it->id) { // TODO: return latest version return atom_it->first(); } if (!atom_it.has_next()) break; ++atom_it; } return nullptr; } VertexStore vertices; EdgeStore edges; };