-1
我正在使用地图内的地图来追踪一些数据。地图插入返回不正确的答案
为了添加一些数据,我首先检查是否基于全局键作为字符串进行跟踪。
如果我在地图上有这个键值,然后检查第一张地图内的地图,看看它是否有值,并将键值作为无符号短整型值。这是结构。
map<string, fileInfo> fileMap;
class fileInfo {
public:
unsigned short int numNeighbors;
map<unsigned short int, neighborInfo> neighbors; //key is id
//... more
}
我能来检查,如果我的主键是在我的整个地图,但是当我检查,看看是否该键就在那里,我得到上插入一个假的,说明这个邻居已经存在,但事实并非如此。我有理智的检查,并确保看看我的钥匙是否匹配,而他们不会。
找到第一个关键
it = fileMap.find(filename);
if (it == fileMap.end()) {
//add to fileMap
}else{
fileInfo currFI = it->second;
neighborInfo n = createNeighbor();
pair<it_Neighbor, bool> ret;
map<unsigned short int, neighborInfo> neighbors = currFI.neighbors;
ret = currFI.neighbors.insert(pair<unsigned short int, neighborInfo> (id, n));
if (ret.second == false) {
cout<< "Neighbor already exists for this file, ignoring duplicates."<< endl;
} else {
cout << "size" << currFI.neighbors.size() << endl;
}
我的尺寸输出总是2,当它应该是4
我是否需要为了使这项工作定义任何运营商或任何东西在我的课?
如何检查密钥是否存在? –
你应该*真的*也发布访问代码。 –
金徽章,1000+代表和1+年的成员,你应该知道更好...... –