结构:
struct st_cost_key
{
int startid;
int dstid;
st_cost_key():startid(-1),dstid(-1){};
st_cost_key(int sid, int tid):startid(sid),dstid(tid){};
~st_cost_key(){};
bool operator < ( const st_cost_key& costkey ) const
{
return (this->startid<costkey.startid || (this->startid==costkey.startid && this->dstid<costkey.dstid));
}
};
定义:
map<st_cost_key, int> m_BusStopDriveCostMap;
添加:
st_cost_key costk(pStopTransferCost->m_nStartBStopIdx, pStopTransferCost->m_nDstBStopIdx);
m_BusStopTransferCostMap.insert(
std::make_pair( costk, pStopTransferCost->m_nCost ) );
查询:
st_cost_key costk(nStartStopIdx, nDstStopIdx);
map<st_cost_key,int>::iterator it = m_BusStopDriveCostMap.find( costk );
if ( it != m_BusStopDriveCostMap.end() )
{
nCost = it->second;
return BT_SUCCEED;
}
采用结构实现stl map 复合key的处理
最新推荐文章于 2023-04-23 20:35:39 发布