//处理批量添加边的函数,边都属于一个图 void handler_add_vertexes(Replier &rep){ string graph_name=rep.get_graph_name(); list<Vertex_u> &vertexes=rep.get_vertexes(); list<Vertex_u>::iterator it=vertexes.begin(); Subgraph *sub; uint32_t num=0; while(it!=vertexes.end()){ sub=graph_set->get_subgraph(graph_name,(*it).id);//得到该图该顶点所在的子图,子图不存在,则会创建一个 Vertex v(*it); int res=sub->add_vertex(v); if(res==0||res==1){ if(res==0){ graph_set->get_graph(graph_name)->vertex_num_increment(); num++;//添加成功,记录一笔 } vertexes.erase(it); it=vertexes.begin(); } else{ it++; if(it==vertexes.end()){ it=vertexes.begin(); } } } ostringstream stream_num; stream_num<<num; string string_num=stream_num.str(); rep.ans(STATUS_OK,string_num.c_str(),string_num.size()+1); }
//处理批量添加边的函数,边都属于一个图 //加边的同时,如果成功,要添加边的属性索引,边的属性索引是针对整个图的,而不是子图 void handler_add_edges(Replier &rep){ string graph_name=rep.get_graph_name(); list<Edge_u> &edges=rep.get_edges(); list<Edge_u>::iterator it=edges.begin(); Subgraph *sub; uint32_t num=0; while(it!=edges.end()){ sub=graph_set->get_subgraph(graph_name,(*it).s_id);//得到该图该顶点所在的子图,子图不存在,则会创建一个 Edge e(*it); int res=sub->add_edge((*it).s_id,e); if(res==0||res==1||res==-1) { if(res==0){ //添加边属性的索引 Graph *graph=graph_set->get_graph(graph_name); Key k((*it).blog_id); Value v((*it).s_id,(*it).d_id); //graph->add_edge_index(k,v); graph_set->get_graph(graph_name)->edge_num_increment(); num++;//添加成功,记录一笔 } edges.erase(it); it=edges.begin(); } else{ it++; if(it==edges.end()){ it=edges.begin(); } } } ostringstream stream_num; stream_num<<num; string string_num=stream_num.str(); rep.ans(STATUS_OK,string_num.c_str(),string_num.size()+1); }
//处理批量read边的函数,边都属于一个图 void handler_read_two_edges(Replier &rep){ string graph_name=rep.get_graph_name(); list<Two_vertex> &vertexes=rep.get_two_vertexes(); list<Two_vertex>::iterator it=vertexes.begin(); Subgraph *sub; uint32_t num=0; list<Edge_u> edges; while(it!=vertexes.end()){ int res; sub=graph_set->get_subgraph(graph_name,(*it).s_id);//得到该图该顶点所在的子图,子图不存在,则会创建一个 //sub->read_edges((*it).s_id,(*it).d_id,edges); res=sub->read_all_edges((*it).s_id,edges); if(res==1||res==0){ vertexes.erase(it); it=vertexes.begin(); } if(res==2){ it++; if(it==vertexes.end()){ it=vertexes.begin(); } } } rep.ans(STATUS_OK,edges); }