#include "rocksdb/memtablerep.h"
#include "db/memtable.h"
#include "db/skiplist.h"
namespace
rocksdb {
namespace
{
class
SkipListRep :
public
MemTableRep {
SkipList<
const
char
*, MemTableRep::KeyComparator&> skip_list_;
public
:
explicit
SkipListRep(MemTableRep::KeyComparator& compare, Arena* arena)
: skip_list_(compare, arena) {
}
virtual
void
Insert(
const
char
* key) override {
skip_list_.Insert(key);
}
virtual
bool
Contains(
const
char
* key)
const
override {
return
skip_list_.Contains(key);
}
virtual
size_t
ApproximateMemoryUsage() override {
return
0;
}
virtual
~SkipListRep() override { }
class
Iterator :
public
MemTableRep::Iterator {
SkipList<
const
char
*, MemTableRep::KeyComparator&>::Iterator iter_;
public
:
explicit
Iterator(
const
SkipList<
const
char
*, MemTableRep::KeyComparator&>* list
) : iter_(list) { }
virtual
~Iterator() override { }
virtual
bool
Valid()
const
override {
return
iter_.Valid();
}
virtual
const
char
* key()
const
override {
return
iter_.key();
}
virtual
void
Next() override {
iter_.Next();
}
virtual
void
Prev() override {
iter_.Prev();
}
virtual
void
Seek(
const
char
* target) override {
iter_.Seek(target);
}
virtual
void
SeekToFirst() override {
iter_.SeekToFirst();
}
virtual
void
SeekToLast() override {
iter_.SeekToLast();
}
};
using
MemTableRep::GetIterator;
virtual
std::shared_ptr<MemTableRep::Iterator> GetIterator() override {
return
std::make_shared<SkipListRep::Iterator>(&skip_list_);
}
};
}
std::shared_ptr<MemTableRep> SkipListFactory::CreateMemTableRep (
MemTableRep::KeyComparator& compare, Arena* arena) {
return
std::shared_ptr<MemTableRep>(
new
SkipListRep(compare, arena));
}
}