priority_queue and unordered_multimap

本文介绍了一种使用优先级队列进行任务调度的方法,并通过哈希多映射实现资源冲突检测。具体实现了自定义比较器以确保任务能够按照特定属性进行排序,并在资源分配前检查是否发生时间上的冲突。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



struct cmp{
bool operator()(const Class &a, const Class &b) const{
return a.x > b.x;
}
};


int main()

{

list<Class> reqs =  ReadFile();

priority_queue < Class, vector<Class>, cmp > q;


for (auto it = reqs.begin(); it != reqs.end(); ++it)
{
q.push(*it);
}


unordered_multimap < string, Class>  map;
while (!q.empty())
{
bool isOverlap = false;
auto cur = q.top();
q.pop();
for (auto loc : cur.y)
{
string key = loc;
int n = map.count(key);
if (map.find(key) != map.end())
{
auto it = map.lower_bound(key);
for (; it != map.upper_bound(key); ++it)
{
//overlapped
if (it->second._endT > cur._startT)
{
rmvReqs.push_back(cur);
isOverlap = true;
break;
}
}
if (it == map.upper_bound(key))
map.insert(make_pair(key, cur));
}
else
{
map.insert(make_pair(key, cur));
}
}
if (!isOverlap) validReq.push_back(cur);

}

       return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值