memgraph/storage/graph.hpp
2015-11-21 19:16:19 +01:00

64 lines
1.5 KiB
C++

#pragma once
#include <list>
#include "mvcc/atom.hpp"
#include "mvcc/store.hpp"
#include "mvcc/mvcc_error.hpp"
#include "vertex.hpp"
#include "edge.hpp"
using VertexStore = mvcc::MvccStore<Vertex>;
using EdgeStore = mvcc::MvccStore<Edge>;
class Graph
{
public:
Graph() {}
mvcc::Atom<Edge>* connect(mvcc::Atom<Vertex>& atom_a, Vertex& a,
mvcc::Atom<Vertex>& 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>*
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;
};