示例#1
0
//处理添加边的函数,如果边的源顶点不存在,则返回错误的状态,如果成功插入,则返回ok状态
//加边的同时,如果成功,要添加边的属性索引,边的属性索引是针对整个图的,而不是子图
void handler_add_edge(Replier &rep){
	proto_edge_u *req_arg=(proto_edge_u*)rep.get_arg();//获取参数
	Subgraph *sub=graph_set->get_subgraph(req_arg->graph_name,req_arg->edge.s_id);//得到该图该顶点所在的子图,子图不存在,则会创建一个
	Edge e(req_arg->edge);
	int res;
	while(true){
		res=sub->add_edge(req_arg->edge.s_id,e);
		if(res==1){
			rep.ans(STATUS_V_NOT_EXIST,"vertex not exist",strlen("vertex not exist")+1);
			break;
		}
		if(res==0) break;
		if(res==-1){
			rep.ans(STATUS_E_EXIST,"edge has exist",strlen("edge has exist")+1);
			break;
		}
	}
	if(res==0){
        //添加边属性的索引
        Graph *graph=graph_set->get_graph(req_arg->graph_name);
        Key k(req_arg->edge.blog_id);
        Value v(req_arg->edge.s_id,req_arg->edge.d_id);
        //graph->add_edge_index(k,v); 
        graph_set->get_graph(req_arg->graph_name)->edge_num_increment();
		rep.ans(STATUS_OK,"ok",strlen("ok")+1);
	}
}
示例#2
0
//处理查找该子图的某个图的边数目的函数
void handler_get_edge_num(Replier &rep){
	proto_graph *req_arg=(proto_graph*)rep.get_arg();
    Graph *graph=graph_set->get_graph(req_arg->graph_name);
    uint32_t num=graph->edge_num; 
    ostringstream stream_num;
	stream_num<<num;
	string string_num=stream_num.str();
	rep.ans(STATUS_OK,string_num.c_str(),string_num.size()+1);
}
示例#3
0
//处理查找该节点所有子图的所有顶点
void handler_read_all_vertex(Replier &rep){
	proto_graph *req_arg=(proto_graph*)rep.get_arg();
    Graph *graph=graph_set->get_graph(req_arg->graph_name);
	list<Vertex_u> vertexes;
	//遍历所有子图
	unordered_map<uint32_t,Subgraph*>::iterator it;
	for(it=graph->sgs.begin();it!=graph->sgs.end();it++){
		it->second->read_all_vertex(vertexes);
	}
	rep.ans(STATUS_OK,vertexes);
}
示例#4
0
//处理根据属性查找边的函数
void handler_read_edge_index(Replier &rep){
	proto_blog_id *req_arg=(proto_blog_id*)rep.get_arg();
	list<Edge_u> edges;//存储返回的结果
        Key k(req_arg->blog_id);
        Graph *graph=graph_set->get_graph(req_arg->graph_name);
        list<Value> vs;
        unordered_map<int,unordered_map<int,int>*> repeated;//这个map用来查重,重复的两个顶点就不用再找边了
        unordered_map<int,unordered_map<int,int>*>::iterator it_out;
        unordered_map<int,int>::iterator it_in;
        list<Value>::iterator it;
        graph->get_edge_index(k,vs);
        for(it=vs.begin();it!=vs.end();it++){
               v_type s_id=(*it).s_id;
               v_type d_id=(*it).d_id;
               //查看
               it_out=repeated.find(s_id);
               int flag;//0代表没有重复,1代表重复
               if(it_out==repeated.end()){
                    unordered_map<int,int>*tmp=new unordered_map<int,int>();
                    (*tmp)[d_id]=1;
                    repeated[s_id]=tmp; 
                    flag=0;
               }else{
                    unordered_map<int,int>*tmp=it_out->second;
                    if(tmp->find(d_id)==tmp->end()){
                         flag=0;
                         (*tmp)[d_id]=1;
                    }else{
                         flag=1;
                    }
               }
               if(flag==0){
                    //顶点没有重复的时候就去查找边
                    Subgraph *sub=graph_set->get_subgraph(req_arg->graph_name,s_id);
					int res;
					while(true){
                    	res=sub->read_edges(s_id,d_id,req_arg->blog_id,edges);    
						if(res==1||res==0){
							break;
						}
					}
               }
        }
        //释放内存
        for(it_out=repeated.begin();it_out!=repeated.end();it_out++)
              delete it_out->second;
	rep.ans(STATUS_OK,edges);
}
示例#5
0
//读取顶点的所有边,如果边的源顶点不存在,则返回错误的状态,如果成功插入,则返回ok状态
void handler_read_edges(Replier &rep){
	proto_graph_vertex *req_arg=(proto_graph_vertex*)rep.get_arg();
	Subgraph *sub=graph_set->get_subgraph(req_arg->graph_name,req_arg->vertex_id);//得到该图该顶点所在的子图,子图不存在,则会创建一个
	list<Edge_u> edges;
	int res;
	while(true){
		res=sub->read_all_edges(req_arg->vertex_id,edges);
		if(res==1){		
			rep.ans(STATUS_V_NOT_EXIST,"vertex not exist",strlen("vertex not exist")+1);
			break;
		}
		if(res==0) break;
	}
	if(res==0){
		rep.ans(STATUS_OK,edges);	
	}
}
示例#6
0
//处理添加顶点的函数,只要客户端把顶点的请求发过来了,说明该顶点就属于该slave节点了,这是一个异步的过程
void handler_add_vertex(Replier &rep){
	proto_graph_vertex_u *req_arg=(proto_graph_vertex_u*)rep.get_arg();//获取参数
	Subgraph *sub=graph_set->get_subgraph(req_arg->graph_name,req_arg->vertex.id);//得到该图该顶点所在的子图,子图不存在,则会创建一个
	Vertex v(req_arg->vertex);
	int res;
	while(true){
		res=sub->add_vertex(v);
		if(res==1){
			rep.ans(STATUS_V_EXIST,"vertex exist",strlen("vertex exist")+1);
			break;
		}
		if(res==0) break;
	}
	if(res==0){
                graph_set->get_graph(req_arg->graph_name)->vertex_num_increment();
		rep.ans(STATUS_OK,"ok",strlen("ok")+1);
	} 	
}
示例#7
0
//读取顶点,如果顶点不存在,则返回错误的状态,如果存在,则返回ok状态和顶点的信息
void handler_read_vertex(Replier &rep){
	proto_graph_vertex *req_arg=(proto_graph_vertex*)rep.get_arg();
	Subgraph *sub=graph_set->get_subgraph(req_arg->graph_name,req_arg->vertex_id);//得到该图该顶点所在的子图,子图不存在,则会创建一个
        Vertex_u v;
        uint32_t num;
	while(true){
        int res=sub->read_vertex(req_arg->vertex_id,v,&num);
		if(res==1){		
			rep.ans(STATUS_V_NOT_EXIST,"vertex not exist",strlen("vertex not exist")+1);
			break;
		}
		if(res==0){
			proto_vertex_num mes;
        	mes.vertex=v;
        	mes.num=num;
			rep.ans(STATUS_OK,&mes,sizeof(proto_vertex_num));	
			break;
		}
	}
}
示例#8
0
void handler_create_graph(Replier& rep){
	proto_create_graph *rep_arg=(proto_create_graph)rep.get_arg();
			
}