retrieves all either incoming or outgoing edges to/from given node N, depending on given direction
| 857 | // retrieves all either incoming or outgoing edges |
| 858 | // to/from given node N, depending on given direction |
| 859 | void Graph_GetNodeEdges |
| 860 | ( |
| 861 | const Graph *g, // graph to collect edges from |
| 862 | const Node *n, // either source or destination node |
| 863 | GRAPH_EDGE_DIR dir, // edge direction ->, <-, <-> |
| 864 | RelationID edgeType, // relationship type |
| 865 | Edge **edges // [output] array of edges |
| 866 | ) { |
| 867 | ASSERT(g); |
| 868 | ASSERT(n); |
| 869 | ASSERT(edges); |
| 870 | |
| 871 | GrB_Type t; |
| 872 | GrB_Info info; |
| 873 | RG_MatrixTupleIter it = {0}; |
| 874 | RG_Matrix M = NULL; |
| 875 | RG_Matrix TM = NULL; |
| 876 | NodeID srcID = ENTITY_GET_ID(n); |
| 877 | NodeID destID = INVALID_ENTITY_ID; |
| 878 | EdgeID edgeID = INVALID_ENTITY_ID; |
| 879 | UNUSED(info); |
| 880 | |
| 881 | if(edgeType == GRAPH_UNKNOWN_RELATION) return; |
| 882 | |
| 883 | bool outgoing = (dir == GRAPH_EDGE_DIR_OUTGOING || |
| 884 | dir == GRAPH_EDGE_DIR_BOTH); |
| 885 | |
| 886 | bool incoming = (dir == GRAPH_EDGE_DIR_INCOMING || |
| 887 | dir == GRAPH_EDGE_DIR_BOTH); |
| 888 | |
| 889 | // if a relationship type is specified, |
| 890 | // retrieve the appropriate relation matrix |
| 891 | // otherwise use the overall adjacency matrix |
| 892 | M = Graph_GetRelationMatrix(g, edgeType, false); |
| 893 | |
| 894 | if(outgoing) { |
| 895 | info = RG_Matrix_type(&t, M); |
| 896 | ASSERT(info == GrB_SUCCESS); |
| 897 | ASSERT(t == GrB_UINT64 || t == GrB_BOOL); |
| 898 | // construct an iterator to traverse over the source node row, |
| 899 | // containing all outgoing edges |
| 900 | RG_MatrixTupleIter_AttachRange(&it, M, srcID, srcID); |
| 901 | if(t == GrB_UINT64) { |
| 902 | while(RG_MatrixTupleIter_next_UINT64(&it, NULL, &destID, &edgeID) == GrB_SUCCESS) { |
| 903 | // collect all edges (src)->(dest) |
| 904 | _CollectEdgesFromEntry(g, srcID, destID, edgeType, edgeID, edges); |
| 905 | } |
| 906 | } else { |
| 907 | while(RG_MatrixTupleIter_next_BOOL(&it, NULL, &destID, NULL) == GrB_SUCCESS) { |
| 908 | Graph_GetEdgesConnectingNodes(g, srcID, destID, edgeType, edges); |
| 909 | } |
| 910 | } |
| 911 | RG_MatrixTupleIter_detach(&it); |
| 912 | } |
| 913 | |
| 914 | if(incoming) { |
| 915 | // if a relationship type is specified, retrieve the appropriate |
| 916 | // transposed relation matrix, |