61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
#include "storage/edges.hpp"
|
|
|
|
#include "storage/edge_accessor.hpp"
|
|
#include "utils/iterator/iterator.hpp"
|
|
|
|
Edges::store_t::Accessor Edges::access() { return edges.access(); }
|
|
|
|
Option<const EdgeAccessor> Edges::find(DbTransaction &t, const Id &id)
|
|
{
|
|
auto edges_accessor = edges.access();
|
|
auto edges_iterator = edges_accessor.find(id);
|
|
|
|
if (edges_iterator == edges_accessor.end())
|
|
return make_option<const EdgeAccessor>();
|
|
|
|
return make_option_const(EdgeAccessor(&edges_iterator->second, t));
|
|
}
|
|
|
|
EdgeAccessor Edges::insert(DbTransaction &t, VertexRecord *from,
|
|
VertexRecord *to)
|
|
{
|
|
// get next vertex id
|
|
auto next = counter.next(std::memory_order_acquire);
|
|
|
|
// create new vertex record
|
|
EdgeRecord edge_record(next, from, to);
|
|
auto edge = edge_record.insert(t.trans);
|
|
|
|
// insert the new vertex record into the vertex store
|
|
auto edges_accessor = edges.access();
|
|
auto result = edges_accessor.insert(next, std::move(edge_record));
|
|
|
|
// create new vertex
|
|
auto inserted_edge_record = result.first;
|
|
|
|
t.to_update_index<TypeGroupEdge>(&inserted_edge_record->second, edge);
|
|
|
|
return EdgeAccessor(edge, &inserted_edge_record->second, t);
|
|
}
|
|
|
|
Edges::prop_familys_t::Accessor Edges::property_family_access()
|
|
{
|
|
return prop_familys.access();
|
|
}
|
|
|
|
EdgePropertyFamily &
|
|
Edges::property_family_find_or_create(const std::string &name)
|
|
{
|
|
auto acc = prop_familys.access();
|
|
auto it = acc.find(name);
|
|
if (it == acc.end()) {
|
|
EdgePropertyFamily *family = new EdgePropertyFamily(name);
|
|
auto res = acc.insert(name, family);
|
|
if (!res.second) {
|
|
delete family;
|
|
}
|
|
it = res.first;
|
|
}
|
|
return *(it->second);
|
|
}
|