@@ -18,15 +18,6 @@ namespace compare {
1818
1919// ---------------------------------------------------------------------------------------------------------------------
2020
21- std::ostream& operator <<(std::ostream& os, const KeyValueMap& km) {
22- os << " {" ;
23- for (const auto & [k, v] : km) {
24- os << k << " =" << v << " , " ;
25- }
26- os << " }" ;
27- return os;
28- }
29-
3021std::ostream& operator <<(std::ostream& os, const KeyDiffMap& km) {
3122 os << " {" ;
3223 for (const auto & [k, v] : km) {
@@ -46,10 +37,6 @@ std::ostream& operator<<(std::ostream& os, const KeySet& km) {
4637 return os;
4738}
4839
49- std::ostream& operator <<(std::ostream& os, const DataLocation& loc) {
50- return os << " (" << loc.path << " , " << loc.offset << " , " << loc.length << " )" ;
51- }
52-
5340std::ostream& operator <<(std::ostream& os, const DataIndex& idx) {
5441 for (const auto & [km, loc] : idx) {
5542 os << " Key: " << km << " -> Value: " << loc << " \n " ;
@@ -59,26 +46,6 @@ std::ostream& operator<<(std::ostream& os, const DataIndex& idx) {
5946
6047// ---------------------------------------------------------------------------------------------------------------------
6148
62-
63- void parseKeyValues (KeyValueMap& container, const std::string& keyValueStr) {
64- std::istringstream stream (keyValueStr);
65- std::string entry;
66-
67- while (std::getline (stream, entry, ' ,' )) {
68- std::istringstream pairStream (entry);
69- std::string key, value;
70- if (std::getline (pairStream, key, ' =' ) && std::getline (pairStream, value)) {
71- container[key] = value; // Update or insert key-value pair
72- }
73- }
74- }
75-
76- KeyValueMap parseKeyValues (const std::string& keyValueStr) {
77- KeyValueMap container;
78- parseKeyValues (container, keyValueStr);
79- return container;
80- }
81-
8249void parseKeySet (KeySet& container, const std::string& keyStr) {
8350 std::istringstream stream (keyStr);
8451 std::string entry;
@@ -94,11 +61,11 @@ KeySet parseKeySet(const std::string& keyStr) {
9461 return container;
9562}
9663
97- compare::KeyDiffMap requestDiff (const KeyValueMap & l, const KeyValueMap & r) {
64+ compare::KeyDiffMap requestDiff (const fdb5::Key & l, const fdb5::Key & r) {
9865 compare::KeyDiffMap res;
9966 for (const auto & [lk, lv] : l) {
100- auto search = r.find (lk);
101- if (search != r. end () ) {
67+ auto [ search, isValid] = r.find (lk);
68+ if (isValid ) {
10269 if (search->second != lv) {
10370 res.insert ({lk, {lv, search->second }});
10471 }
@@ -109,8 +76,8 @@ compare::KeyDiffMap requestDiff(const KeyValueMap& l, const KeyValueMap& r) {
10976 }
11077
11178 for (const auto & [rk, rv] : r) {
112- auto search = l.find (rk);
113- if (search == l. end () ) {
79+ auto [ search, isValid] = l.find (rk);
80+ if (!isValid ) {
11481 res.insert ({rk, {{}, rv}});
11582 }
11683 }
@@ -120,21 +87,15 @@ compare::KeyDiffMap requestDiff(const KeyValueMap& l, const KeyValueMap& r) {
12087// ---------------------------------------------------------------------------------------------------------------------
12188
12289
123- KeyValueMap applyKeyDiff (KeyValueMap k, const KeyDiffMap& diff, bool swapDiff) {
90+ fdb5::Key applyKeyDiff (fdb5::Key k, const KeyDiffMap& diff, bool swapDiff) {
12491 for (const auto & [field, val_pair] : diff) {
12592 const auto & val = swapDiff ? val_pair.first : val_pair.second ;
12693 if (val) {
127- auto it = k.find (field);
128- if (it != k.end ()) {
129- it->second = *val; // replace value
130- }
131- else {
132- k.insert ({field, *val});
133- }
94+ k.set (field, *val);
13495 }
13596 else {
13697 // Delete
137- k.erase (field);
98+ k.unset (field);
13899 }
139100 }
140101 return k; // return modified copy
@@ -265,31 +226,26 @@ void Result::update(const Result& other) {
265226// ---------------------------------------------------------------------------------------------------------------------
266227
267228
268- bool isSubset (const KeyValueMap & a, const KeyValueMap & b) {
229+ bool isSubset (const fdb5::Key & a, const fdb5::Key & b) {
269230 for (const auto & kv : a) {
270- auto it = b.find (kv.first );
271- if (it == b. end () || it->second != kv.second )
231+ auto [it, isValid] = b.find (kv.first );
232+ if (!isValid || it->second != kv.second )
272233 return false ;
273234 }
274235 return true ;
275236}
276237
277238
278- DataIndex assembleCompareMap (fdb5::FDB& fdb, const fdb5::FDBToolRequest& req, const KeyValueMap & ignore) {
239+ DataIndex assembleCompareMap (fdb5::FDB& fdb, const fdb5::FDBToolRequest& req, const fdb5::Key & ignore) {
279240 DataIndex out;
280241
281242 auto list = fdb.list (req);
282243 fdb5::ListElement elem;
283244
284245 while (list.next (elem)) {
285- KeyValueMap km;
286- for (const auto & bit : elem.keys ()) {
287- auto d = bit.keyDict ();
288- km.insert (d.begin (), d.end ());
289- }
246+ fdb5::Key km = elem.combinedKey ();
290247 if (ignore.empty () || !isSubset (ignore, km)) {
291- out.emplace (km, DataLocation{elem.location ().uri ().path (), static_cast <long long >(elem.location ().offset ()),
292- static_cast <long long >(elem.location ().length ())});
248+ out.emplace (km, elem);
293249 }
294250 }
295251 eckit::Log::info () << " [LOG] FDB request: " << req << " resulted in " << out.size () << " entries.\n " ;
0 commit comments