Skip to content

Commit

Permalink
Add doubly-linked skip list implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Zhang <[email protected]>
  • Loading branch information
v01dstar committed Sep 24, 2024
1 parent 1570d85 commit dfec84a
Show file tree
Hide file tree
Showing 6 changed files with 1,288 additions and 49 deletions.
5 changes: 5 additions & 0 deletions db/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3820,6 +3820,11 @@ size_t rocksdb_options_get_memtable_huge_page_size(rocksdb_options_t* opt) {
return opt->rep.memtable_huge_page_size;
}

void rocksdb_options_set_doubly_skip_list_rep(rocksdb_options_t* opt) {
rocksdb::MemTableRepFactory* factory = new rocksdb::DoublySkipListFactory();
opt->rep.memtable_factory.reset(factory);
}

void rocksdb_options_set_hash_skip_list_rep(rocksdb_options_t* opt,
size_t bucket_count,
int32_t skiplist_height,
Expand Down
2 changes: 2 additions & 0 deletions include/rocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,8 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_set_hash_skip_list_rep(
rocksdb_options_t*, size_t, int32_t, int32_t);
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_hash_link_list_rep(
rocksdb_options_t*, size_t);
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_doubly_skip_list_rep(
rocksdb_options_t* opt);
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_plain_table_factory(
rocksdb_options_t*, uint32_t, int, double, size_t, size_t, char,
unsigned char, unsigned char);
Expand Down
21 changes: 21 additions & 0 deletions include/rocksdb/memtablerep.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,27 @@ class SkipListFactory : public MemTableRepFactory {
size_t lookahead_;
};

// This uses a doubly skip list to store keys, which is similar to skip list,
// but optimize for prev seek.
class DoublySkipListFactory : public MemTableRepFactory {
public:
explicit DoublySkipListFactory(size_t lookahead = 0)
: lookahead_(lookahead) {}

using MemTableRepFactory::CreateMemTableRep;
virtual MemTableRep* CreateMemTableRep(const MemTableRep::KeyComparator&,
Allocator*, const SliceTransform*,
Logger* logger) override;
const char* Name() const override { return "DoublySkipListFactory"; }

bool IsInsertConcurrentlySupported() const override { return true; }

bool CanHandleDuplicatedKey() const override { return true; }

private:
size_t lookahead_;
};

// This creates MemTableReps that are backed by an std::vector. On iteration,
// the vector is sorted. This is useful for workloads where iteration is very
// rare and writes are generally not issued after reads begin.
Expand Down
Loading

0 comments on commit dfec84a

Please sign in to comment.