我需要一组数字的大地图。所以我使用的是 stxxl,它基本上类似于map<std::string, std::vector<int>>
. 键是 3 个字母的标识符。地图中大约有3k个enteries,每个enteries最多可以包含500K个数字。在值中使用向量很重要,因为我需要更改它(添加/删除数字)。
问题是,在我插入所有数据后,当我尝试访问地图中的元素时,向量被破坏了。
#define MAX_STRING_IN_MAP ("ZZZZZZZ")
// String comparator.
struct CompareGreaterString
{
bool operator () (const std::string& a, const std::string& b) const {
return a > b;
}
static std::string max_value() {
return MAX_STRING_IN_MAP;
}
};
typedef stxxl::map<std::string, std::vector<int>, CompareGreaterString, DATA_NODE_BLOCK_SIZE, DATA_LEAF_BLOCK_SIZE> myMap;
...
ifstream input_file;
myMap map((mapBacteria::node_block_type::raw_size) * 5, (mapBacteria::leaf_block_type::raw_size) * 5);
...
unsigned int count = 0;
while (count < max_number) {
count++;
std::string name;
unsigned int length;
input_file >> name;
input_file >> length;
std::vector<int> iterationGroup = readNumbers(input_file);
myMap.insert(std::pair<std::string, std::vector<int>>(name, iterationGroup));
// If i am trying to access the data here, like this:
// auto result = myMap[name];
// It seems perfectely fine.
}
例如,如果在上述插入之后,我将尝试访问地图:
auto result = myMap["aaa"];
然后我得到一个大小合适的向量,但它的所有元素都有一个值,0xfeeefeee
而不是最初在插入向量中的数字。