removes edges from Graph and updates graph relevant matrices
| 1088 | |
| 1089 | // removes edges from Graph and updates graph relevant matrices |
| 1090 | void Graph_DeleteEdges |
| 1091 | ( |
| 1092 | Graph *g, |
| 1093 | Edge *edges, |
| 1094 | uint64_t n |
| 1095 | ) { |
| 1096 | ASSERT(g != NULL); |
| 1097 | ASSERT(n > 0); |
| 1098 | ASSERT(edges != NULL); |
| 1099 | |
| 1100 | uint64_t x; |
| 1101 | RG_Matrix R; |
| 1102 | RG_Matrix M; |
| 1103 | GrB_Info info; |
| 1104 | bool entry_deleted; |
| 1105 | |
| 1106 | MATRIX_POLICY policy = Graph_SetMatrixPolicy(g, SYNC_POLICY_NOP); |
| 1107 | |
| 1108 | for (uint i = 0; i < n; i++) { |
| 1109 | Edge *e = edges + i; |
| 1110 | int r = Edge_GetRelationID(e); |
| 1111 | NodeID src_id = Edge_GetSrcNodeID(e); |
| 1112 | NodeID dest_id = Edge_GetDestNodeID(e); |
| 1113 | |
| 1114 | ASSERT(!DataBlock_ItemIsDeleted((void *)e->attributes)); |
| 1115 | |
| 1116 | // an edge of type r has just been deleted, update statistics |
| 1117 | GraphStatistics_DecEdgeCount(&g->stats, r, 1); |
| 1118 | |
| 1119 | R = Graph_GetRelationMatrix(g, r, false); |
| 1120 | |
| 1121 | // single edge of type R connecting src to dest, delete entry |
| 1122 | info = RG_Matrix_removeEntry_UINT64(R, src_id, dest_id, ENTITY_GET_ID(e), &entry_deleted); |
| 1123 | ASSERT(info == GrB_SUCCESS); |
| 1124 | |
| 1125 | if(entry_deleted) { |
| 1126 | // TODO: consider making ADJ UINT64_T where ADJ[i,j] = #connections |
| 1127 | // drop the entry once it reaches 0 |
| 1128 | // |
| 1129 | // see if source is connected to destination with additional edges |
| 1130 | bool connected = false; |
| 1131 | int relationCount = Graph_RelationTypeCount(g); |
| 1132 | for(int i = 0; i < relationCount; i++) { |
| 1133 | if(i == r) continue; |
| 1134 | M = Graph_GetRelationMatrix(g, i, false); |
| 1135 | info = RG_Matrix_extractElement_UINT64(&x, M, src_id, dest_id); |
| 1136 | if(info == GrB_SUCCESS) { |
| 1137 | connected = true; |
| 1138 | break; |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | // there are no additional edges connecting source to destination |
| 1143 | // remove edge from THE adjacency matrix |
| 1144 | if(!connected) { |
| 1145 | M = Graph_GetAdjacencyMatrix(g, false); |
| 1146 | info = RG_Matrix_removeElement_BOOL(M, src_id, dest_id); |
| 1147 | ASSERT(info == GrB_SUCCESS); |