edge type store
This commit is contained in:
parent
2b1fc70695
commit
a8a1ce9f0a
@ -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)
|
||||
|
28
include/storage/edge_type/edge_type.hpp
Normal file
28
include/storage/edge_type/edge_type.hpp
Normal 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>;
|
28
include/storage/edge_type/edge_type_store.hpp
Normal file
28
include/storage/edge_type/edge_type_store.hpp
Normal 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;
|
||||
};
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "storage/model/label.hpp"
|
||||
#include "storage/label/label.hpp"
|
||||
|
||||
class LabelCollection
|
||||
{
|
@ -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
|
@ -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();
|
||||
|
||||
|
@ -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; }
|
||||
};
|
||||
|
25
src/storage/edge_type/edge_type.cpp
Normal file
25
src/storage/edge_type/edge_type.cpp
Normal 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;
|
||||
}
|
13
src/storage/edge_type/edge_type_store.cpp
Normal file
13
src/storage/edge_type/edge_type_store.cpp
Normal 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();
|
||||
}
|
@ -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;
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -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)) {}
|
@ -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(); }
|
@ -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)
|
||||
{
|
@ -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};
|
||||
};
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user