MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / Graph_GetNodeDegree

Function Graph_GetNodeDegree

src/graph/graph.c:946–1048  ·  view source on GitHub ↗

returns node incoming/outgoing degree

Source from the content-addressed store, hash-verified

944
945// returns node incoming/outgoing degree
946uint64_t Graph_GetNodeDegree
947(
948 const Graph *g, // graph to inquery
949 const Node *n, // node to get degree of
950 GRAPH_EDGE_DIR dir, // incoming/outgoing/both
951 RelationID edgeType // relation type
952) {
953 ASSERT(g != NULL);
954 ASSERT(n != NULL);
955
956 NodeID srcID = ENTITY_GET_ID(n);
957 NodeID destID = INVALID_ENTITY_ID;
958 EdgeID edgeID = INVALID_ENTITY_ID;
959 uint64_t edge_count = 0;
960 RG_Matrix M = NULL;
961 RG_Matrix TM = NULL;
962 RG_MatrixTupleIter it = {0};
963
964 if(edgeType == GRAPH_UNKNOWN_RELATION) {
965 return 0; // no edges
966 }
967
968 bool outgoing = (dir == GRAPH_EDGE_DIR_OUTGOING ||
969 dir == GRAPH_EDGE_DIR_BOTH);
970
971 bool incoming = (dir == GRAPH_EDGE_DIR_INCOMING ||
972 dir == GRAPH_EDGE_DIR_BOTH);
973
974 // relationships to consider
975 int start_rel;
976 int end_rel;
977
978 if(edgeType != GRAPH_NO_RELATION) {
979 // consider only specified relationship
980 start_rel = edgeType;
981 end_rel = start_rel + 1;
982 } else {
983 // consider all relationship types
984 start_rel = 0;
985 end_rel = Graph_RelationTypeCount(g);
986 }
987
988 // for each relationship type to consider
989 for(edgeType = start_rel; edgeType < end_rel; edgeType++) {
990 M = Graph_GetRelationMatrix(g, edgeType, false);
991
992 //----------------------------------------------------------------------
993 // outgoing edges
994 //----------------------------------------------------------------------
995
996 // TODO: revisit once we get rid of MULTI-EDGE hack
997 if(outgoing) {
998 // construct an iterator to traverse over the source node row,
999 // containing all outgoing edges
1000 RG_MatrixTupleIter_AttachRange(&it, M, srcID, srcID);
1001 // scan row
1002 while(RG_MatrixTupleIter_next_UINT64(&it, NULL, &destID, &edgeID)
1003 == GrB_SUCCESS) {

Callers 1

_AR_NodeDegreeFunction · 0.85

Calls 8

Graph_RelationTypeCountFunction · 0.85
Graph_GetRelationMatrixFunction · 0.85
array_lenFunction · 0.85

Tested by

no test coverage detected