Last active
December 29, 2015 04:59
-
-
Save aozturk/7619006 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rocksdb::Slice key1 = "1"; | |
rocksdb::Slice key2 = "2"; | |
rocksdb::Slice key3 = "3"; | |
std::string val1 = "one"; | |
std::string val2 = "two"; | |
std::string val3 = "three"; | |
// populate the database with entries | |
db->Put(rocksdb::WriteOptions(), key1, val1); | |
db->Put(rocksdb::WriteOptions(), key2, val2); | |
db->Put(rocksdb::WriteOptions(), key3, val3); | |
// create new iterator | |
rocksdb::Iterator* it = db->NewIterator(rocksdb::ReadOptions()); | |
// iterate all entries | |
for (it->SeekToFirst(); it->Valid(); it->Next()) { | |
cout << it->key().ToString() << ": " << it->value().ToString() << endl; | |
} | |
assert(it->status().ok()); // check for any errors found during the scan | |
cout << "---" << endl; // separator | |
// iterate entries within range [start, end) | |
for (it->Seek(key2); it->Valid() && it->key().ToString() < key3.ToString(); | |
it->Next()) { | |
cout << it->key().ToString() << ": " << it->value().ToString() << endl; | |
} | |
cout << "---" << endl; // separator | |
// iterate all in reverse order | |
for (it->SeekToLast(); it->Valid(); it->Prev()) { | |
cout << it->key().ToString() << ": " << it->value().ToString() << endl; | |
} | |
// destroy iterator object | |
delete it; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment