memgraph/src/storage/indexes/index.hpp

49 lines
1.2 KiB
C++
Raw Normal View History

2016-01-02 19:20:51 +08:00
#pragma once
#include "data_structures/skiplist/skiplist.hpp"
#include "keys/unique_key.hpp"
#include "storage/cursor.hpp"
2016-01-09 21:43:55 +08:00
template <class Key, class Item>
2016-01-02 19:20:51 +08:00
class Index
{
public:
2016-01-02 19:20:51 +08:00
using skiplist_t = SkipList<Key, Item*>;
using iterator_t = typename skiplist_t::Iterator;
using accessor_t = typename skiplist_t::Accessor;
using K = typename Key::key_t;
2016-01-09 21:43:55 +08:00
using cursor_t = Cursor<accessor_t, iterator_t, K>;
// cursor_t insert(const K& key, Item* item, tx::Transaction& t)
auto insert(const K& key, Item* item)
2016-01-02 19:20:51 +08:00
{
// Item has to be some kind of container for the real data like Vertex,
// the container has to be transactionally aware
// in other words index or something that wraps index has to be
// transactionally aware
2016-01-09 21:43:55 +08:00
auto accessor = skiplist.access();
auto result = accessor.insert_unique(key, item);
2016-01-02 19:20:51 +08:00
// TODO: handle existing insert
return result;
}
auto remove(const K& key)
{
auto accessor = skiplist.access();
return accessor.remove(key);
2016-01-02 19:20:51 +08:00
}
auto find(const K& key)
{
auto accessor = skiplist.access();
return accessor.find(key);
}
2016-01-02 19:20:51 +08:00
private:
skiplist_t skiplist;
};