I'm currently using a RocksDB database for a personal project and I try to get all the content in reverse order of my database which is indexed by a prefix. However I don't manage to find the good code for my loop. I fell like I'm missing something. Here is my code :
//My iterator is already created with the rocksdb::ReadOptions()
rocksdb::Slice key{reinterpret_cast<const char *>(indexToFind), sizeof(indexToFind};
std::vector<int> ids;
it->SeekForPrev(key);
auto currentKey = it->key();
while(it->Valid() && it->key().starts_with(key)) {
/* Some custom treatment here */
it->SeekForPrev(it->key());
it->Prev();
currentKey = it->key();
}
if (!it->status().ok()) {
std::cout << it->status().ToString() << std::endl;
}
assert(it->status().ok()); // Check for any errors found during the scan
Cheers and thanks in advance, Clément.