memgraph/include/storage/indexes/index_record.hpp
Kruno Tomola Fabro 5a42e15c4a Alpha version of label indexes.
Squashed messages from 9 commits:

9.
Properties now uses PropertyFamily and contained classes.
Fetching,seting,clearing properties can be done with PropertyFamilyKey or PropertyTypeKey.
Hierarchy of newly added clases is:
Vertices -n-> PropertyFamily {name: String} <-1-n-> PropertyType {type: Property::Flags}
Edges -n-> PropertyFamily {name: String} <-1-n-> PropertyType {type: Property::Flags}

PropertyFamilyKey -> PropertyType
PropertyTypeKey -> PropertyType

PropertyType t0,t1;
let t0!=t1 be true
let t0.family==t1.family be true

then next is true
PropertyTypeKey{&t0}!=PropertyTypeKey{&t1}
PropertyFamilyKey{&t0}==PropertyFamilyKey{&t1}
PropertyFamilyKey{&t0}==PropertyTypeKey{&t1}
PropertyTypeKey{&t0}==PropertyFamilyKey{&t1}

8.
Intermedate commit.
Noticed that integration queries throw SEGFAULT.

7.
Defined interface for indexes.
Fixed three memory leaks.
Fixed integration_queries test which now passes.

6.
Commit which return Xorshift128plus to valid shape.

5.
Tmp commit.

4.
Label Index is compiling.

3.
tmp

2.
Vertex::Accessor now updates Label index.

1.
Applied changes for code review.
2016-08-18 15:34:36 +01:00

68 lines
1.5 KiB
C++

#pragma once
#include "database/db_transaction.hpp"
#include "mvcc/version_list.hpp"
#include "utils/total_ordering.hpp"
// class DbTransaction;
// namespace tx
// {
// class Transaction;
// }
// T type of record.
// K key on which record is ordered.
template <class T, class K>
class IndexRecord : public TotalOrdering<IndexRecord<T, K>>
{
public:
using vlist_t = mvcc::VersionList<T>;
IndexRecord() = default;
IndexRecord(K key, T *record, vlist_t *vlist)
: key(std::move(key)), record(record), vlist(vlist)
{
assert(record != nullptr);
assert(vlist != nullptr);
}
friend bool operator<(const IndexRecord &lhs, const IndexRecord &rhs)
{
return lhs.key < rhs.key ||
(lhs.key == rhs.key && lhs.vlist == rhs.vlist &&
lhs.record < rhs.record);
}
friend bool operator==(const IndexRecord &lhs, const IndexRecord &rhs)
{
return lhs.key == rhs.key &&
(lhs.vlist != rhs.vlist || lhs.record == rhs.record);
}
bool empty() const { return record == nullptr; }
bool is_valid(tx::Transaction &t) const
{
assert(!empty());
return record == vlist->find(t);
}
const auto access(DbTransaction &db) const
{
return T::Accessor::create(record, vlist, db);
}
const K key;
private:
T *const record{nullptr};
vlist_t *const vlist{nullptr};
};
template <class K>
using VertexIndexRecord = IndexRecord<Vertex, K>;
template <class K>
using EdgeIndexRecord = IndexRecord<Edge, K>;