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

Function _build_graph

tests/unit/test_algebraic_expression.c:93–138  ·  view source on GitHub ↗

Create a graph containing: * Entities: 'people' and 'countries'. * Relations: 'friend', 'visit' and 'war'. */

Source from the content-addressed store, hash-verified

91 * Entities: 'people' and 'countries'.
92 * Relations: 'friend', 'visit' and 'war'. */
93static void _build_graph() {
94 GraphContext *gc = QueryCtx_GetGraphCtx();
95
96 Node n;
97 Graph *g = gc->g;
98 Graph_AcquireWriteLock(g);
99
100 size_t city_count = 2;
101 size_t person_count = 2;
102 size_t node_count = person_count + city_count;
103
104 // Introduce person and country labels.
105 int city_label[1] = {GraphContext_GetSchema(gc, "City", SCHEMA_NODE)->id};
106 int person_label[1] = {GraphContext_GetSchema(gc, "Person", SCHEMA_NODE)->id};
107 Graph_AllocateNodes(g, node_count);
108
109 for(int i = 0; i < person_count; i++) {
110 n = GE_NEW_NODE();
111 Graph_CreateNode(g, &n, person_label, 1);
112 }
113
114 for(int i = 0; i < city_count; i++) {
115 n = GE_NEW_NODE();
116 Graph_CreateNode(g, &n, city_label, 1);
117 }
118
119 // Creates a relation matrices.
120 GrB_Index war_relation_id = GraphContext_GetSchema(gc, "war", SCHEMA_EDGE)->id;
121 GrB_Index visit_relation_id = GraphContext_GetSchema(gc, "visit", SCHEMA_EDGE)->id;
122 GrB_Index friend_relation_id = GraphContext_GetSchema(gc, "friend", SCHEMA_EDGE)->id;
123
124 // Introduce relations, connect nodes.
125 Edge e;
126 Graph_CreateEdge(g, 0, 1, friend_relation_id, &e);
127 Graph_CreateEdge(g, 1, 0, friend_relation_id, &e);
128
129 Graph_CreateEdge(g, 0, 2, visit_relation_id, &e);
130 Graph_CreateEdge(g, 0, 3, visit_relation_id, &e);
131 Graph_CreateEdge(g, 1, 2, visit_relation_id, &e);
132
133 Graph_CreateEdge(g, 2, 3, war_relation_id, &e);
134 Graph_CreateEdge(g, 3, 2, war_relation_id, &e);
135
136 Graph_ApplyAllPending(g, true);
137 Graph_ReleaseLock(g);
138}
139
140static void _bind_matrices() {
141 int mat_id;

Callers 1

setupFunction · 0.85

Calls 8

QueryCtx_GetGraphCtxFunction · 0.85
Graph_AcquireWriteLockFunction · 0.85
GraphContext_GetSchemaFunction · 0.85
Graph_AllocateNodesFunction · 0.85
Graph_CreateNodeFunction · 0.85
Graph_CreateEdgeFunction · 0.85
Graph_ApplyAllPendingFunction · 0.85
Graph_ReleaseLockFunction · 0.85

Tested by

no test coverage detected