This commit is contained in:
Kruno Tomola Fabro 2016-08-28 15:47:13 +01:00
parent 9469d09c57
commit 77a3298d1e
45 changed files with 1906 additions and 163 deletions

View File

@ -401,6 +401,7 @@ EXECUTE_PROCESS(
# TODO: create separate static library from bolt code
set(memgraph_src_files
${src_dir}/barrier/barrier.cpp
${src_dir}/utils/string/transform.cpp
${src_dir}/utils/string/join.cpp
${src_dir}/utils/string/file.cpp

View File

@ -0,0 +1,547 @@
#pragma once
#include "barrier/common.hpp"
// This namespace is holding header parts of barrier classes. Barrier class
// object is in fact object from other class inside memgraph. Main purpose of
// barrier classes is to hide real classes from outside viewers. This header
// should be only to be included from memgraph into generated/compiled query.
// And this header must ensure that it defines all classes and methods required
// for querys.
namespace barrier
{
// Every class which must be visible to outside the barrier should have there
// barrier class defined here.
// ************ Here should be forward declarations of Sized barrier classes
class VertexAccessor; // DONE // .cpp
class EdgeAccessor; // DONE // .cpp
class VertexIterator; // DONE // .cpp
class EdgeIterator; // DONE // .cpp
class VertexAccessIterator; // DONE // .cpp
class OutEdgesIterator; // DONE // .cpp
class InEdgesIterator; // DONE // .cpp
class VertexPropertyKey; // DONE // .cpp
class EdgePropertyKey; // DONE // .cpp
template <class T>
class VertexPropertyType; // DONE // .cpp
template <class T>
class EdgePropertyType; // DONE // .cpp
template <class Stream>
class BoltSerializer; // DONE // .cpp
// ************ Here should be forward declarations of Unsized barrier classes
class Label; // DONE // .cpp
class EdgeType; // DONE // .cpp
class Db;
class DbAccessor; // DONE // .cpp
class VertexPropertyFamily; // DONE // .cpp
class EdgePropertyFamily; // DONE // .cpp
template <class K>
class VertexIndex; // DONE // .cpp
template <class K>
class EdgeIndex; // DONE // .cpp
// ************* Here should be defined usings
using label_ref_t = ReferenceWrapper<const Label>;
// ************ Here should be definitions of Sized barrier classes
// Original class should have Sized barrier class if it can't be Unsized.
// Sized barrier classes should:
// --Have same name as original class.
// --Inherit Sized class from common.hpp as private. Blueprint:
// class class_name: Sized<size_of_t,aligment_of_t>
// --Sized template arguments must be hardcoded numbers equal to sizeof(T) and
// alignof(T) where T is original class.
// --It should have friends barrier classes which are permitted to construct it.
// --It should have undefined public constructor which is specialized in .cpp
// Blueprint:
// public:
// template<class T> class_name(T &&d);
// --It should delete or specify following methods depending on the behavior of
// the original class:
// public:
// class_name(const class_name &other);
// class_name(class_name &&other);
// ~class_name();
// class_name &operator=(const class_name &other);
// class_name &operator=(class_name &&other);
// --It should specify public methods which can be called on the original class.
// An example of such Sized barrier class:
//
// class Accessor : private Sized<16, 8>
// {
// public://
// template <class T>
// Accessor(T &&d);
//
// Accessor(const Accessor &other);
// Accessor(Accessor &&other);
// ~Accessor();
//
// Accessor &operator=(const Accessor &other);
// Accessor &operator=(Accessor &&other);
//
// int get_prop(Name &name);
// };
//
// Blueprint:
// class class_name : private Sized<,>
// {
// public://
// template <class T>
// class_name(T &&d);
//
// class_name(const class_name &other);
// class_name(class_name &&other);
// ~class_name();
//
// class_name &operator=(const class_name &other);
// class_name &operator=(class_name &&other);
//
// };
// TODO: Extract methods od RecordAccessor for VertexAccessor and EdgeAccessor
// into joined class.
class VertexAccessor : private Sized<24, 8>
{
public:
template <class T>
VertexAccessor(T &&d);
VertexAccessor(const VertexAccessor &other);
VertexAccessor(VertexAccessor &&other);
VertexAccessor(VertexAccessor const &&other);
~VertexAccessor();
VertexAccessor &operator=(const VertexAccessor &other);
VertexAccessor &operator=(VertexAccessor &&other);
size_t out_degree() const;
size_t in_degree() const;
size_t degree() const;
bool add_label(const Label &label);
bool remove_label(const Label &label);
bool has_label(const Label &label) const;
const std::vector<label_ref_t> &labels() const;
OutEdgesIterator out() const;
InEdgesIterator in() const;
bool in_contains(VertexAccessor const &other) const;
bool empty() const;
bool fill() const;
const Id &id() const;
VertexAccessor update() const;
bool remove() const;
const Property &at(VertexPropertyFamily &key) const;
const Property &at(VertexPropertyKey &key) const;
template <class V>
OptionPtr<V> at(VertexPropertyType<V> &key) const;
template <class V, class... Args>
void set(VertexPropertyType<V> &key, Args &&... args);
void set(VertexPropertyKey &key, Property::sptr value);
void clear(VertexPropertyKey &key);
void clear(VertexPropertyFamily &key);
template <class Handler>
void accept(Handler &handler) const;
explicit operator bool() const;
friend bool operator==(const VertexAccessor &a, const VertexAccessor &b);
friend bool operator!=(const VertexAccessor &a, const VertexAccessor &b);
};
class EdgeAccessor : private Sized<24, 8>
{
public:
template <class T>
EdgeAccessor(T &&d);
EdgeAccessor(const EdgeAccessor &other);
EdgeAccessor(EdgeAccessor &&other);
EdgeAccessor(EdgeAccessor const &&other);
~EdgeAccessor();
EdgeAccessor &operator=(const EdgeAccessor &other);
EdgeAccessor &operator=(EdgeAccessor &&other);
void edge_type(const EdgeType &edge_type);
const EdgeType &edge_type() const;
const VertexAccessor from() const;
const VertexAccessor to() const;
bool empty() const;
bool fill() const;
const Id &id() const;
EdgeAccessor update() const;
bool remove() const;
const Property &at(EdgePropertyFamily &key) const;
const Property &at(EdgePropertyKey &key) const;
template <class V>
OptionPtr<V> at(EdgePropertyType<V> &key) const;
template <class V, class... Args>
void set(EdgePropertyType<V> &key, Args &&... args);
void set(EdgePropertyKey &key, Property::sptr value);
void clear(EdgePropertyKey &key);
void clear(EdgePropertyFamily &key);
template <class Handler>
void accept(Handler &handler) const;
explicit operator bool() const;
friend bool operator==(const EdgeAccessor &a, const EdgeAccessor &b);
friend bool operator!=(const EdgeAccessor &a, const EdgeAccessor &b);
};
class DbAccessor : protected Sized<40, 8>
{
public:
DbAccessor(Db &d);
DbAccessor(const DbAccessor &other) = delete;
DbAccessor(DbAccessor &&other) = delete;
~DbAccessor();
DbAccessor &operator=(const DbAccessor &other) = delete;
DbAccessor &operator=(DbAccessor &&other) = delete;
VertexAccessIterator vertex_access();
Option<const VertexAccessor> vertex_find(const Id &id);
VertexAccessor vertex_insert();
Option<const EdgeAccessor> edge_find(const Id &id);
EdgeAccessor edge_insert(VertexAccessor const &from,
VertexAccessor const &to);
const Label &label_find_or_create(const char *name);
bool label_contains(const char *name);
const EdgeType &type_find_or_create(const char *name);
bool type_contains(const char *name);
VertexPropertyFamily &vertex_property_family_get(const std::string &name);
EdgePropertyFamily &edge_property_family_get(const std::string &name);
VertexPropertyKey vertex_property_key(const std::string &name, Type type);
EdgePropertyKey edge_property_key(const std::string &name, Type type);
template <class T>
VertexPropertyType<T> vertex_property_key(const std::string &name);
template <class T>
EdgePropertyType<T> edge_property_key(const std::string &name);
bool commit();
void abort();
};
class VertexIterator : private Sized<8, 8>
{
public:
template <class T>
VertexIterator(T &&d);
VertexIterator(const VertexIterator &other) = delete;
VertexIterator(VertexIterator &&other);
~VertexIterator();
VertexIterator &operator=(const VertexIterator &other) = delete;
VertexIterator &operator=(VertexIterator &&other) = delete;
Option<const VertexAccessor> next();
};
// TODO: Find reasons of such great size ant try to decrease it.
class VertexAccessIterator : private Sized<552, 8>
{
public:
template <class T>
VertexAccessIterator(T &&d);
VertexAccessIterator(const VertexAccessIterator &other) = delete;
VertexAccessIterator(VertexAccessIterator &&other);
~VertexAccessIterator();
VertexAccessIterator &operator=(const VertexAccessIterator &other) = delete;
VertexAccessIterator &operator=(VertexAccessIterator &&other) = delete;
Option<const VertexAccessor> next();
};
class OutEdgesIterator : private Sized<40, 8>
{
public:
template <class T>
OutEdgesIterator(T &&d);
OutEdgesIterator(const OutEdgesIterator &other) = delete;
OutEdgesIterator(OutEdgesIterator &&other);
~OutEdgesIterator();
OutEdgesIterator &operator=(const OutEdgesIterator &other) = delete;
OutEdgesIterator &operator=(OutEdgesIterator &&other) = delete;
Option<const EdgeAccessor> next();
};
class InEdgesIterator : private Sized<56, 8>
{
public:
template <class T>
InEdgesIterator(T &&d);
InEdgesIterator(const InEdgesIterator &other) = delete;
InEdgesIterator(InEdgesIterator &&other);
~InEdgesIterator();
InEdgesIterator &operator=(const InEdgesIterator &other) = delete;
InEdgesIterator &operator=(InEdgesIterator &&other) = delete;
Option<const EdgeAccessor> next();
};
class EdgeIterator : private Sized<8, 8>
{
public:
template <class T>
EdgeIterator(T &&d);
EdgeIterator(const EdgeIterator &other) = delete;
EdgeIterator(EdgeIterator &&other);
~EdgeIterator();
EdgeIterator &operator=(const EdgeIterator &other) = delete;
EdgeIterator &operator=(EdgeIterator &&other) = delete;
Option<const EdgeAccessor> next();
};
class VertexPropertyKey : private Sized<8, 8>
{
public:
template <class T>
VertexPropertyKey(T &&d);
VertexPropertyKey(const VertexPropertyKey &other) = default;
VertexPropertyKey(VertexPropertyKey &&other) = default;
~VertexPropertyKey();
VertexPropertyKey &operator=(const VertexPropertyKey &other) = default;
VertexPropertyKey &operator=(VertexPropertyKey &&other) = default;
};
class EdgePropertyKey : private Sized<8, 8>
{
public:
template <class T>
EdgePropertyKey(T &&d);
EdgePropertyKey(const EdgePropertyKey &other) = default;
EdgePropertyKey(EdgePropertyKey &&other) = default;
~EdgePropertyKey();
EdgePropertyKey &operator=(const EdgePropertyKey &other) = default;
EdgePropertyKey &operator=(EdgePropertyKey &&other) = default;
};
template <class K>
class VertexPropertyType : private Sized<8, 8>
{
public:
template <class T>
VertexPropertyType(T &&d);
VertexPropertyType(const VertexPropertyType &other) = default;
VertexPropertyType(VertexPropertyType &&other) = default;
~VertexPropertyType();
VertexPropertyType &operator=(const VertexPropertyType &other) = default;
VertexPropertyType &operator=(VertexPropertyType &&other) = default;
};
template <class K>
class EdgePropertyType : private Sized<8, 8>
{
public:
template <class T>
EdgePropertyType(T &&d);
EdgePropertyType(const EdgePropertyType &other) = default;
EdgePropertyType(EdgePropertyType &&other) = default;
~EdgePropertyType();
EdgePropertyType &operator=(const EdgePropertyType &other) = default;
EdgePropertyType &operator=(EdgePropertyType &&other) = default;
};
template <class Stream>
class BoltSerializer : private Sized<8, 8>
{
public:
template <class T>
BoltSerializer(T &&d);
BoltSerializer(const BoltSerializer &other) = default;
BoltSerializer(BoltSerializer &&other) = default;
~BoltSerializer();
BoltSerializer &operator=(const BoltSerializer &other) = default;
BoltSerializer &operator=(BoltSerializer &&other) = default;
void write(const VertexAccessor &vertex);
void write(const EdgeAccessor &edge);
void write(const Property &prop);
void write_null();
void write(const Bool &prop);
void write(const Float &prop);
void write(const Double &prop);
void write(const Int32 &prop);
void write(const Int64 &prop);
void write(const std::string &value);
void write(const String &prop);
template <class T>
void handle(const T &prop);
};
// ************ Here should be definitions of Unsized barrier classes
// Original class can be Unsized barrier class if they are only used outside the
// barrier through reference/pointer.
// Usized barrier classes should:
// --Have same name as original class or somethin more specific if it is
// partialy specialized.
// --Inherit Unsized class from common.hpp as protected. Blueprint:
// class class_name: protected Unsized
// --It should specify public methods which can be called on the original class.
// An example of such Unsized barrier class:
//
// class Db : protected Unsized
// {
// public:
// Accessor access();
// Name &get_name(const char *str);
// };
//
// Blueprint:
// class class_name : protected Unsized
// {
// public:
//
// };
class VertexPropertyFamily : protected Unsized
{
public:
OptionPtr<VertexIndex<std::nullptr_t>> index();
};
class EdgePropertyFamily : protected Unsized
{
public:
OptionPtr<EdgeIndex<std::nullptr_t>> index();
};
class Label : protected Unsized
{
public:
VertexIndex<std::nullptr_t> &index() const;
};
class EdgeType : protected Unsized
{
public:
EdgeIndex<std::nullptr_t> &index() const;
};
template <class K>
class VertexIndex : protected Unsized
{
public:
// TODO: This iterator sometimes has known type. It can be added to this
// border to avoid dynamic dispatch
VertexIterator for_range(DbAccessor &, Border<K> from = Border<K>(),
Border<K> to = Border<K>());
bool unique();
Order order();
};
template <class K>
class EdgeIndex : protected Unsized
{
public:
// TODO: This iterator has known type. It can be added to this border to
// avoid dynamic dispatch
EdgeIterator for_range(DbAccessor &, Border<K> from = Border<K>(),
Border<K> to = Border<K>());
bool unique();
Order order();
};
class Db : protected Unsized
{
};
}

View File

@ -0,0 +1,163 @@
#pragma once
#include <cassert>
#include <type_traits>
#include <utility>
#include <vector>
// THis shoul be the only place to include code from memgraph other than
// barrier.cpp
#include "mvcc/id.hpp"
#include "storage/model/properties/all.hpp"
#include "utils/border.hpp"
#include "utils/iterator/iterator.hpp"
#include "utils/option_ptr.hpp"
#include "utils/order.hpp"
#include "utils/reference_wrapper.hpp"
// Contains common classes and functions for barrier.hpp and barrier.cpp.
namespace barrier
{
// This define accepts other define which accepts property type to instantiate
// template. Recieved define will be called for all property types.
#define INSTANTIATE_FOR_PROPERTY(x) \
x(Int32) x(Int64) x(Float) x(Double) x(Bool) x(String) x(ArrayInt32) \
x(ArrayInt64) x(ArrayFloat) x(ArrayDouble) x(ArrayBool) x(ArrayString)
// **************************** HELPER FUNCTIONS **************************** //
template <class TO, class FROM>
TO &ref_as(FROM &ref)
{
return (*reinterpret_cast<TO *>(&ref));
}
template <class TO, class FROM>
TO const &ref_as(FROM const &ref)
{
return (*reinterpret_cast<TO const *>(&ref));
}
template <class TO, class FROM>
TO *ptr_as(FROM *ref)
{
return (reinterpret_cast<TO *>(ref));
}
template <class TO, class FROM>
TO const *ptr_as(FROM const *ref)
{
return (reinterpret_cast<TO const *>(ref));
}
template <class TO, class FROM>
TO value_as(FROM &&ref)
{
static_assert(sizeof(FROM) == sizeof(FROM), "Border class size mismatch");
static_assert(alignof(TO) == alignof(FROM),
"Border class aligment mismatch");
return std::move((*reinterpret_cast<TO *>(&ref)));
}
template <class TO, class FROM>
const TO value_as(const FROM &&ref)
{
static_assert(sizeof(FROM) == sizeof(FROM), "Border class size mismatch");
static_assert(alignof(TO) == alignof(FROM),
"Border class aligment mismatch");
return std::move((*reinterpret_cast<TO const *>(&ref)));
}
// Barrier classes which will be used only through reference/pointer should
// inherit this class.
class Unsized
{
public:
// Deleting following constructors/destroyers and opertators will assure
// that this class/derived classes can't be created,copyed,deleted or moved.
// This way the other side can't "accidentaly" create/copy/destroy or move
// objects which inherit this class because that would be erroneous.
Unsized() = delete;
Unsized(const Unsized &other) = delete;
Unsized(Unsized &&other) = delete;
~Unsized() = delete;
Unsized &operator=(const Unsized &other) = delete;
Unsized &operator=(Unsized &&other) = delete;
};
// Barrier classes which will be used as value should inherit this class.
// Template accepts size_B in B of object of original class from memgraph.
// Template accepts alignment_B in B of object of original class from memgraph.
template <std::size_t size_B, std::size_t alignment_B>
class Sized
{
protected:
// This will ensure that this/derived class can't be instantiated.
// This way side outside the barrier can't "accidentaly" create this/derived
// type because that would be erroneous.
Sized() = delete;
//
// // This constructor serves as a check for correctness of size_B and
// // alignment_B template parametars. Derived class MUST call this
// constructor
// // with T which it holds where T is original class from memgraph.
// template <class T>
// Sized(T &&d)
// // : data(value_as<
// // typename std::aligned_storage<size_B, alignment_B>::type>(
// // std::move(d)))
// {
// new (&ref_as<T>(data)) T(std::move(d));
// static_assert(size_B == sizeof(T), "Border class size mismatch");
// static_assert(alignment_B == alignof(T),
// "Border class aligment mismatch");
// }
//
// // This constructor serves as a check for correctness of size_B and
// // alignment_B template parametars. Derived class MUST call this
// constructor
// // with T which it holds where T is original class from memgraph.
// template <class T>
// Sized(const T &&d)
// // : data(value_as<
// // const typename std::aligned_storage<size_B,
// alignment_B>::type>(
// // std::move(d)))
// {
// new (&ref_as<T>(data)) T(std::move(d));
// static_assert(size_B == sizeof(T), "Border class size mismatch");
// static_assert(alignment_B == alignof(T),
// "Border class aligment mismatch");
// }
// // This constructor serves as a check for correctness of size_B and
// // alignment_B template parametars. Derived class MUST call this
// constructor
// // with T which it holds where T is original class from memgraph.
// template <class T>
// Sized(std::unique_ptr<T> &&d)
// : data(value_as<
// const typename std::aligned_storage<size_B,
// alignment_B>::type>(
// std::unique_ptr<T>(nullptr)))
// {
// ref_as<std::unique_ptr<T>>(data) = std::move(d);
//
// static_assert(size_B == sizeof(T), "Border class size mismatch");
// static_assert(alignment_B == alignof(T),
// "Border class aligment mismatch");
// }
private:
// Here is the aligned storage which imitates size and aligment of object of
// original class from memgraph.
typename std::aligned_storage<size_B, alignment_B>::type data;
};
// HELPER FUNCTIONS
template <class R>
bool option_fill(Option<R> &o)
{
return o.is_present() && o.get().fill();
}
}

View File

@ -85,7 +85,7 @@ public:
encoder.write_integer(edge.to().id());
// write the type of the edge
encoder.write_string(edge.edge_type().get());
encoder.write_string(edge.edge_type());
// write the property map
auto props = edge.properties();

View File

@ -69,6 +69,7 @@ private:
{
other.list = nullptr;
other.curr = nullptr;
other.prev = nullptr;
}
~IteratorBase()
@ -95,6 +96,9 @@ private:
}
}
IteratorBase &operator=(IteratorBase const &other) = delete;
IteratorBase &operator=(IteratorBase &&other) = delete;
T &operator*() const
{
assert(valid());

View File

@ -1,8 +1,10 @@
#pragma once
#include "database/db.hpp"
#include "database/db_transaction.hpp"
#include "storage/model/properties/property_family.hpp"
#include "utils/border.hpp"
#include "utils/iterator/iterator.hpp"
#include "utils/option.hpp"
namespace tx
@ -51,8 +53,15 @@ public:
DbAccessor(Db &db, tx::Transaction &t);
//*******************VERTEX METHODS
auto vertex_access();
// TODO: Implement class specaily for this return
auto vertex_access()
{
return iter::make_map(
iter::make_iter(this->db_transaction.db.graph.vertices.access()),
[&](auto e) -> auto {
return VertexAccessor(&(e->second), db_transaction);
});
}
Option<const VertexAccessor> vertex_find(const Id &id);
@ -94,11 +103,21 @@ public:
template <class T>
VertexPropertyFamily::PropertyType::PropertyTypeKey<T>
vertex_property_key(const std::string &name);
vertex_property_key(const std::string &name)
{
return vertex_property_family_get(name)
.get(T::type)
.template type_key<T>();
}
template <class T>
EdgePropertyFamily::PropertyType::PropertyTypeKey<T>
edge_property_key(const std::string &name);
edge_property_key(const std::string &name)
{
return edge_property_family_get(name)
.get(T::type)
.template type_key<T>();
}
// ******************** TRANSACTION METHODS

View File

@ -36,6 +36,8 @@
using namespace std;
constexpr char *_string = "string";
bool equal_str(const char *a, const char *b) { return strcasecmp(a, b) == 0; }
// CSV importer for importing multiple files regarding same graph.
@ -203,7 +205,7 @@ private:
warn(
"Column ", tmp_vec[0],
" doesn't have specified type so string type will be used");
tmp_vec.push_back("string");
tmp_vec.push_back(_string);
} else {
warn("Empty colum definition, skiping column.");
std::unique_ptr<Filler> f(new SkipFiller());

View File

@ -1,18 +1,25 @@
#pragma once
#include "database/db.hpp"
#include "database/db_accessor.cpp"
#include "database/db_accessor.hpp"
#include "query_engine/query_stripper.hpp"
#include "query_engine/util.hpp"
#include "storage/indexes/impl/nonunique_unordered_index.cpp"
// #include "storage/model/properties/properties.cpp"
#include "storage/model/properties/property.hpp"
#include "storage/model/properties/property_family.hpp"
#include "utils/command_line/arguments.hpp"
#include "utils/iterator/iterator.hpp"
// #include "utils/utils.cpp"
#include <iostream>
#include <map>
// #include "database/db.hpp"
// #include "database/db_accessor.cpp"
// #include "database/db_accessor.hpp"
// #include "query_engine/query_stripper.hpp"
// #include "query_engine/util.hpp"
// #include "storage/indexes/impl/nonunique_unordered_index.cpp"
// #include "storage/model/properties/property.hpp"
// #include "storage/model/properties/property_family.hpp"
// #include "utils/command_line/arguments.hpp"
// #include "utils/iterator/iterator.hpp"
#include "barrier/barrier.hpp"
using namespace std;
namespace barrier
{
auto load_queries(Db &db)
{
std::map<uint64_t, std::function<bool(const properties_t &)>> queries;
@ -37,7 +44,7 @@ auto load_queries(Db &db)
auto vertex_accessor = t.vertex_insert();
vertex_accessor.set(prop_key, args[0]);
vertex_accessor.add_label(label);
cout_properties(vertex_accessor.properties());
// cout_properties(vertex_accessor.properties());
t.commit();
return true;
};
@ -56,7 +63,7 @@ auto load_queries(Db &db)
vertex_accessor.set(prop_country, args[2]);
vertex_accessor.set(prop_created, args[3]);
vertex_accessor.add_label(label);
cout_properties(vertex_accessor.properties());
// cout_properties(vertex_accessor.properties());
t.commit();
return true;
};
@ -70,10 +77,10 @@ auto load_queries(Db &db)
return false;
}
auto vertex_accessor = maybe_va.get();
cout_properties(vertex_accessor.properties());
// cout_properties(vertex_accessor.properties());
cout << "LABELS:" << endl;
for (auto label_ref : vertex_accessor.labels()) {
cout << label_ref.get() << endl;
// cout << label_ref.get() << endl;
}
t.commit();
return true;
@ -95,9 +102,9 @@ auto load_queries(Db &db)
t.commit();
cout << edge_accessor.edge_type() << endl;
// cout << edge_accessor.edge_type() << endl;
cout_properties(edge_accessor.properties());
// cout_properties(edge_accessor.properties());
return true;
};
@ -109,19 +116,19 @@ auto load_queries(Db &db)
auto edge_accessor = maybe_ea.get();
// print edge type and properties
cout << "EDGE_TYPE: " << edge_accessor.edge_type() << endl;
// cout << "EDGE_TYPE: " << edge_accessor.edge_type() << endl;
auto from = edge_accessor.from();
if (!from.fill()) return t.commit(), false;
cout << "FROM:" << endl;
cout_properties(from->data.props);
// cout_properties(from->data.props);
auto to = edge_accessor.to();
if (!to.fill()) return t.commit(), false;
cout << "TO:" << endl;
cout_properties(to->data.props);
// cout_properties(to->data.props);
t.commit();
@ -137,7 +144,7 @@ auto load_queries(Db &db)
auto v = maybe_v.get();
v.set(prop_name, args[1]);
cout_properties(v.properties());
// cout_properties(v.properties());
t.commit();
@ -173,7 +180,7 @@ auto load_queries(Db &db)
iter::for_all(t.vertex_access(), [&](auto vertex) {
if (vertex.fill()) {
cout_properties(vertex->data.props);
// cout_properties(vertex->data.props);
}
});
@ -191,7 +198,7 @@ auto load_queries(Db &db)
auto prop_key = t.vertex_property_key("name", Flags::String);
cout << "VERTICES" << endl;
iter::for_all(label.index->for_range_exact(t),
iter::for_all(label.index().for_range(t),
[&](auto a) { cout << a.at(prop_key) << endl; });
return true;
@ -208,3 +215,4 @@ auto load_queries(Db &db)
return queries;
}
}

View File

@ -19,11 +19,11 @@ public:
typedef Edge record_t;
typedef EdgeRecord record_list_t;
void edge_type(edge_type_ref_t edge_type);
void edge_type(EdgeType const &edge_type);
edge_type_ref_t edge_type() const;
const EdgeType &edge_type() const;
VertexAccessor from() const;
const VertexAccessor from() const;
VertexAccessor to() const;
const VertexAccessor to() const;
};

View File

@ -37,10 +37,11 @@ public:
CharStr char_str() { return CharStr(&id[0]); }
std::unique_ptr<type_index_t> index;
type_index_t &index() const;
private:
std::string id;
std::unique_ptr<type_index_t> index_v;
};
using edge_type_ref_t = ReferenceWrapper<const EdgeType>;

View File

@ -13,6 +13,8 @@ class EdgeAccessor;
class DbTransaction;
using EdgePropertyFamily = PropertyFamily<TypeGroupEdge>;
template <class K>
using EdgeIndexBase = IndexBase<TypeGroupEdge, K>;
class Edges
{

View File

@ -36,6 +36,8 @@ public:
IndexBase(bool unique, Order order, const tx::Transaction &t);
virtual ~IndexBase(){};
// Insert's value.
// unique => returns false if there is already valid equal value.
// nonunique => always succeds.
@ -66,12 +68,15 @@ public:
// True if transaction is obliged to insert T into index.
bool is_obliged_to_insert(const tx::Transaction &t);
// Are the records unique
const bool unique;
// Ordering of the records.
const Order order;
bool unique() { return _unique; }
Order order() { return _order; }
private:
// Are the records unique
const bool _unique;
// Ordering of the records.
const Order _order;
// Id of transaction which created this index.
const Id created;
// Active state

View File

@ -41,9 +41,10 @@ public:
CharStr char_str() const { return CharStr(name.c_str()); }
std::unique_ptr<label_index_t> index;
label_index_t &index() const;
private:
std::unique_ptr<label_index_t> index_v;
std::string name;
};

View File

@ -1,6 +1,6 @@
#pragma once
#include <set>
#include <vector>
// #include "storage/label/label.hpp"
#include "utils/reference_wrapper.hpp"
@ -24,8 +24,8 @@ public:
size_t count() const;
bool remove(const Label &label);
void clear();
const std::set<label_ref_t> &operator()() const;
const std::vector<label_ref_t> &operator()() const;
private:
std::set<label_ref_t> _labels;
std::vector<label_ref_t> _labels;
};

View File

@ -39,10 +39,35 @@ public:
const Property &at(prop_key_t &key) const;
template <class T>
auto at(type_key_t<T> &key) const;
OptionPtr<T> at(type_key_t<T> &key) const
{
auto f_key = key.family_key();
auto it = props.find(f_key);
if (it == props.end() || it->first.prop_type() != key.prop_type())
return OptionPtr<T>();
return OptionPtr<T>(&(it->second.get()->template as<T>()));
}
template <class T, class... Args>
void set(type_key_t<T> &key, Args &&... args);
void set(type_key_t<T> &key, Args &&... args)
{
auto value = std::make_shared<T>(std::forward<Args>(args)...);
// try to emplace the item
// TODO: There is uneccesary copying of value here.
auto result = props.emplace(std::make_pair(key, value));
if (!result.second) {
// It is necessary to change key because the types from before and
// now
// could be different.
prop_key_t &key_ref = const_cast<prop_key_t &>(result.first->first);
key_ref = key;
result.first->second = std::move(value);
}
}
void set(prop_key_t &key, Property::sptr value);

View File

@ -91,7 +91,7 @@ public:
}
template <class V>
auto at(type_key_t<TG, V> &key) const
OptionPtr<V> at(type_key_t<TG, V> &key) const
{
return properties().template at<V>(key);
}
@ -152,6 +152,7 @@ public:
return !(a == b);
}
protected:
T *record{nullptr};
vlist_t *const vlist;
DbTransaction &db;

View File

@ -1,7 +1,9 @@
#pragma once
// #include "storage/edge_accessor.hpp"
#include "storage/record_accessor.hpp"
#include "storage/vertex.hpp"
// #include "utils/iterator/iterator.hpp"
class Vertices;
@ -26,7 +28,7 @@ public:
bool has_label(const Label &label) const;
const std::set<label_ref_t> &labels() const;
const std::vector<label_ref_t> &labels() const;
auto out() const;

View File

@ -13,6 +13,8 @@ class DbTransaction;
class VertexAccessor;
using VertexPropertyFamily = PropertyFamily<TypeGroupVertex>;
template <class K>
using VertexIndexBase = IndexBase<TypeGroupVertex, K>;
class Vertices
{

View File

@ -1,6 +1,7 @@
#pragma once
#include <memory>
#include "utils/option.hpp"
namespace iter

View File

@ -20,6 +20,14 @@ public:
: begin(std::move(acc.begin())), acc(std::forward<A>(acc))
{
}
IteratorAccessor(IteratorAccessor &&other)
: begin(std::move(other.begin)), acc(std::forward<A>(other.acc))
{
}
~IteratorAccessor() final {}
// Iter(const Iter &other) = delete;
// Iter(Iter &&other) :
// begin(std::move(other.begin)),end(std::move(other.end)) {};

View File

@ -8,5 +8,7 @@ template <class T>
class IteratorBase
{
public:
virtual ~IteratorBase(){};
virtual Option<T> next() = 0;
};

View File

@ -13,6 +13,10 @@ class LambdaIterator : public IteratorBase<T>
public:
LambdaIterator(F &&f) : func(std::move(f)) {}
LambdaIterator(LambdaIterator &&other) : func(std::move(other.func)) {}
~LambdaIterator() final {}
Option<T> next() final { return func(); }
private:

View File

@ -23,6 +23,10 @@ public:
// std::move is a optimization for it.
Map(I &&iter, OP &&op) : iter(std::move(iter)), op(std::move(op)) {}
Map(Map &&m) : iter(std::move(m.iter)), op(std::move(m.op)) {}
~Map() final {}
Option<T> next() final
{
auto item = iter.next();

View File

@ -104,6 +104,26 @@ public:
return *data._M_ptr();
}
template <class U>
Option<U> map()
{
if (is_present()) {
return Option<U>(U(take()));
} else {
return Option<U>();
}
}
template <class U, class F>
Option<U> map(F f)
{
if (is_present()) {
return Option<U>(f(take()));
} else {
return Option<U>();
}
}
T take()
{
assert(initialized);

View File

@ -16,3 +16,8 @@ include_directories(${CMAKE_SOURCE_DIR}/poc)
add_executable(isolation isolation.cpp isolation/header.cpp)
target_link_libraries(isolation ${fmt_static_lib})
add_executable(size_aligment size_aligment.cpp)
target_link_libraries(size_aligment memgraph)
target_link_libraries(size_aligment Threads::Threads)
target_link_libraries(size_aligment ${fmt_static_lib})

View File

@ -58,7 +58,7 @@ public:
auto now = this;
double sum = 0;
do {
sum += *(now->vacc.at(tkey).get());
sum += (now->vacc.at(tkey).get())->value;
now = now->parent;
} while (now != nullptr);
return sum;
@ -89,7 +89,7 @@ double calc_heuristic_cost_dummy(type_key_t<TypeGroupVertex, Double> tkey,
EdgeAccessor &edge, VertexAccessor &vertex)
{
assert(!vertex.empty());
return 1 - *vertex.at(tkey).get();
return 1 - vertex.at(tkey).get()->value;
}
typedef bool (*EdgeFilter)(DbAccessor &t, EdgeAccessor &, Node *before);

View File

@ -7,11 +7,13 @@
#include "isolation/db.hpp"
#include "isolation/header.hpp"
using namespace base;
// using namespace base;
int main()
{
std::cout << sizeof(Accessor) << " : " << alignof(Accessor) << "\n";
std::cout << sizeof(sha::Accessor) << " : " << alignof(sha::Accessor)
<< "\n";
Db db;
db.data = 207;

View File

@ -1,7 +1,5 @@
#include <string>
namespace base
{
class Accessor
{
public:
@ -25,4 +23,3 @@ public:
int data = 0;
Name name = {"name"};
};
}

View File

@ -8,30 +8,32 @@ TO &ref_as(FROM &ref)
return (*reinterpret_cast<TO *>(&ref));
}
template <class TO, class FROM>
TO value_as(FROM &&ref)
// template <class TO, class FROM>
// TO value_as(FROM &&ref)
// {
// return std::move((*reinterpret_cast<TO *>(&ref)));
// }
sha::Accessor::Accessor(const sha::Accessor &other)
: Sized(sizeof(::Accessor), alignof(::Accessor))
{
return std::move((*reinterpret_cast<TO *>(&ref)));
as<::Accessor>() = other.as<::Accessor>();
}
sha::Accessor::Accessor(const sha::Accessor::Accessor &other)
: Sized(sizeof(base::Accessor), alignof(base::Accessor))
sha::Accessor::Accessor(sha::Accessor &&other)
: Sized(sizeof(::Accessor), alignof(::Accessor))
{
as<base::Accessor>() = other.as<base::Accessor>();
as<::Accessor>() = value_as<::Accessor>(other);
}
sha::Accessor::Accessor(sha::Accessor::Accessor &&other)
: Sized(sizeof(base::Accessor), alignof(base::Accessor))
{
as<base::Accessor>() = value_as<base::Accessor>(other);
}
sha::Accessor::~Accessor() { as<::Accessor>().~Accessor(); }
sha::Accessor &sha::Accessor::operator=(const sha::Accessor::Accessor &other)
sha::Accessor &sha::Accessor::operator=(const sha::Accessor &other)
{
// TODO
return *this;
}
sha::Accessor &sha::Accessor::operator=(sha::Accessor::Accessor &&other)
sha::Accessor &sha::Accessor::operator=(sha::Accessor &&other)
{
// TODO
return *this;
@ -39,21 +41,21 @@ sha::Accessor &sha::Accessor::operator=(sha::Accessor::Accessor &&other)
int sha::Accessor::get_prop(sha::Name &name)
{
return as<base::Accessor>().data;
return as<::Accessor>().data;
}
sha::Accessor sha::Db::access()
{
auto &db = as<base::Db>();
auto &db = as<::Db>();
db.accessed++;
base::Accessor acc;
::Accessor acc;
acc.data = db.data;
return sha::Accessor(value_as<sha::Accessor>(acc));
return sha::Accessor(std::move(acc));
}
sha::Name &sha::Db::get_name(const char *str)
{
auto &db = as<base::Db>();
auto &db = as<::Db>();
db.accessed++;
return ref_as<sha::Name>(db.name);
}

View File

@ -4,10 +4,17 @@
#include <cassert>
#include <type_traits>
#include <utility>
namespace sha
{
template <class TO, class FROM>
TO value_as(FROM &&ref)
{
return std::move((*reinterpret_cast<TO *>(&ref)));
}
// Sized
class Name;
class Db;
@ -62,6 +69,20 @@ public:
assert(alignment_B == _alignment_B);
}
// This constructr also serves as a check for correctness of size and
// aligment.
template <class T>
Sized(T &&d)
: data(value_as<
typename std::aligned_storage<size_B, alignment_B>::type>(
std::move(d)))
{
static_assert(size_B == sizeof(T), "Border class size mismatch");
static_assert(alignment_B == alignof(T),
"Border class aligment mismatch");
}
protected:
template <class T>
T &as()
@ -88,17 +109,28 @@ private:
// above:
// assert(sizeof(Accessor)==sizeof(std::set<int>));
// assert(alignof(Accessor)==alignof(std::set<int>));
std::aligned_storage<size_B, alignment_B> data;
typename std::aligned_storage<size_B, alignment_B>::type data;
};
// Type which will be passed by value so it's real size matters.
class Accessor : private Sized<16, 8>
{
// The only border classes which can create this class.
friend Db;
private:
// The only valid concstructor for original class
template <class T>
Accessor(T &&d) : Sized(std::move(d))
{
}
public:
// If the underlying type can't be copyed or moved this two constructors
// would be deleted.
Accessor(const Accessor &other);
Accessor(Accessor &&other);
~Accessor();
// If the underlying type can't be copyed or moved this two operators
// would be deleted.
@ -114,7 +146,7 @@ class Name : private Unsized
};
// Type which will be passed by ref/pointer only so it's size doesnt matter.
class Db : public Unsized
class Db : private Unsized
{
public:
Accessor access();

View File

@ -151,7 +151,7 @@ void fill_with_bt(
{
auto bus_t = com.at(prop_vertex_business_types);
if (bus_t.is_present()) {
for (auto &bt : *bus_t.get()) {
for (auto &bt : bus_t.get()->value) {
values[bt] += weight;
}
}
@ -240,7 +240,7 @@ auto query(DbAccessor &t, const Id &start_id)
// cout << " type_works_in" << endl;
iter::for_all_fill(employ.out(), [&](auto employ_edge) {
// cout << " employ.out()" << endl;
auto ee_type = employ_edge.edge_type();
auto &ee_type = employ_edge.edge_type();
// cout << " ee_type: " << ee_type << endl;
if (ee_type == type_interested_in) {
@ -263,7 +263,7 @@ auto query(DbAccessor &t, const Id &start_id)
return;
}
auto str = feedback.get()->c_str();
auto str = feedback.get()->value.c_str();
double weight = 0;
if (strcasecmp(str, "like") == 0) {
weight = 1;
@ -289,7 +289,7 @@ auto query(DbAccessor &t, const Id &start_id)
if (!os.is_present()) {
return;
}
auto str = os.get()->c_str();
auto str = os.get()->value.c_str();
if (strcasecmp(str, "pending") == 0) {
weight = 0.5;
@ -306,7 +306,7 @@ auto query(DbAccessor &t, const Id &start_id)
ee_type == type_searched_and_clicked) {
auto count = employ_edge.at(prop_edge_count);
if (count.is_present()) {
weight = 0.01 * (*count.get());
weight = 0.01 * (count.get()->value);
}
}
@ -336,7 +336,7 @@ Option<Id> find_company(DbAccessor &t, int64_t cid)
.type_key<Int64>();
const Label &label_company = t.label_find_or_create("Company");
iter::find_fill(label_company.index->for_range_exact(t), [&](auto v) {
iter::find_fill(label_company.index().for_range_exact(t), [&](auto v) {
if (v.has_label(label_company)) {
auto id = v.at(prop_vertex_company_id);
if (id.is_present()) {
@ -369,7 +369,7 @@ int main(int argc, char **argv)
auto begin = clock();
int i = 0;
iter::find_fill(
t.label_find_or_create("Company").index->for_range_exact(t),
t.label_find_or_create("Company").index().for_range_exact(t),
[&](auto v) {
coll.push_back(make_pair(v, query(t, v.id())));
i++;

56
poc/size_aligment.cpp Normal file
View File

@ -0,0 +1,56 @@
#include "database/db.hpp"
#include "database/db_accessor.hpp"
#include <chrono>
#include <ctime>
#include <strings.h>
#include <unistd.h>
#include <unordered_map>
#include "database/db_accessor.cpp"
#include "import/csv_import.hpp"
#include "storage/indexes/impl/nonunique_unordered_index.cpp"
#include "storage/model/properties/properties.cpp"
#include "storage/record_accessor.cpp"
#include "storage/vertex_accessor.cpp"
#include "utils/command_line/arguments.hpp"
using namespace std;
using vertex_access_iterator =
decltype(((DbAccessor *)nullptr_t())->vertex_access());
using out_edge_iterator_t =
decltype(((VertexAccessor *)(std::nullptr_t()))->out());
using in_edge_iterator_t =
decltype(((::VertexAccessor *)(std::nullptr_t()))->in());
int main()
{
cout << "DbAccessor.vertex_access(): size: "
<< sizeof(vertex_access_iterator)
<< " aligment: " << alignof(vertex_access_iterator) << endl;
cout << "DbAccessor: size: " << sizeof(DbAccessor)
<< " aligment: " << alignof(DbAccessor) << endl;
cout << "VertexAccessor: size: " << sizeof(VertexAccessor)
<< " aligment: " << alignof(VertexAccessor) << endl;
cout << "std::unique_ptr<IteratorBase<const ::VertexAccessor>>: size: "
<< sizeof(std::unique_ptr<IteratorBase<const ::VertexAccessor>>)
<< " aligment: "
<< alignof(std::unique_ptr<IteratorBase<const ::VertexAccessor>>)
<< endl;
cout << "VertexAccessor.out(): size: " << sizeof(out_edge_iterator_t)
<< " aligment: " << alignof(out_edge_iterator_t) << endl;
cout << "VertexAccessor.in(): size: " << sizeof(in_edge_iterator_t)
<< " aligment: " << alignof(in_edge_iterator_t) << endl;
// cout << ": size: " << sizeof(void) << " aligment: " << alignof(void)
// << endl;
return 0;
}

View File

@ -0,0 +1,846 @@
#include "barrier/barrier.hpp"
// This is the place for imports from memgraph .hpp
#include "communication/bolt/v1/serialization/bolt_serializer.hpp"
#include "database/db.hpp"
#include "database/db_accessor.hpp"
#include "storage/edge_type/edge_type.hpp"
#include "storage/label/label.hpp"
// This is the place for imports from memgraph .cpp
// #include "database/db_accessor.cpp"
#include "storage/vertex_accessor.cpp"
// TODO: Extract trans functions to other hpp for easy including into other
// code.
// **************************** HELPER DEFINES *******************************//
// returns transformed pointer
#define THIS (trans(this))
// Performs call x on transformed border class.
#define HALF_CALL(x) (THIS->x)
// Performs call x on transformed border class and returns transformed output.
#define CALL(x) trans(HALF_CALL(x))
#define TRANSFORM_REF(x, y) \
x &trans(y &l) { return ref_as<x>(l); } \
const x &trans(const y &l) { return ref_as<const x>(l); } \
y &trans(x &l) { return ref_as<y>(l); } \
const y &trans(const x &l) { return ref_as<const y>(l); } \
x *trans(y *l) { return ptr_as<x>(l); } \
const x *trans(const y *l) { return ptr_as<const x>(l); } \
y *trans(x *l) { return ptr_as<y>(l); } \
const y *trans(const x *l) { return ptr_as<const y>(l); }
#define TRANSFORM_REF_TEMPLATED(x, y) \
x &trans(y &l) { return ref_as<x>(l); } \
template <class T> \
x const &trans(y const &l) \
{ \
return ref_as<const x>(l); \
} \
template <class T> \
y &trans(x &l) \
{ \
return ref_as<y>(l); \
} \
template <class T> \
y const &trans(x const &l) \
{ \
return ref_as<const y>(l); \
} \
template <class T> \
x *trans(y *l) \
{ \
return ptr_as<x>(l); \
} \
template <class T> \
const x *trans(const y *l) \
{ \
return ptr_as<const x>(l); \
} \
template <class T> \
y *trans(x *l) \
{ \
return ptr_as<y>(l); \
} \
template <class T> \
const y *trans(const x *l) \
{ \
return ptr_as<const y>(l); \
}
// #define VALID_CONSTRUCTION(x, y) \
// template <> \
// barrier::x::x(y &&d) : Sized(std::move(d)) \
// { \
// }
//
// #define VALID_CONSTRUCTION_CONST(x, y) \
// template <> \
// barrier::x::x(y const &&d) : Sized(std::move(d)) \
// { \
// }
// Generates transformation function from original class to border class.
#define TRANSFORM_VALUE_ONE_RAW(x, y) \
x trans(y &&d) { return x(std::move(d)); }
// Generates transformation function from original class to border class.
#define TRANSFORM_VALUE_ONE(x, y) \
x trans(y &&d) { return value_as<x>(std::move(d)); }
// Generates transformation functions between border class x and original class
// y by value. Only mutable values.
#define TRANSFORM_VALUE_MUT(x, y) \
TRANSFORM_VALUE_ONE(x, y) \
y trans(x &&d) { return value_as<y>(std::move(d)); }
// Generates transformation functions between border class x and original class
// y by value.
#define TRANSFORM_VALUE(x, y) \
TRANSFORM_VALUE_MUT(x, y) \
VALID_CONSTRUCTION_CONST(x, y) \
const x trans(const y &&d) { return value_as<const x>(std::move(d)); } \
const y trans(const x &&d) { return value_as<const y>(std::move(d)); }
// Duplicates given first name to call second given with name and ::name
#define DUP(x, y) y(x, ::x)
// ********************** TYPES OF AUTO
using vertex_access_iterator_t =
decltype(((::DbAccessor *)(std::nullptr_t()))->vertex_access());
using out_edge_iterator_t =
decltype(((::VertexAccessor *)(std::nullptr_t()))->out());
using in_edge_iterator_t =
decltype(((::VertexAccessor *)(std::nullptr_t()))->in());
// This file should contain all implementations of methods from barrier classes
// defined in barrier.hpp.
// Implementations should follow the form:
// border_return_type border_class::method_name(arguments){
// return
// CALL(method_name(trans(arguments)))/HALF_CALL(method_name(trans(arguments)));
// }
// ********************** ALL VALID CONVERSIONS ***************************** //
// Implementations must use exclusivly trans functions to cast between types.
// ******************** OVERLOADED trans FUNCTIONS.
// This enclosure is the only dangerous part of barrier except of Sized class in
// common.hpp
namespace barrier
{
// Blueprint for valid transformation of references:
// TRANSFORM_REF(, ::);
// template <class T> TRANSFORM_REF_TEMPLATED(<T>,::<T>);
// ***************** TRANSFORMS of reference
DUP(Label, TRANSFORM_REF);
DUP(EdgeType, TRANSFORM_REF);
DUP(VertexPropertyFamily, TRANSFORM_REF);
DUP(EdgePropertyFamily, TRANSFORM_REF);
DUP(VertexAccessor, TRANSFORM_REF);
DUP(EdgeAccessor, TRANSFORM_REF);
DUP(Db, TRANSFORM_REF);
DUP(DbAccessor, TRANSFORM_REF);
TRANSFORM_REF(std::vector<label_ref_t>, std::vector<::label_ref_t>);
TRANSFORM_REF(VertexPropertyKey,
::VertexPropertyFamily::PropertyType::PropertyFamilyKey);
TRANSFORM_REF(EdgePropertyKey,
::EdgePropertyFamily::PropertyType::PropertyFamilyKey);
TRANSFORM_REF(VertexIterator,
std::unique_ptr<IteratorBase<const ::VertexAccessor>>);
TRANSFORM_REF(EdgeIterator,
std::unique_ptr<IteratorBase<const ::EdgeAccessor>>);
TRANSFORM_REF(VertexAccessIterator, vertex_access_iterator_t);
TRANSFORM_REF(OutEdgesIterator, out_edge_iterator_t);
TRANSFORM_REF(InEdgesIterator, in_edge_iterator_t);
template <class T>
TRANSFORM_REF_TEMPLATED(VertexIndex<T>, VertexIndexBase<T>);
template <class T>
TRANSFORM_REF_TEMPLATED(EdgeIndex<T>, EdgeIndexBase<T>);
template <class T>
TRANSFORM_REF_TEMPLATED(BoltSerializer<T>, ::bolt::BoltSerializer<T>);
template <class T>
TRANSFORM_REF_TEMPLATED(
VertexPropertyType<T>,
::VertexPropertyFamily::PropertyType::PropertyTypeKey<T>);
template <class T>
TRANSFORM_REF_TEMPLATED(EdgePropertyType<T>,
::EdgePropertyFamily::PropertyType::PropertyTypeKey<T>);
// ****************** TRANSFORMS of value
// Blueprint for valid transformation of value:
// TRANSFORM_VALUE(, ::);
DUP(VertexAccessor, TRANSFORM_VALUE);
DUP(EdgeAccessor, TRANSFORM_VALUE);
TRANSFORM_VALUE(EdgePropertyKey,
::EdgePropertyFamily::PropertyType::PropertyFamilyKey);
TRANSFORM_VALUE(VertexPropertyKey,
::VertexPropertyFamily::PropertyType::PropertyFamilyKey);
TRANSFORM_VALUE_ONE(VertexAccessIterator, vertex_access_iterator_t);
TRANSFORM_VALUE_ONE(OutEdgesIterator, out_edge_iterator_t);
TRANSFORM_VALUE_ONE(InEdgesIterator, in_edge_iterator_t);
TRANSFORM_VALUE_ONE(VertexIterator,
std::unique_ptr<IteratorBase<const ::VertexAccessor>>);
template <class T>
TRANSFORM_VALUE_ONE_RAW(
VertexPropertyType<T>,
::VertexPropertyFamily::PropertyType::PropertyTypeKey<T>);
template <class T>
TRANSFORM_VALUE_ONE_RAW(EdgePropertyType<T>,
::EdgePropertyFamily::PropertyType::PropertyTypeKey<T>)
template <class T>
TRANSFORM_VALUE_ONE_RAW(BoltSerializer<T>, ::bolt::BoltSerializer<T>)
// ********************* SPECIAL SIZED CONSTRUCTORS
#define VertexPropertyType_constructor(x) \
template <> \
template <> \
VertexPropertyType<x>::VertexPropertyType( \
::VertexPropertyFamily::PropertyType::PropertyTypeKey<x> &&d) \
: Sized(std::move(d)) \
{ \
}
INSTANTIATE_FOR_PROPERTY(VertexPropertyType_constructor);
#define EdgePropertyType_constructor(x) \
template <> \
template <> \
EdgePropertyType<x>::EdgePropertyType( \
::EdgePropertyFamily::PropertyType::PropertyTypeKey<x> &&d) \
: Sized(std::move(d)) \
{ \
}
INSTANTIATE_FOR_PROPERTY(EdgePropertyType_constructor);
DbAccessor::DbAccessor(Db &db) : Sized(::DbAccessor(trans(db))) {}
}
// ************************* Implementations
namespace barrier
{
// ************************* EdgePropertyType
#define FOR_ALL_PROPS_delete_EdgePropertyType(x) \
template <> \
EdgePropertyType<x>::~EdgePropertyType() \
{ \
HALF_CALL(~PropertyTypeKey()); \
}
INSTANTIATE_FOR_PROPERTY(FOR_ALL_PROPS_delete_EdgePropertyType)
// ************************* VertexPropertyType
#define FOR_ALL_PROPS_delete_VertexPropertyType(x) \
template <> \
VertexPropertyType<x>::~VertexPropertyType() \
{ \
HALF_CALL(~PropertyTypeKey()); \
}
INSTANTIATE_FOR_PROPERTY(FOR_ALL_PROPS_delete_VertexPropertyType)
// ***************** Label
VertexIndex<std::nullptr_t> &Label::index() const
{
auto &index = HALF_CALL(index());
IndexBase<TypeGroupVertex, std::nullptr_t> &ib = index;
return trans(ib);
}
// **************** EdgeType
EdgeIndex<std::nullptr_t> &EdgeType::index() const { return CALL(index()); }
// **************** VertexIndex
template <class K>
VertexIterator VertexIndex<K>::for_range(DbAccessor &t, Border<K> from,
Border<K> to)
{
auto ret = THIS->for_range(trans(t), std::move(from), std::move(to));
VertexIterator it(std::move(ret));
return it;
}
template <class K>
bool VertexIndex<K>::unique()
{
return HALF_CALL(unique());
}
template <class K>
Order VertexIndex<K>::order()
{
return HALF_CALL(order());
}
// **************** EdgeIndex
template <class K>
EdgeIterator EdgeIndex<K>::for_range(DbAccessor &t, Border<K> from,
Border<K> to)
{
return CALL(for_range(trans(t), std::move(from), std::move(to)));
}
template <class K>
bool EdgeIndex<K>::unique()
{
return HALF_CALL(unique());
}
template <class K>
Order EdgeIndex<K>::order()
{
return HALF_CALL(order());
}
// ************************* DbAccessor
DbAccessor::~DbAccessor() { THIS->~DbAccessor(); }
VertexAccessIterator DbAccessor::vertex_access()
{
return CALL(vertex_access());
}
Option<const VertexAccessor> DbAccessor::vertex_find(const Id &id)
{
return HALF_CALL(vertex_find(id)).map<const VertexAccessor>();
}
VertexAccessor DbAccessor::vertex_insert() { return CALL(vertex_insert()); }
Option<const EdgeAccessor> DbAccessor::edge_find(const Id &id)
{
return HALF_CALL(edge_find(id)).map<const EdgeAccessor>();
}
EdgeAccessor DbAccessor::edge_insert(VertexAccessor const &from,
VertexAccessor const &to)
{
return CALL(edge_insert(trans(from), trans(to)));
}
const Label &DbAccessor::label_find_or_create(const char *name)
{
return CALL(label_find_or_create(name));
}
bool DbAccessor::label_contains(const char *name)
{
return HALF_CALL(label_contains(name));
}
const EdgeType &DbAccessor::type_find_or_create(const char *name)
{
return CALL(type_find_or_create(name));
}
bool DbAccessor::type_contains(const char *name)
{
return HALF_CALL(type_contains(name));
}
VertexPropertyFamily &
DbAccessor::vertex_property_family_get(const std::string &name)
{
return CALL(vertex_property_family_get(name));
}
EdgePropertyFamily &
DbAccessor::edge_property_family_get(const std::string &name)
{
return CALL(edge_property_family_get(name));
}
VertexPropertyKey DbAccessor::vertex_property_key(const std::string &name,
Type type)
{
return CALL(vertex_property_key(name, type));
}
EdgePropertyKey DbAccessor::edge_property_key(const std::string &name,
Type type)
{
return CALL(edge_property_key(name, type));
}
template <class T>
VertexPropertyType<T> DbAccessor::vertex_property_key(const std::string &name)
{
return CALL(vertex_property_key<T>(name));
}
#define DbAccessor_vertex_property_key(x) \
template VertexPropertyType<x> DbAccessor::vertex_property_key<x>( \
const std::string &name);
INSTANTIATE_FOR_PROPERTY(DbAccessor_vertex_property_key)
template <class T>
EdgePropertyType<T> DbAccessor::edge_property_key(const std::string &name)
{
return CALL(edge_property_key<T>(name));
}
#define DbAccessor_edge_property_key(x) \
template EdgePropertyType<x> DbAccessor::edge_property_key<x>( \
const std::string &name);
INSTANTIATE_FOR_PROPERTY(DbAccessor_edge_property_key)
bool DbAccessor::commit() { return HALF_CALL(commit()); }
void DbAccessor::abort() { HALF_CALL(abort()); }
// ************************** VertexAccessor
VertexAccessor::VertexAccessor(const VertexAccessor &other)
: Sized(::VertexAccessor(trans(other)))
{
}
VertexAccessor::VertexAccessor(VertexAccessor &&other)
: Sized(trans(std::move(other)))
{
}
VertexAccessor::VertexAccessor(VertexAccessor const &&other)
: Sized(trans(std::move(other)))
{
}
VertexAccessor::~VertexAccessor() { HALF_CALL(~VertexAccessor()); }
VertexAccessor &VertexAccessor::operator=(const VertexAccessor &other)
{
HALF_CALL(operator=(trans(other)));
return *this;
}
VertexAccessor &VertexAccessor::operator=(VertexAccessor &&other)
{
HALF_CALL(operator=(trans(std::move(other))));
return *this;
}
size_t VertexAccessor::out_degree() const { return HALF_CALL(out_degree()); }
size_t VertexAccessor::in_degree() const { return HALF_CALL(in_degree()); }
size_t VertexAccessor::degree() const { return HALF_CALL(degree()); }
bool VertexAccessor::add_label(const Label &label)
{
return HALF_CALL(add_label(trans(label)));
}
bool VertexAccessor::remove_label(const Label &label)
{
return HALF_CALL(remove_label(trans(label)));
}
bool VertexAccessor::has_label(const Label &label) const
{
return HALF_CALL(has_label(trans(label)));
}
const std::vector<label_ref_t> &VertexAccessor::labels() const
{
return CALL(labels());
}
OutEdgesIterator VertexAccessor::out() const { return CALL(out()); }
InEdgesIterator VertexAccessor::in() const { return CALL(in()); }
bool VertexAccessor::in_contains(VertexAccessor const &other) const
{
return HALF_CALL(in_contains(trans(other)));
}
bool VertexAccessor::empty() const { return HALF_CALL(empty()); }
bool VertexAccessor::fill() const { return HALF_CALL(fill()); }
const Id &VertexAccessor::id() const { return HALF_CALL(id()); }
VertexAccessor VertexAccessor::update() const { return CALL(update()); }
bool VertexAccessor::remove() const { return HALF_CALL(remove()); }
const Property &VertexAccessor::at(VertexPropertyFamily &key) const
{
return HALF_CALL(at(trans(key)));
}
const Property &VertexAccessor::at(VertexPropertyKey &key) const
{
return HALF_CALL(at(trans(key)));
}
template <class V>
OptionPtr<V> VertexAccessor::at(VertexPropertyType<V> &key) const
{
return HALF_CALL(at(trans<V>(key)));
}
#define VertexAccessor_at(x) \
template OptionPtr<x> VertexAccessor::at(VertexPropertyType<x> &key) const;
INSTANTIATE_FOR_PROPERTY(VertexAccessor_at);
// NOTE: I am not quite sure if this method will have any use
template <class V, class... Args>
void VertexAccessor::set(VertexPropertyType<V> &key, Args &&... args)
{
HALF_CALL(set(trans(key), args...));
}
void VertexAccessor::set(VertexPropertyKey &key, Property::sptr value)
{
HALF_CALL(set(trans(key), std::move(value)));
}
void VertexAccessor::clear(VertexPropertyKey &key)
{
HALF_CALL(clear(trans(key)));
}
void VertexAccessor::clear(VertexPropertyFamily &key)
{
HALF_CALL(clear(trans(key)));
}
// NOTE: I am not quite sure if this method will have any use
template <class Handler>
void VertexAccessor::accept(Handler &handler) const
{
HALF_CALL(accept(handler));
}
VertexAccessor::operator bool() const { return HALF_CALL(operator bool()); }
bool operator==(const VertexAccessor &a, const VertexAccessor &b)
{
return trans(a) == trans(b);
}
bool operator!=(const VertexAccessor &a, const VertexAccessor &b)
{
return trans(a) != trans(b);
}
// ************************** EdgeAccessor
EdgeAccessor::EdgeAccessor(const EdgeAccessor &other)
: Sized(::EdgeAccessor(trans(other)))
{
}
EdgeAccessor::EdgeAccessor(EdgeAccessor &&other)
: Sized(trans(std::move(other)))
{
}
EdgeAccessor::EdgeAccessor(EdgeAccessor const &&other)
: Sized(trans(std::move(other)))
{
}
EdgeAccessor::~EdgeAccessor() { HALF_CALL(~EdgeAccessor()); }
EdgeAccessor &EdgeAccessor::operator=(const EdgeAccessor &other)
{
HALF_CALL(operator=(trans(other)));
return *this;
}
EdgeAccessor &EdgeAccessor::operator=(EdgeAccessor &&other)
{
HALF_CALL(operator=(trans(std::move(other))));
return *this;
}
void EdgeAccessor::edge_type(const EdgeType &edge_type)
{
HALF_CALL(edge_type(trans(edge_type)));
}
const EdgeType &EdgeAccessor::edge_type() const { return CALL(edge_type()); }
const VertexAccessor EdgeAccessor::from() const { return CALL(from()); }
const VertexAccessor EdgeAccessor::to() const { return CALL(to()); }
bool EdgeAccessor::empty() const { return HALF_CALL(empty()); }
bool EdgeAccessor::fill() const { return HALF_CALL(fill()); }
const Id &EdgeAccessor::id() const { return HALF_CALL(id()); }
EdgeAccessor EdgeAccessor::update() const { return CALL(update()); }
bool EdgeAccessor::remove() const { return HALF_CALL(remove()); }
const Property &EdgeAccessor::at(EdgePropertyFamily &key) const
{
return HALF_CALL(at(trans(key)));
}
const Property &EdgeAccessor::at(EdgePropertyKey &key) const
{
return HALF_CALL(at(trans(key)));
}
template <class V>
OptionPtr<V> EdgeAccessor::at(EdgePropertyType<V> &key) const
{
return HALF_CALL(at(trans<V>(key)));
}
#define EdgeAccessor_at(x) \
template OptionPtr<x> EdgeAccessor::at(EdgePropertyType<x> &key) const;
INSTANTIATE_FOR_PROPERTY(EdgeAccessor_at);
// NOTE: I am not quite sure if this method will have any use
template <class V, class... Args>
void EdgeAccessor::set(EdgePropertyType<V> &key, Args &&... args)
{
HALF_CALL(set(trans(key), args...));
}
void EdgeAccessor::set(EdgePropertyKey &key, Property::sptr value)
{
HALF_CALL(set(trans(key), std::move(value)));
}
void EdgeAccessor::clear(EdgePropertyKey &key) { HALF_CALL(clear(trans(key))); }
void EdgeAccessor::clear(EdgePropertyFamily &key)
{
HALF_CALL(clear(trans(key)));
}
// NOTE: I am not quite sure if this method will have any use
template <class Handler>
void EdgeAccessor::accept(Handler &handler) const
{
HALF_CALL(accept(handler));
}
EdgeAccessor::operator bool() const { return HALF_CALL(operator bool()); }
bool operator==(const EdgeAccessor &a, const EdgeAccessor &b)
{
return trans(a) == trans(b);
}
bool operator!=(const EdgeAccessor &a, const EdgeAccessor &b)
{
return trans(a) != trans(b);
}
// ************************* VertexIterator
VertexIterator::VertexIterator(VertexIterator &&other)
: Sized(std::unique_ptr<IteratorBase<const ::VertexAccessor>>(nullptr))
{
*THIS = value_as<std::unique_ptr<IteratorBase<const ::VertexAccessor>>>(
std::move(other));
}
VertexIterator::~VertexIterator() { HALF_CALL(~unique_ptr()); }
Option<const VertexAccessor> VertexIterator::next()
{
return HALF_CALL(get()->next()).map<const VertexAccessor>();
}
// ************************* EdgeIterator
// TODO : change
EdgeIterator::EdgeIterator(EdgeIterator &&other)
: Sized(std::unique_ptr<IteratorBase<const ::EdgeAccessor>>(nullptr))
{
*THIS = value_as<std::unique_ptr<IteratorBase<const ::EdgeAccessor>>>(
std::move(other));
}
EdgeIterator::~EdgeIterator() { HALF_CALL(~unique_ptr()); }
Option<const EdgeAccessor> EdgeIterator::next()
{
return HALF_CALL(get()->next()).map<const EdgeAccessor>();
}
// ************************* OutEdgesIterator
OutEdgesIterator::OutEdgesIterator(OutEdgesIterator &&other)
: Sized(trans(std::move(other)))
{
}
OutEdgesIterator::~OutEdgesIterator() { HALF_CALL(~out_edge_iterator_t()); }
Option<const EdgeAccessor> OutEdgesIterator::next()
{
return HALF_CALL(next()).map<const EdgeAccessor>();
}
// ************************* InEdgesIterator
InEdgesIterator::InEdgesIterator(InEdgesIterator &&other)
: Sized(trans(std::move(other)))
{
}
InEdgesIterator::~InEdgesIterator() { HALF_CALL(~in_edge_iterator_t()); }
Option<const EdgeAccessor> InEdgesIterator::next()
{
return HALF_CALL(next()).map<const EdgeAccessor>();
}
// ************************* VertexAccessIterator
VertexAccessIterator::VertexAccessIterator(VertexAccessIterator &&other)
: Sized(trans(std::move(other)))
{
}
VertexAccessIterator::~VertexAccessIterator()
{
HALF_CALL(~vertex_access_iterator_t());
}
Option<const VertexAccessor> VertexAccessIterator::next()
{
return HALF_CALL(next()).map<const VertexAccessor>();
}
// ************************* VertexPropertyKey
VertexPropertyKey::~VertexPropertyKey() { HALF_CALL(~PropertyFamilyKey()); }
// ************************* EdgePropertyKey
EdgePropertyKey::~EdgePropertyKey() { HALF_CALL(~PropertyFamilyKey()); }
// ************************* VertexPropertyFamily
OptionPtr<VertexIndex<std::nullptr_t>> VertexPropertyFamily::index()
{
OptionPtr<IndexBase<TypeGroupVertex, std::nullptr_t>> ret =
THIS->index.get_read();
if (ret.is_present()) {
return OptionPtr<VertexIndex<std::nullptr_t>>(&trans(*ret.get()));
} else {
return OptionPtr<VertexIndex<std::nullptr_t>>();
}
}
// ************************* VertexPropertyFamily
OptionPtr<EdgeIndex<std::nullptr_t>> EdgePropertyFamily::index()
{
OptionPtr<IndexBase<TypeGroupEdge, std::nullptr_t>> ret =
THIS->index.get_read();
if (ret.is_present()) {
return OptionPtr<EdgeIndex<std::nullptr_t>>(&trans(*ret.get()));
} else {
return OptionPtr<EdgeIndex<std::nullptr_t>>();
}
}
// ************************* BOLT SERIALIZER
template <class Stream>
BoltSerializer<Stream>::~BoltSerializer()
{
THIS->~BoltSerializer();
}
template <class Stream>
void BoltSerializer<Stream>::write(const VertexAccessor &vertex)
{
HALF_CALL(write(trans(vertex)));
}
template <class Stream>
void BoltSerializer<Stream>::write(const EdgeAccessor &edge)
{
HALF_CALL(write(trans(edge)));
}
template <class Stream>
void BoltSerializer<Stream>::write(const Property &prop)
{
HALF_CALL(write(prop));
}
template <class Stream>
void BoltSerializer<Stream>::write_null()
{
HALF_CALL(write_null());
}
template <class Stream>
void BoltSerializer<Stream>::write(const Bool &prop)
{
HALF_CALL(write(prop));
}
template <class Stream>
void BoltSerializer<Stream>::write(const Float &prop)
{
HALF_CALL(write(prop));
}
template <class Stream>
void BoltSerializer<Stream>::write(const Double &prop)
{
HALF_CALL(write(prop));
}
template <class Stream>
void BoltSerializer<Stream>::write(const Int32 &prop)
{
HALF_CALL(write(prop));
}
template <class Stream>
void BoltSerializer<Stream>::write(const Int64 &prop)
{
HALF_CALL(write(prop));
}
template <class Stream>
void BoltSerializer<Stream>::write(const std::string &value)
{
HALF_CALL(write(value));
}
template <class Stream>
void BoltSerializer<Stream>::write(const String &prop)
{
HALF_CALL(write(prop));
}
template <class Stream>
template <class T>
void BoltSerializer<Stream>::handle(const T &prop)
{
HALF_CALL(template handle<T>(prop));
}
}
// **************************** ERROR EXAMPLES ****************************** //
// **************************** COMPILE TIME
/*
error:
../libmemgraph.a(barrier.cpp.o): In function `Option<barrier::VertexAccessor
const> Option<VertexAccessor const>::map<barrier::VertexAccessor const>()':
/home/ktf/Workspace/memgraph/include/utils/option.hpp:111: undefined reference
to `barrier::VertexAccessor::VertexAccessor<VertexAccessor const>(VertexAccessor
const&&)'
description:
Constructor VertexAccessor<::VertexAccessor const>(::VertexAccessor const&&)
isn't written.
error:
../libmemgraph.a(barrier.cpp.o): In function `barrier::EdgeAccessor::from()
const':
/home/ktf/Workspace/memgraph/src/barrier/barrier.cpp:501: undefined reference to
`barrier::VertexAccessor::VertexAccessor<barrier::VertexAccessor
const>(barrier::VertexAccessor const&&)'
description:
Move constructor VertexAccessor<VertexAccessor const>(VertexAccessor const&&)
isn't defined.
*/

View File

@ -1,3 +1,5 @@
#pragma once
#include "database/db.hpp"
#include "database/db_accessor.hpp"
#include "utils/iterator/iterator.hpp"
@ -13,14 +15,7 @@ DbAccessor::DbAccessor(Db &db, tx::Transaction &t)
}
// VERTEX METHODS
auto DbAccessor::vertex_access()
{
return iter::make_map(
iter::make_iter(this->db_transaction.db.graph.vertices.access()),
[&](auto e) -> auto {
return VertexAccessor(&(e->second), db_transaction);
});
}
// auto DbAccessor::vertex_access()
Option<const VertexAccessor> DbAccessor::vertex_find(const Id &id)
{
@ -98,20 +93,6 @@ DbAccessor::edge_property_key(const std::string &name, Type type)
return edge_property_family_get(name).get(type).family_key();
}
template <class T>
VertexPropertyFamily::PropertyType::PropertyTypeKey<T>
DbAccessor::vertex_property_key(const std::string &name)
{
return vertex_property_family_get(name).get(T::type).template type_key<T>();
}
template <class T>
EdgePropertyFamily::PropertyType::PropertyTypeKey<T>
DbAccessor::edge_property_key(const std::string &name)
{
return edge_property_family_get(name).get(T::type).template type_key<T>();
}
// TRANSACTION METHODS
bool DbAccessor::commit()
{

View File

@ -38,7 +38,7 @@ bool DbTransaction::update_indexes()
// TODO: This could be done in batch
// NOTE: This assumes that type index is created with the database.
TRY(e.record->data.edge_type->index->insert(
TRY(e.record->data.edge_type->index().insert(
EdgeTypeIndexRecord(std::nullptr_t(), e.record, e.vlist)));
TRY(update_property_indexes<TypeGroupEdge>(e, trans));
@ -50,7 +50,7 @@ bool DbTransaction::update_indexes()
// TODO: This could be done in batch
// NOTE: This assumes that label index is created with the
// database.
TRY(l.get().index->insert(
TRY(l.get().index().insert(
LabelIndexRecord(std::nullptr_t(), v.record, v.vlist)));
}

View File

@ -1,22 +1,22 @@
#include "storage/edge_accessor.hpp"
void EdgeAccessor::edge_type(edge_type_ref_t edge_type)
void EdgeAccessor::edge_type(const EdgeType &edge_type)
{
this->record->data.edge_type = &edge_type.get();
this->record->data.edge_type = &edge_type;
}
edge_type_ref_t EdgeAccessor::edge_type() const
const EdgeType &EdgeAccessor::edge_type() const
{
runtime_assert(this->record->data.edge_type != nullptr, "EdgeType is null");
return edge_type_ref_t(*this->record->data.edge_type);
return *this->record->data.edge_type;
}
VertexAccessor EdgeAccessor::from() const
const VertexAccessor EdgeAccessor::from() const
{
return VertexAccessor(this->vlist->from(), this->db);
}
VertexAccessor EdgeAccessor::to() const
const VertexAccessor EdgeAccessor::to() const
{
return VertexAccessor(this->vlist->to(), this->db);
}

View File

@ -1,17 +1,17 @@
#include "storage/edge_type/edge_type.hpp"
EdgeType::EdgeType(const std::string &id)
: id(id), index(std::unique_ptr<type_index_t>(new type_index_t()))
: id(id), index_v(std::unique_ptr<type_index_t>(new type_index_t()))
{
}
EdgeType::EdgeType(const char *id)
: id(std::string(id)),
index(std::unique_ptr<type_index_t>(new type_index_t()))
index_v(std::unique_ptr<type_index_t>(new type_index_t()))
{
}
EdgeType::EdgeType(std::string &&id)
: id(std::move(id)),
index(std::unique_ptr<type_index_t>(new type_index_t()))
index_v(std::unique_ptr<type_index_t>(new type_index_t()))
{
}
@ -31,3 +31,5 @@ std::ostream &operator<<(std::ostream &stream, const EdgeType &type)
}
EdgeType::operator const std::string &() const { return id; }
EdgeType::type_index_t &EdgeType::index() const { return *index_v.get(); }

View File

@ -1,5 +1,7 @@
#include "storage/indexes/impl/unique_ordered_index.hpp"
#include "database/db.hpp"
#include "database/db_accessor.hpp"
#include "database/db_transaction.hpp"
#include "storage/edge_accessor.hpp"
@ -30,7 +32,7 @@ UniqueOrderedIndex<T, K>::UniqueOrderedIndex(Order order,
template <class T, class K>
bool UniqueOrderedIndex<T, K>::insert(IndexRecord<T, K> &&value)
{
if (this->order == Descending) {
if (this->order() == Descending) {
value.set_descending();
}
return set.access().insert(std::move(value)).second;
@ -54,13 +56,13 @@ auto UniqueOrderedIndex<T, K>::for_range_exact(DbAccessor &t_v,
auto end = to_v;
// Sorted order must be checked
if (this->order == Ascending && from_v.key.is_present()) {
if (this->order() == Ascending && from_v.key.is_present()) {
begin = acc.cfind_or_larger(from_v);
} else if (this->order == Descending && to_v.key.is_present()) {
} else if (this->order() == Descending && to_v.key.is_present()) {
begin = acc.cfind_or_larger(to_v);
end = from_v;
} else {
assert(this->order != None);
assert(this->order() != None);
}
return iter::make_iterator([

View File

@ -6,13 +6,13 @@
template <class TG, class K>
IndexBase<TG, K>::IndexBase(bool unique, Order order)
: unique(unique), order(order), created(Id(0)), active(true)
: _unique(unique), _order(order), created(Id(0)), active(true)
{
}
template <class TG, class K>
IndexBase<TG, K>::IndexBase(bool unique, Order order, const tx::Transaction &t)
: unique(unique), order(order), created(t.id)
: _unique(unique), _order(order), created(t.id)
{
}

View File

@ -3,7 +3,7 @@
Label::Label(const char *name)
: name(std::string(name)),
index(std::unique_ptr<label_index_t>(new label_index_t()))
index_v(std::unique_ptr<label_index_t>(new label_index_t()))
{
}
@ -33,3 +33,5 @@ std::ostream &operator<<(std::ostream &stream, const Label &label)
}
Label::operator const std::string &() const { return name; }
Label::label_index_t &Label::index() const { return *index_v.get(); }

View File

@ -12,28 +12,43 @@ auto LabelCollection::cend() const { return _labels.end(); }
bool LabelCollection::add(const Label &label)
{
return _labels.insert(label_ref_t(label)).second;
if (has(label)) {
return false;
} else {
_labels.push_back(label_ref_t(label));
return true;
}
// return _labels.(label_ref_t(label)).second;
}
bool LabelCollection::has(const Label &label) const
{
return _labels.count(label);
for (auto l : _labels) {
if (l == label) {
return true;
}
}
return false;
}
size_t LabelCollection::count() const { return _labels.size(); }
bool LabelCollection::remove(const Label &label)
{
auto it = _labels.find(label);
auto end = _labels.end();
for (auto it = _labels.begin(); it != end; it++) {
if (*it == label) {
_labels.erase(it);
return true;
}
}
if (it == _labels.end()) return false;
return _labels.erase(it), true;
return false;
}
void LabelCollection::clear() { _labels.clear(); }
const std::set<label_ref_t> &LabelCollection::operator()() const
const std::vector<label_ref_t> &LabelCollection::operator()() const
{
return _labels;
}

View File

@ -33,39 +33,6 @@ const Property &Properties<TG>::at(prop_key_t &key) const
return *it->second.get();
}
template <class TG>
template <class T>
auto Properties<TG>::at(type_key_t<T> &key) const
{
auto f_key = key.family_key();
auto it = props.find(f_key);
if (it == props.end() || it->first.prop_type() != key.prop_type())
return Option<decltype(
&(it->second.get()->template as<T>().value_ref()))>();
return make_option(&(it->second.get()->template as<T>().value_ref()));
}
template <class TG>
template <class T, class... Args>
void Properties<TG>::set(type_key_t<T> &key, Args &&... args)
{
auto value = std::make_shared<T>(std::forward<Args>(args)...);
// try to emplace the item
// TODO: There is uneccesary copying of value here.
auto result = props.emplace(std::make_pair(key, value));
if (!result.second) {
// It is necessary to change key because the types from before and now
// could be different.
prop_key_t &key_ref = const_cast<prop_key_t &>(result.first->first);
key_ref = key;
result.first->second = std::move(value);
}
}
template <class TG>
void Properties<TG>::set(prop_key_t &key, Property::sptr value)
{

View File

@ -1,3 +1,5 @@
#pragma once
#include "storage/vertex_accessor.hpp"
#include "database/db.hpp"
@ -34,7 +36,7 @@ bool VertexAccessor::has_label(const Label &label) const
return this->record->data.labels.has(label);
}
const std::set<label_ref_t> &VertexAccessor::labels() const
const std::vector<label_ref_t> &VertexAccessor::labels() const
{
return this->record->data.labels();
}

View File

@ -1,4 +1,9 @@
#include "query_engine/hardcode/queries.hpp"
#include "barrier/barrier.cpp"
#include "database/db.hpp"
#include "query_engine/query_stripper.hpp"
#include "storage/edges.cpp"
#include "storage/edges.hpp"
#include "storage/vertices.cpp"
@ -9,7 +14,7 @@ int main(void)
{
Db db;
auto query_functions = load_queries(db);
auto query_functions = load_queries(barrier::trans(db));
auto stripper = make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL);

View File

@ -1,6 +1,11 @@
#include <iostream>
#include "query_engine/hardcode/queries.hpp"
#include "barrier/barrier.cpp"
#include "database/db.hpp"
#include "query_engine/query_stripper.hpp"
#include "storage/edges.cpp"
#include "storage/edges.hpp"
#include "storage/vertices.cpp"
@ -11,7 +16,7 @@ using namespace std;
int main(int argc, char **argv)
{
Db db;
auto queries = load_queries(db);
auto queries = load_queries(barrier::trans(db));
// auto arguments = all_arguments(argc, argv);
// auto input_query = extract_query(arguments);