史记_魏公子列传

魏公子,魏无忌是也,也即信陵君。 魏昭王去世后,并未手足相残,其同父异母的弟弟做了魏王,自己被封为信陵君。 公子无忌礼贤下士,门客三千,因此各诸侯不敢加兵谋魏十余年。 魏王因公子无忌有能力提前知晓赵王行动,便对其产生忌惮。

January 27, 2026 · 1 min

你好,世界

这是我基于 CentOS 9 + Nginx + Hugo 搭建的个人博客。 域名:zrq2.batch.icu HTTPS:Let’s Encrypt 博客系统:Hugo 🚀 欢迎访问!

January 25, 2026 · 1 min

CPP Code Demo1

CPP Code Demo1: video player play decode #include <iostream> using namespace std; // 纯虚类及其子类 共同服务于第三类(此类是业务应用层概念, 前者是底层逻辑概念) struct IDecode { virtual bool Decode(const char* data, size_t size) = 0; virtual ~IDecode() {} }; struct MP4Decode : public IDecode { bool Decode(const char* data, size_t size) { //todo return true; } ~MP4Decode() {} }; struct AVIDecode : public IDecode { bool Decode(const char* data, size_t size) { //todo return true; } ~AVIDecode() {} }; struct Player { Player(IDecode* de) : decode(de) {} ~Player() {} bool Play(const char* data, size_t size) { if (decode->Decode(data, size)) { cout << "Decode Success, Start Play..." << endl; // to play } else { cout << "Decode Failed, Stop Play..." << endl; } } private: IDecode* decode; };

1 min

优先级队列的理解

C++ 优先队列(priority_queue) 和 比较函数 优先级(priority):谁更先被取出 堆类型(max/min heap):堆顶元素是最大(大顶堆)还是最小(小顶堆) 比较函数bool compare(T a, T b) 返回true STL 默认 comparator 表示 “a 是否小于 b”, #include <queue> struct Order { double price; int volume; long long timestamp; // 用于同价的先进先出 // 买单队列的比较函数: 价格高的排在前面,大顶堆 struct BuyComp { bool operator() (const Order& a, const Order& b) { if(a.price != b.price) return a.price < b.price; return a.timestamp > b.timestamp; } }; // 卖单队列的比较函数: 价格低的排在前面,小顶堆 struct SellComp { bool operator() (const Order& a, const Order& b) { if(a.price != b.price) return a.price > b.price; return a.timestamp > b.timestamp; } }; }; class MatchingEngine { priority_queue<Order, vector<Order>, Order::BuyComp> buyOrders; priority_queue<Order, vector<Order>, Order::SellComp> sellOrders; long long timer = 0; public: void process(string type, double price, int volume) { Order current = {price, volume, timer++}; if (type == "BUY") { // 尝试与现有的卖单撮合 while(!sellOrders.empty() && current.volume > 0 && current.price >= sellOrders.top().price) { Order bestSell = sellOrders.top(); sellOrders.pop(); int tradeVol = min(bestSell.volume, current.volume); cout << "成交: price:" << bestSell.price << "volume: " << tradeVol << endl; current.volume -= tradeVol; bestSell.volume -= tradeVol; if(bestSell.volume > 0) sellOrders.push(bestSell); } if(current.volume > 0) buyOrders.push(current); } else if (type == "SELL") { // 尝试与现有的买单撮合 while(!buyOrders.empty() && current.volume > 0 && current.price < buyOrders.top().price) { Order bestBuy = buyOrders.top(); buyOrders.pop(); int tradeVol = min(bestBuy.volume, current.volume); cout << "成交: price:" << current.price << "volume: " << tradeVol << endl; current.volume -= tradeVol; bestBuy.volume -= tradeVol; if(bestBuy.volume > 0) buyOrders.push(bestBuy); } if(current.volume > 0) sellOrders.push(current); } } };

2 min

快捷键

vscode 复制当前行到下一行/上一行 shift + alt + 上键/下键

1 min