#include <string>
#include <unordered_map>
#include <chrono>
#include <vector>
#include <algorithm>
#include <iostream>
struct Index {
std::vector<std::string> collections;
std::chrono::system_clock::time_point last_query_time;
};
struct Database {
std::vector<std::string> collection_names;
std::vector<Index> indexes;
};
using time_point = std::chrono::system_clock::time_point;
std::unordered_map<std::string, time_point> get_last_query_time(const Database& database) {
std::unordered_map<std::string, time_point> last_query;
for (auto& c : database.collection_names) {
last_query[c] = {};
}
for (auto& i : database.indexes){
for (auto& c : i.collections) {
last_query[c] = std::max(last_query[c], i.last_query_time);
}
}
return last_query;
}
int main() {
Database database{ {"collection1","collection2","collection3"}, {{{"collection1","collection3"},std::chrono::system_clock::now()}} };
auto last_query = get_last_query_time(database);
for (auto& p : last_query) {
std::cout << p.first << ":" << p.second.time_since_epoch().count() << "\n";
}
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHVub3JkZXJlZF9tYXA+CiNpbmNsdWRlIDxjaHJvbm8+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnN0cnVjdCBJbmRleCB7CglzdGQ6OnZlY3RvcjxzdGQ6OnN0cmluZz4gY29sbGVjdGlvbnM7CglzdGQ6OmNocm9ubzo6c3lzdGVtX2Nsb2NrOjp0aW1lX3BvaW50IGxhc3RfcXVlcnlfdGltZTsKfTsKCnN0cnVjdCBEYXRhYmFzZSB7CglzdGQ6OnZlY3RvcjxzdGQ6OnN0cmluZz4gY29sbGVjdGlvbl9uYW1lczsKCXN0ZDo6dmVjdG9yPEluZGV4PiBpbmRleGVzOwp9OwoKdXNpbmcgdGltZV9wb2ludCA9IHN0ZDo6Y2hyb25vOjpzeXN0ZW1fY2xvY2s6OnRpbWVfcG9pbnQ7CgpzdGQ6OnVub3JkZXJlZF9tYXA8c3RkOjpzdHJpbmcsIHRpbWVfcG9pbnQ+IGdldF9sYXN0X3F1ZXJ5X3RpbWUoY29uc3QgRG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