我正在使用std::map定义为std::map<std::vector<int>, double>,您会看到键值是整数向量。我的地图中的成员数量是 24600。这是最小的工作示例:
InOutLetFileVelocityWeights.h:
#include <iostream>
#include <string>
#include <vector>
#include <map>
class InOutLetFileVelocityWeights
{
public:
InOutLetFileVelocityWeights();
const std::string& GetWeightsFilePath()
{
return velocityWeightsFilePath;
}
void SetWeightsFilePath(const std::string& path)
{
velocityWeightsFilePath = path;
}
double GetValue(std::vector<int>& xyz);
void Initialise();
private:
std::string velocityWeightsFilePath;
std::map<std::vector<int>, double> weights_table;
};
Run Code Online (Sandbox Code Playgroud)
InOutLetFileVelocityWeights.cc:
#include "InOutLetFileVelocityWeights.h"
#include <algorithm>
#include <fstream>
#include <cmath>
InOutLetFileVelocityWeights::InOutLetFileVelocityWeights()
{
}
double InOutLetFileVelocityWeights::GetValue(std::vector<int>& xyz)
{
double value;
value = weights_table.at(xyz);
return value;
}
void InOutLetFileVelocityWeights::Initialise()
{
/* Load …Run Code Online (Sandbox Code Playgroud)