From 70859515efd460686dd9ae34b0c8617f9fc330d2 Mon Sep 17 00:00:00 2001 From: Ashwin <ashwin2007ray@gmail.com> Date: Mon, 8 Feb 2016 02:58:01 +1100 Subject: [PATCH] Made key and value generic (still to be done in merge.cc) --- tools/merge/merge.cc | 6 +++--- tools/merge/merge_heap.cc | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/merge/merge.cc b/tools/merge/merge.cc index 6d20e8e8..52d31003 100644 --- a/tools/merge/merge.cc +++ b/tools/merge/merge.cc @@ -64,12 +64,12 @@ int main(int argc, char* argv[]) { rocksdb::Iterator* it = cur_db->NewIterator(rocksdb::ReadOptions()); for (it->SeekToFirst(); it->Valid(); it->Next()) { - std::string key_s = it->key().ToString(); - std::string val_s = it->value().ToString(); + Slice key_s = it->key(); + Slice val_s = it->value(); std::string val_t; Status s = db->Get(ReadOptions(), key_s, &val_t); if(s.ok()) { - assert(val_t == val_s && "Same key has different value"); + assert(val_t == val_s.ToString() && "Same key has different value"); } else { s = db->Put(WriteOptions(), key_s, val_s); assert(s.ok()); diff --git a/tools/merge/merge_heap.cc b/tools/merge/merge_heap.cc index d89a28a6..121b3931 100644 --- a/tools/merge/merge_heap.cc +++ b/tools/merge/merge_heap.cc @@ -33,10 +33,10 @@ namespace fs = std::experimental::filesystem; class node { public: - std::string key; - std::string value; + Slice key; + Slice value; int idx; - node(std::string k, std::string v, int id) { + node(Slice k, Slice v, int id) { key = k; value = v; idx = id; @@ -46,14 +46,14 @@ public: class compare { public: bool operator()(node &a, node &b) { - return a.key < b.key; + return a.key.compare(b.key) <= 0; } }; int main(int argc, char* argv[]) { if(argc != 3) { std::cerr << "Wrong number of arguments\nusage : ./<executable>\ - <folder_having_rocksDB_directories_to_be_merged> <destination_folder>\n"; + <folder_having_rocksDB_directories_to_be_merged> <destination_folder>\n"; exit(0); } @@ -91,15 +91,15 @@ int main(int argc, char* argv[]) { if(!it->Valid()) { continue; } - struct node tnode(it->key().ToString(), it->value().ToString(), counter++); + struct node tnode(it->key(), it->value(), counter++); itVec.push_back(it); pq.push(tnode); } - std::string lastKey = "", lastValue = ""; + Slice lastKey, lastValue; while(!pq.empty()) { - struct node top = pq.top(); + const struct node &top = pq.top(); pq.pop(); if(top.key == lastKey) { @@ -115,7 +115,7 @@ int main(int argc, char* argv[]) { if(!itVec[top.idx]->Valid()) { continue; } - struct node tnode(itVec[top.idx]->key().ToString(), itVec[top.idx]->value().ToString(), top.idx); + struct node tnode(itVec[top.idx]->key(), itVec[top.idx]->value(), top.idx); pq.push(tnode); } -- GitLab