memgraph/include/storage/indexes/index_record.hpp
Kruno Tomola Fabro b2ce3d58a4 Added cleaner.
Added multithreading to dbms.
Skiplist now supports emplace insert.
2016-08-30 00:45:07 +01:00

69 lines
1.7 KiB
C++

#pragma once
#include "mvcc/id.hpp"
#include "utils/border.hpp"
#include "utils/total_ordering.hpp"
namespace tx
{
class Transaction;
}
class DbTransaction;
// TG type group
// K key on which record is ordered.
template <class TG, class K>
class IndexRecord : public TotalOrdering<IndexRecord<TG, K>>,
public TotalOrdering<Border<K>, IndexRecord<TG, K>>
{
public:
IndexRecord() = default;
IndexRecord(K key, typename TG::record_t *record,
typename TG::vlist_t *vlist);
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)) ^
lhs.descending;
}
friend bool operator==(const IndexRecord &lhs, const IndexRecord &rhs)
{
return lhs.key == rhs.key &&
(lhs.vlist != rhs.vlist || lhs.record == rhs.record);
}
friend bool operator<(const Border<K> &lhs, const IndexRecord &rhs)
{
return lhs < rhs.key;
}
friend bool operator==(const Border<K> &lhs, const IndexRecord &rhs)
{
return lhs == rhs.key;
}
// Will change ordering of record to descending.
void set_descending();
bool empty() const;
bool is_valid(tx::Transaction &t) const;
// True if it can be removed.
bool to_clean(const Id &oldest_active) const;
// This method is valid only if is_valid is true.
const auto access(DbTransaction &db) const;
const K key;
private:
bool descending = false;
typename TG::record_t *const record{nullptr};
typename TG::vlist_t *const vlist{nullptr};
};