edge type store

This commit is contained in:
Marko Budiselic 2016-07-06 17:37:05 +01:00
parent 2b1fc70695
commit a8a1ce9f0a
18 changed files with 152 additions and 50 deletions

View File

@ -183,26 +183,29 @@ EXECUTE_PROCESS(
# add_executable(query_hasher src/query_engine/main_query_hasher.cpp)
# target_link_libraries(query_hasher ${fmt_static_lib})
# hard coded implementation of queries
# add_executable(
# queries
# src/query_engine/main_queries.cpp
# src/mvcc/id.cpp
# src/storage/label_store.cpp
# src/storage/vertices.cpp
# src/storage/model/label.cpp
# src/storage/model/label_collection.cpp
# src/storage/model/properties/property.cpp
# src/storage/model/properties/null.cpp
# src/storage/model/properties/bool.cpp
# src/storage/model/properties/string.cpp
# src/storage/model/properties/properties.cpp
# src/storage/locking/record_lock.cpp
# src/storage/vertex_accessor.cpp
# src/transactions/transaction.cpp
# )
# target_link_libraries(queries ${fmt_static_lib})
add_executable(
queries
src/query_engine/main_queries.cpp
src/mvcc/id.cpp
src/storage/vertices.cpp
src/storage/label/label.cpp
src/storage/label/label_collection.cpp
src/storage/label/label_store.cpp
src/storage/edge_type/edge_type.cpp
src/storage/edge_type/edge_type_store.cpp
src/storage/model/properties/property.cpp
src/storage/model/properties/null.cpp
src/storage/model/properties/bool.cpp
src/storage/model/properties/string.cpp
src/storage/model/properties/properties.cpp
src/storage/locking/record_lock.cpp
src/storage/vertex_accessor.cpp
src/transactions/transaction.cpp
)
target_link_libraries(queries ${fmt_static_lib})
# tests
enable_testing()
add_subdirectory(tests)
# enable_testing()
# add_subdirectory(tests)

View File

@ -0,0 +1,28 @@
#pragma once
#include <stdint.h>
#include <ostream>
#include "utils/total_ordering.hpp"
#include "utils/reference_wrapper.hpp"
class EdgeType : public TotalOrdering<EdgeType>
{
public:
EdgeType();
EdgeType(const std::string& id);
EdgeType(std::string&& id);
friend bool operator<(const EdgeType& lhs, const EdgeType& rhs);
friend bool operator==(const EdgeType& lhs, const EdgeType& rhs);
friend std::ostream& operator<<(std::ostream& stream, const EdgeType& type);
operator const std::string&() const;
private:
std::string id;
};
using edge_type_ref_t = ReferenceWrapper<const EdgeType>;

View File

@ -0,0 +1,28 @@
#pragma once
#include <stdexcept>
#include "storage/edge_type/edge_type.hpp"
#include "data_structures/concurrent/concurrent_set.hpp"
class EdgeTypeStore
{
public:
const EdgeType& find_or_create(const std::string& name);
bool contains(const std::string& name); // TODO: const
// TODO: implement find method
// return { EdgeType, is_found }
// TODO: find by reference if it is possible (should be faster)
// figure out the fastest way to store and find types
// do the same for labels
// TODO: EdgeTypeStore and LabelStore are almost the same
// templetize the two of them
private:
ConcurrentSet<EdgeType> edge_types;
};

View File

@ -2,7 +2,7 @@
#include <set>
#include "storage/model/label.hpp"
#include "storage/label/label.hpp"
class LabelCollection
{

View File

@ -2,7 +2,7 @@
#include <stdexcept>
#include "storage/model/label.hpp"
#include "storage/label/label.hpp"
#include "data_structures/concurrent/concurrent_set.hpp"
class LabelStore

View File

@ -181,8 +181,9 @@ int main(int argc, char **argv)
e.from(v1.vlist);
e.to(v2.vlist);
e.edge_type(EdgeType("IN"));
auto &edge_type = db.graph.edge_type_store.find_or_create("IS");
e.edge_type(edge_type);
t.commit();

View File

@ -2,6 +2,8 @@
#include "storage/edge.hpp"
#include "storage/record_accessor.hpp"
#include "utils/assert.hpp"
#include "utils/reference_wrapper.hpp"
class Edges;
@ -10,33 +12,29 @@ class Edge::Accessor : public RecordAccessor<Edge, Edges, Edge::Accessor>
public:
using RecordAccessor::RecordAccessor;
void edge_type(EdgeType type)
void edge_type(edge_type_ref_t edge_type)
{
this->record->data.edge_type = type;
this->record->data.edge_type = &edge_type.get();
}
const std::string& edge_type() const
edge_type_ref_t edge_type() const
{
return this->record->data.edge_type;
runtime_assert(this->record->data.edge_type != nullptr,
"EdgeType is null");
return edge_type_ref_t(*this->record->data.edge_type);
}
void from(VertexRecord* vertex_record)
void from(VertexRecord *vertex_record)
{
this->record->data.from = vertex_record;
}
void to(VertexRecord* vertex_record)
void to(VertexRecord *vertex_record)
{
this->record->data.to = vertex_record;
}
auto from()
{
return this->record->data.from;
}
auto from() { return this->record->data.from; }
auto to()
{
return this->record->data.to;
}
auto to() { return this->record->data.to; }
};

View File

@ -0,0 +1,25 @@
#include "storage/edge_type/edge_type.hpp"
EdgeType::EdgeType() {}
EdgeType::EdgeType(const std::string& id) : id(id) {}
EdgeType::EdgeType(std::string&& id) : id(std::move(id)) {}
bool operator<(const EdgeType& lhs, const EdgeType& rhs)
{
return lhs.id < rhs.id;
}
bool operator==(const EdgeType& lhs, const EdgeType& rhs)
{
return lhs.id == rhs.id;
}
std::ostream& operator<<(std::ostream& stream, const EdgeType& type)
{
return stream << type.id;
}
EdgeType::operator const std::string&() const
{
return id;
}

View File

@ -0,0 +1,13 @@
#include "storage/edge_type/edge_type_store.hpp"
const EdgeType& EdgeTypeStore::find_or_create(const std::string& name)
{
auto accessor = edge_types.access();
return accessor.insert(EdgeType(name)).first;
}
bool EdgeTypeStore::contains(const std::string& name) // const
{
auto accessor = edge_types.access();
return accessor.find(EdgeType(name)) != accessor.end();
}

View File

@ -1,8 +1,9 @@
#pragma once
#include "storage/vertices.hpp"
#include "storage/edges.hpp"
#include "storage/label_store.hpp"
#include "storage/edge_type/edge_type_store.hpp"
#include "storage/label/label_store.hpp"
#include "storage/vertices.hpp"
class Graph
{
@ -11,5 +12,7 @@ public:
Edges edges;
Vertices vertices;
LabelStore label_store;
EdgeTypeStore edge_type_store;
};

View File

@ -5,7 +5,7 @@
#include "data_structures/concurrent/concurrent_map.hpp"
#include "storage/indexes/index_record.hpp"
#include "storage/indexes/index_record_collection.hpp"
#include "storage/model/label.hpp"
#include "storage/label/label.hpp"
template <class Key, class Item>
class Index

View File

@ -1,4 +1,4 @@
#include "storage/model/label.hpp"
#include "storage/label/label.hpp"
Label::Label(const std::string& name) : name(name) {}
Label::Label(std::string&& name) : name(std::move(name)) {}

View File

@ -1,4 +1,4 @@
#include "storage/model/label_collection.hpp"
#include "storage/label/label_collection.hpp"
auto LabelCollection::begin() { return _labels.begin(); }
auto LabelCollection::begin() const { return _labels.begin(); }

View File

@ -1,4 +1,4 @@
#include "storage/label_store.hpp"
#include "storage/label/label_store.hpp"
const Label& LabelStore::find_or_create(const std::string& name)
{

View File

@ -1,14 +1,17 @@
#pragma once
#include "property_model.hpp"
#include "edge_type.hpp"
#include "mvcc/version_list.hpp"
#include "property_model.hpp"
#include "storage/edge_type/edge_type.hpp"
class EdgeModel : public PropertyModel
{
public:
VertexRecord* from;
VertexRecord* to;
VertexRecord *from;
VertexRecord *to;
EdgeType edge_type;
// TODO: here should be the reference
// but something that is copyable
// because this model is copied all the time (mvcc)
const EdgeType *edge_type {nullptr};
};

View File

@ -1,7 +1,7 @@
#pragma once
#include "property_model.hpp"
#include "storage/model/label_collection.hpp"
#include "storage/label/label_collection.hpp"
#include "edge_list.hpp"
class VertexModel : public PropertyModel