Reverse iteration indexed by prefix RocksDb
Clash Royale CLAN TAG#URR8PPP
Reverse iteration indexed by prefix RocksDb
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 keyreinterpret_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.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.