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

Function QueryGraph_MatrixRepresentation

src/graph/query_graph.c:730–770  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

728}
729
730GrB_Matrix QueryGraph_MatrixRepresentation
731(
732 const QueryGraph *qg
733) {
734 ASSERT(qg != NULL);
735
736 // make a clone of the given graph as we're about to modify it
737 QueryGraph *qg_clone = QueryGraph_Clone(qg);
738
739 // give an ID for each node, abuse of `labelID`
740 uint node_count = QueryGraph_NodeCount(qg_clone);
741 for(uint i = 0; i < node_count; i++) {
742 QGNode *n = qg_clone->nodes[i];
743 if(QGNode_LabelCount(n) == 0) QGNode_AddLabel(n, "", i);
744 else n->labelsID[0] = i;
745 }
746
747 GrB_Matrix m; // matrix representation of QueryGraph
748 GrB_Info res = GrB_Matrix_new(&m, GrB_BOOL, node_count, node_count);
749 UNUSED(res);
750 ASSERT(res == GrB_SUCCESS);
751
752 // build matrix representation of query graph
753 for(uint i = 0; i < node_count; i++) {
754 const QGNode *n = qg_clone->nodes[i];
755 GrB_Index src = QGNode_GetLabelID(n, 0);
756 uint outgoing_degree = QGNode_OutgoingDegree(n);
757
758 for(uint j = 0; j < outgoing_degree; j++) {
759 const QGEdge *e = n->outgoing_edges[j];
760 GrB_Index dest = QGNode_GetLabelID(e->dest, 0);
761
762 // populate `m`
763 res = GrB_Matrix_setElement_BOOL(m, true, src, dest);
764 ASSERT(res == GrB_SUCCESS);
765 }
766 }
767
768 QueryGraph_Free(qg_clone);
769 return m;
770}
771
772void QueryGraph_Print
773(

Callers 1

IsAcyclicGraphFunction · 0.85

Calls 8

QueryGraph_CloneFunction · 0.85
QueryGraph_NodeCountFunction · 0.85
QGNode_LabelCountFunction · 0.85
QGNode_AddLabelFunction · 0.85
GrB_Matrix_newFunction · 0.85
QGNode_GetLabelIDFunction · 0.85
QGNode_OutgoingDegreeFunction · 0.85
QueryGraph_FreeFunction · 0.85

Tested by

no test coverage detected