#pragma once #include #include #include #include #include template class Memdb { struct memdb_column { T key; U value; std::chrono::system_clock::time_point timestamp; bool be_del = false; }; struct index_keys { T key; std::list ::iterator item; }; struct index_timestamp { std::list ::iterator item; bool operator<(const index_timestamp& a) const; }; private: std::list db; std::unordered_map keys; std::priority_queue time_touch; size_t __size = 0; int MAX_TIME = 60 * 10; // 10分钟 void flush(); void update_queue(); public: using key_t = T; using value_t = U; static constexpr bool fail = false; static constexpr bool succ = true; Memdb(); Memdb(int max_time); Memdb& operator=(const Memdb& to_be_cp_memdb); ~Memdb(); size_t size() const; const std::unordered_map & get_keys() const; const std::list & get_db() const; const std::priority_queue & get_time_touch() const; bool insert(key_t to_be_ins_k, value_t ins_v); bool remove(key_t to_be_del_k); bool update(key_t to_be_udt_k, value_t udt_v, bool need_to_udt_timetouch=false); std::optional search(key_t to_be_sch_k); };