Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 处理字符串的STXXL_C++_String_C++11_Bigdata_Stxxl - Fatal编程技术网

C++ 处理字符串的STXXL

C++ 处理字符串的STXXL,c++,string,c++11,bigdata,stxxl,C++,String,C++11,Bigdata,Stxxl,我正在处理大型数据集。我可以问一下如何在我想与stxxl一起使用的类中存储字符串吗?我读过几篇讨论,到处都有人说字符串不是POD类型,因此它不能存储在stxxl::vector中,但我不确定,因为我尝试了它,检查了数据,一切似乎都很好。我在这里也看到了一种方法,它们使用stxxl::vector,所以可能库已经更新以支持std::string class HighWay { private: uint64_t id; string name; int speed;

我正在处理大型数据集。我可以问一下如何在我想与stxxl一起使用的类中存储字符串吗?我读过几篇讨论,到处都有人说字符串不是POD类型,因此它不能存储在stxxl::vector中,但我不确定,因为我尝试了它,检查了数据,一切似乎都很好。我在这里也看到了一种方法,它们使用stxxl::vector,所以可能库已经更新以支持std::string

class HighWay
{
private:
    uint64_t id; 
    string name;
    int speed;
    string attributes; //additional attributes of way
    string edges; //written uint64_t from,uint64_t to, int distance  written as string
    string nodes; //vector<uint64_t> written as string
public:
    HighWay() = default;
    void setId(uint64_t _id) {
        id = boost::lexical_cast<string>(_id);
    }
void setName(string _name) {
    name = _name;
}
void setSpeed(int _speed) {
    speed = _speed;
}
void setAttributes(string _attributes) {
    attributes = _attributes;
}
void setEdges(string _edges) {
    edges = _edges;
}

void setNodes(vector<uint64_t>refs) {
    stringstream s;
    uint64_t i = 0;
    for (; i < refs.size()-1;i++) {
        s << boost::lexical_cast<uint64_t>(refs[i]) << " ";
    }
    s << boost::lexical_cast<uint64_t>(refs[i]);

    nodes = s.str();
}

uint64_t getId() {
    return id;
}
string getName() {
    return name;
}
int getSpeed() {
    return speed;
}
string getAttributes() {
    return attributes;
}
string getEdges() {
    return edges;
}

std::vector<int64_t> getNodes() {
    stringstream s(nodes);
    uint64_t node;
    std::vector<int64_t> result;
    while (s >> node) {
        result.push_back(static_cast<int64_t>(node));
    }

    return result;
}
};
一级公路
{
私人:
uint64_t id;
字符串名;
整数速度;
字符串属性;//路径的其他属性
字符串边;//写入uint64\u t from,uint64\u t to,int距离写入为字符串
字符串节点;//向量写为字符串
公众:
高速公路()=默认值;
void setId(uint64\u t\u id){
id=boost::词法转换(_id);
}
void setName(字符串_name){
名称=_名称;
}
无效设置速度(内部速度){
速度=_速度;
}
void setAttributes(字符串属性){
属性=_属性;
}
无效设置边(字符串_边){
边=_边;
}
void集合节点(矢量){
细绳;
uint64_t i=0;
对于(;i(标准::istream&i、TypeName和entry)
{
i>>entry.start;
i>>entry.end;
返回i;
}
std::ostream&operator entry.start;
i>>entry.end;
返回i;
}

std::ostream&operator它确实是被禁止的,但是违反no-POD规则的症状通常是不可预测的。只要字符串都在内存中,它很可能会出现,但在这种情况下,你根本不需要STXXL。

我明白,有没有更好的方法来解决这个问题?STXXL库不喜欢我的问题的可行解决方案。例如,你对这个数据库有经验吗?他们说它有点像redis,所以也许它可以用于预处理,或者有没有更好的方法我不知道?我的问题是,我需要暂时存储预处理数据,然后再将最终数据插入到数据库及其应用程序中数据集比已安装的RAM所能处理的数据量大得多。没有经验。当我遇到这样的问题时,我非常积极地优化了这个问题,使其适合RAM。这包括将我不需要编辑的所有字符串加载到单个内存块中,并将
char const*const
存储到该块中。此外,我还将我的算法分为多个过程,每个过程都能放入内存。是的,我也在使用多个过程来获取我需要的内容,事实上我需要将整个文件读取两次。问题是,如果我将预处理数据的一部分存储在数据库中,那么对如此大的数据集进行更新操作需要花费大量时间。因此,由于速度问题,我不得不保持p甚至在内存中存储预处理的文件,以便我可以添加我后来发现的附加数据。
//class to store in map
struct TypeName{
    uint64_t start;
    uint64_t end;
};

std::istream& operator >> (std::istream& i, TypeName& entry)
{
    i >> entry.start;
    i >> entry.end;
    return i;
}
std::ostream& operator << (std::ostream& i, const TypeName& entry)
{
    i << entry.start << " ";
    i << entry.end;
    return i;
}

struct PoiCategories{
   uint64_t start;
   uint64_t end;
};

std::istream& operator >> (std::istream& i,PoiCategories& entry)
{
    i >> entry.start;
    i >> entry.end;
    return i;
}

std::ostream& operator << (std::ostream& i, const PoiCategories& entry)
{
    i << entry.start << " ";
    i << entry.end;
    return i;
}

 //object i want to store
struct Poi {
    Poi() = default;
    uint64_t id;
    char type;
    uint64_t id_in_pois; //id in vector pois

void addCategories(
    vector<int> &kats, //categories to insert
    stxxl::vector<uint64_t> &categories, //vector to store category
    std::unordered_map <uint64_t, PoiCategories> &idPoi_categories //index to vector categories to retrieve all categories for Poi
    )
{
    size_t  start = categories.size();
    for (auto & kat : kats) {
        categories.push_back(kat);
    }
    size_t end = categories.size() - 1;
    idPoi_categories.insert(make_pair(id, PoiCategories{start, end }));


}

vector<int> getCategories(
    stxxl::vector<uint64_t> &categories,
    std::unordered_map <uint64_t, PoiKategorie> &idPoi_categories
    )
{
    std::vector<int> result;
    PoiCategories bounds = idPoi_categories.find(id)->second;
    for (size_t i = bounds.start; i <= bounds.end; i++) {
        result.push_back(categories[i]);
    }

    return result;
}