Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

Dreamer2002 Apr 9th, 2020 (edited) 187 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma once
  2. #include "date.h"
  3. #include <map>
  4. #include <vector>
  5. #include <set>
  6. #include <algorithm>
  7. using namespace std;
  8. class Database{
  9. public:
  10.     void Add(const Date& new_date,const string& new_event);
  11.     void Print(ostream& stream) const;
  12.     template <class Func>
  13.     vector<pair<Date,string>> FindIf(Func func) const{
  14.         vector<pair<Date,string>> result;
  15.         for (auto it=database.begin();it!=database.end();it++)
  16.         {
  17.             for (auto it1=it->second.begin();it1!=it->second.end();it1++)
  18.                 if (func(it->first,*it1)) result.push_back(make_pair(it->first,*it1));
  19.         }
  20.         return result;
  21.  
  22.     }
  23.     template <class Func>
  24.     int RemoveIf(Func func){
  25.         int result=0;
  26.         for (auto it=database.begin();it!=database.end();it++)
  27.         {
  28.             int before=it->second.size();
  29.             auto c = it->first;
  30.             auto new_border = stable_partition(it->second.begin(),it->second.end(),[func,c](const string& s){
  31.                 return !func(c,s);
  32.             });
  33.             it->second.erase(new_border,it->second.end());
  34.             result+=before-it->second.size();
  35.             if (it->second.size()==0) database.erase(it->first);
  36.         }
  37.         return result;
  38.     }
  39.     string Last(const Date& new_date) const;
  40. private:
  41.     map<Date,set<string>> unique_database;
  42.     map<Date,vector<string>> database;
  43. };
  44. /*
  45. Database.cpp
  46.  #include "database.h"
  47. using namespace std;
  48. void Database::Add(const Date &new_date, const string &new_event) {
  49.     auto it = unique_database[new_date].insert(new_event);
  50.     if (it.second) database[new_date].push_back(new_event);
  51. }
  52. void Database::Print(ostream& stream) const {
  53.     for (const auto [key,value] : database)
  54.         for (const auto c : value)
  55.              stream << key << " " << c << endl;
  56. }
  57. string Database::Last(const Date& new_date) const{
  58.     auto it = database.upper_bound(new_date);
  59.     if (it!=database.begin())
  60.         return prev(it)->second.back();
  61.     throw invalid_argument("error");
  62. }
  63.  */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top