当前位置: 首页>>代码示例>>C++>>正文


C++ graphchi_vertex::sort_edges_indirect方法代码示例

本文整理汇总了C++中graphchi_vertex::sort_edges_indirect方法的典型用法代码示例。如果您正苦于以下问题:C++ graphchi_vertex::sort_edges_indirect方法的具体用法?C++ graphchi_vertex::sort_edges_indirect怎么用?C++ graphchi_vertex::sort_edges_indirect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graphchi_vertex的用法示例。


在下文中一共展示了graphchi_vertex::sort_edges_indirect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: grab_adj

 /**
   * Grab pivot's adjacency list into memory.
   */
 int grab_adj(graphchi_vertex<uint32_t, uint32_t> &v) {
     if(is_pivot(v.id())) {            
         int ncount = v.num_edges();
         // Count how many neighbors have larger id than v
         v.sort_edges_indirect();
  
         
         int actcount = 0;
         vid_t lastvid = 0;
         for(int i=0; i<ncount; i++) {
             if (v.edge(i)->vertexid > v.id() && v.edge(i)->vertexid != lastvid)  
                 actcount++;  // Need to store only ids larger than me
             lastvid = v.edge(i)->vertex_id();
         }
         
         // Allocate the in-memory adjacency list, using the
         // knowledge of the number of edges.
         dense_adj dadj = dense_adj(actcount, (vid_t*) calloc(sizeof(vid_t), actcount));
         actcount = 0;
         lastvid = 0;
         for(int i=0; i<ncount; i++) {
             if (v.edge(i)->vertexid > v.id() && v.edge(i)->vertexid != lastvid) {  // Need to store only ids larger than me
                 dadj.adjlist[actcount++] = v.edge(i)->vertex_id();
             }
             lastvid = v.edge(i)->vertex_id();
         }
         assert(dadj.count == actcount);
         adjs[v.id() - pivot_st] = dadj;
         assert(v.id() - pivot_st < adjs.size());
         __sync_add_and_fetch(&grabbed_edges, actcount);
         return actcount;
     }
     return 0;
 }
开发者ID:Prokopp,项目名称:graphchi-cpp,代码行数:37,代码来源:trianglecounting.cpp

示例2: update

    /**
     *  Vertex update function.
     */
    void update(graphchi_vertex<VertexDataType, EdgeDataType> &v, graphchi_context &gcontext) {
        
        if (gcontext.iteration % 2 == 0) {
            adjcontainer->grab_adj(v);
        } else {
            uint32_t oldcount = v.get_data();
            uint32_t newcounts = 0;

            v.sort_edges_indirect();
            
            vid_t lastvid = 0;
            
            /**
              * Iterate through the edges, and if an edge is from a 
              * pivot vertex, compute intersection of the relevant
              * adjacency lists.
              */
            for(int i=0; i<v.num_edges(); i++) {
                graphchi_edge<uint32_t> * e = v.edge(i);
                if (e->vertexid > v.id() && e->vertexid >= adjcontainer->pivot_st) {
                    assert(!is_deleted_edge_value(e->get_data()));
                    if (e->vertexid != lastvid) {  // Handles reciprocal edges (a->b, b<-a)
                        if (adjcontainer->is_pivot(e->vertexid)) {
                            uint32_t pivot_triangle_count = adjcontainer->intersection_size(v, e->vertexid, i);
                            newcounts += pivot_triangle_count;
                            
                            /* Write the number of triangles into edge between this vertex and pivot */
                            if (pivot_triangle_count == 0 && e->get_data() == 0) {
                                /* ... or remove the edge, if the count is zero. */
                                v.remove_edge(i); 
                            } else {
                                
                                e->set_data(e->get_data() + pivot_triangle_count);
                            }
                        } else {
                            break;
                        }
                    }
                    lastvid = e->vertexid;
                }  
                assert(newcounts >= 0);
            }
            
            if (newcounts > 0) {
                v.set_data(oldcount + newcounts);
            }
        }
        
        
        /* Collect triangle counts matched by vertices with id lower than
            his one, and delete */
        if (gcontext.iteration % 2 == 0) {
            int newcounts = 0;
          
            for(int i=0; i < v.num_edges(); i++) {
                graphchi_edge<uint32_t> * e = v.edge(i);
                if (e->vertexid < v.id()) {
                    newcounts += e->get_data();
                    e->set_data(0);
                    
                    // This edge can be now deleted. Is there some other situations we can delete?
                    if (v.id() < adjcontainer->pivot_st && e->vertexid < adjcontainer->pivot_st) {
                        v.remove_edge(i);
                    }
                }
            }
            v.set_data(v.get_data() + newcounts);
        }
        
     }
开发者ID:Prokopp,项目名称:graphchi-cpp,代码行数:73,代码来源:trianglecounting.cpp


注:本文中的graphchi_vertex::sort_edges_indirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。