Template Class MovePriorityQueue

Class Documentation

template<typename KeyType>
class MovePriorityQueue

基于模板的通用优先队列(收益桶核心)。

通过 KeyType 切换后端映射:

  • KeyType = int:使用 vector<int> 直接索引,适用于按分区独立的桶;

  • KeyType = pair<int,int>:使用 unordered_map,适用于全局统一桶。

Public Functions

inline MovePriorityQueue(const int total, const int max_level, const graph &g)

开辟并激活队列,通过 total 提供快速内存槽预占,并挂入被监控图结构。

inline void clear()

清空桶并重置状态。

inline bool compare_element(int id_a, int id_b) const

元素比较方法:按收益值降序排列,收益相同时按面积升序排列。

inline void heap_up(int id)

内部堆维护:元素升值后向上调整位置。

inline void heap_down(int id)

内部堆维护:元素收益降低后向下调整位置。

inline void change_priority(KeyType id, const Gain &new_gain)

更新指定元素的优先级,并在堆中重新调整位置。

inline void insert(const Gain &ele)

将元素插入队列。

inline Gain top() const

返回收益最高的元素(不删除)。

inline Gain pop()

移除并返回收益最高的元素。

inline void remove(KeyType id)

移除指定 ID 的元素。

inline Gain get(const vector<VectorXi> &occupied_resources, const graph &g, bool bound_constraint, vector<VectorXi> fpga_resources, VectorXi upper_resources, VectorXi lower_resources)

返回满足资源约束的最高收益可行移动。如果最高收益元素超出资源限制,则依次尝试次优元素。

inline bool check(KeyType id) const
inline bool get_active() const
inline void set_active(const bool active)
inline int get_total() const

Private Types

using MapType = conditional_t<is_same_v<KeyType, int>, vector<int>, unordered_map<pair<int, int>, int, hashfunc>>

Private Functions

inline int mapGet(const KeyType &k) const
inline void mapSet(const KeyType &k, int v)
inline void mapErase(const KeyType &k)
inline bool mapHas(const KeyType &k) const
inline void mapClear()

Private Members

bool active_
const graph &g_
int total_ = 0
int max_level_ = 25
MapType vertices_map_
vector<Gain> gains_

Private Static Functions

static inline KeyType keyOf(const Gain &g)
static inline int Parent(int element)
static inline int Left(int element)
static inline int Right(int element)