⚡️ 将queue切换为set

This commit is contained in:
shufeng2012 committed 2026-08-12 20:11:07 +08:00
1 parent 82875b3021
commit 02d95a2bd9
2 files changed
+51 -177

No files matched your search

+7 -18
View File
@@ -1,14 +1,15 @@
#pragma once
#include <memory>
#include <list>
#include <unordered_map>
#include <chrono>
#include <queue>
#include <set>
#include <optional>
#include <cmath>
namespace shufeng2012 {
template <typename T, typename U>
class Memdb {
@@ -18,7 +19,6 @@ struct memdb_column {
T key;
U value;
std::chrono::system_clock::time_point timestamp;
bool be_del = false;
};
struct index_keys {
@@ -36,15 +36,10 @@ struct index_timestamp {
private:
std::list <memdb_column> db;
std::unordered_map <T, index_keys> keys;
std::priority_queue <index_timestamp> time_touch;
std::multiset <index_timestamp> time_touch_;
std::multiset <index_timestamp> time_touch;
size_t __size = 0;
int MAX_TIME = 60 * 10; // 10分钟
void flush();
void update_queue();
// 内测版
void flush_();
public:
@@ -61,17 +56,11 @@ public:
size_t size() const;
const std::unordered_map <T, index_keys>& get_keys() const;
const std::list <memdb_column>& get_db() const;
const std::priority_queue <index_timestamp>& get_time_touch() const;
const std::multiset <typename Memdb <T, U>::index_timestamp>& 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<U> search(key_t to_be_sch_k);
// 内测版
const std::multiset <index_timestamp>& 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<U> search_(key_t to_be_sch_k);
};
};
}