From a7875272d7c9c10a176fb02b12e7ed83a6ccbf70 Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Tue, 8 Nov 2016 12:36:05 -0800 Subject: [PATCH] c: support seek_for_prev Summary: support seek_for_prev in c abi. Closes https://github.com/facebook/rocksdb/pull/1457 Differential Revision: D4135360 Pulled By: lightmark fbshipit-source-id: 61256b0 --- db/c.cc | 5 +++++ db/c_test.c | 4 ++++ include/rocksdb/c.h | 3 +++ 3 files changed, 12 insertions(+) diff --git a/db/c.cc b/db/c.cc index cbc77e546..4118819e4 100644 --- a/db/c.cc +++ b/db/c.cc @@ -1031,6 +1031,11 @@ void rocksdb_iter_seek(rocksdb_iterator_t* iter, const char* k, size_t klen) { iter->rep->Seek(Slice(k, klen)); } +void rocksdb_iter_seek_for_prev(rocksdb_iterator_t* iter, const char* k, + size_t klen) { + iter->rep->SeekForPrev(Slice(k, klen)); +} + void rocksdb_iter_next(rocksdb_iterator_t* iter) { iter->rep->Next(); } diff --git a/db/c_test.c b/db/c_test.c index 5bc8bc8a0..75cb7d5eb 100644 --- a/db/c_test.c +++ b/db/c_test.c @@ -495,6 +495,10 @@ int main(int argc, char** argv) { CheckIter(iter, "foo", "hello"); rocksdb_iter_seek(iter, "b", 1); CheckIter(iter, "box", "c"); + rocksdb_iter_seek_for_prev(iter, "g", 1); + CheckIter(iter, "foo", "hello"); + rocksdb_iter_seek_for_prev(iter, "box", 3); + CheckIter(iter, "box", "c"); rocksdb_iter_get_error(iter, &err); CheckNoError(err); rocksdb_iter_destroy(iter); diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index b17917098..e5b859ce6 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -347,6 +347,9 @@ extern ROCKSDB_LIBRARY_API void rocksdb_iter_seek_to_first(rocksdb_iterator_t*); extern ROCKSDB_LIBRARY_API void rocksdb_iter_seek_to_last(rocksdb_iterator_t*); extern ROCKSDB_LIBRARY_API void rocksdb_iter_seek(rocksdb_iterator_t*, const char* k, size_t klen); +extern ROCKSDB_LIBRARY_API void rocksdb_iter_seek_for_prev(rocksdb_iterator_t*, + const char* k, + size_t klen); extern ROCKSDB_LIBRARY_API void rocksdb_iter_next(rocksdb_iterator_t*); extern ROCKSDB_LIBRARY_API void rocksdb_iter_prev(rocksdb_iterator_t*); extern ROCKSDB_LIBRARY_API const char* rocksdb_iter_key(