【发布时间】:2011-09-30 01:20:37
【问题描述】:
我正在努力将一个框架从 C++ 移植到 Java,结果比我预期的要难,因为我对 C++ 知之甚少。我遇到了这个我不太了解的sn-p。如果有人能告诉我标记的行是做什么的,那就太棒了。
/** Heap data, stored as a vector */
std::vector< std::pair< _Tp, _Val > > data;
/** Maps objects to their positions in the data vector */
std::map< _Tp, int> mapping;
//I understand that this method takes a pair of type <_Tp, _Val>
template <class _Tp, class _Val>
void Heap<_Tp,_Val>::push(std::pair< _Tp, _Val > x)
{
int index=data.size();
//Here is where I run into trouble
//I can't seem to figure out what this line is doing
//I know it is inserting a Key-Value pair into the map
//but why is .second being called? and what exactly is this if statement
//checking?
if (mapping.insert(std::make_pair(x.first,index)).second)
{
data.push_back(x);
percolate_up(index);
}
}
【问题讨论】:
标签: c++