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

Function _DeleteEntities

src/execution_plan/ops/op_delete.c:30–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30static void _DeleteEntities
31(
32 OpDelete *op
33) {
34 uint node_count = array_len(op->deleted_nodes);
35 uint edge_count = array_len(op->deleted_edges);
36 uint node_deleted = 0;
37 uint edge_deleted = 0;
38
39 // nothing to delete, quickly return
40 if((node_count + edge_count) == 0) return;
41
42 Graph *g = op->gc->g;
43 GraphContext *gc = op->gc;
44
45 //--------------------------------------------------------------------------
46 // removing node duplicates
47 //--------------------------------------------------------------------------
48
49 // remove node duplicates
50 Node *nodes = op->deleted_nodes;
51 Node *distinct_nodes = array_new(Node, 1);
52
53 qsort(nodes, node_count, sizeof(Node),
54 (int(*)(const void*, const void*))entity_cmp);
55
56 for(uint i = 0; i < node_count; i++) {
57 while(i < node_count - 1 &&
58 ENTITY_GET_ID(nodes + i) == ENTITY_GET_ID(nodes + i + 1)) {
59 i++;
60 }
61
62 Node *n = nodes + i;
63
64 // skip already deleted nodes
65 if(Graph_EntityIsDeleted((GraphEntity *)n)) {
66 continue;
67 }
68
69 array_append(distinct_nodes, *n);
70
71 // mark node's edges for deletion
72 Graph_GetNodeEdges(g, n, GRAPH_EDGE_DIR_BOTH, GRAPH_NO_RELATION,
73 &op->deleted_edges);
74 }
75
76 node_count = array_len(distinct_nodes);
77 edge_count = array_len(op->deleted_edges);
78
79 //--------------------------------------------------------------------------
80 // remove edge duplicates
81 //--------------------------------------------------------------------------
82
83 Edge *edges = op->deleted_edges;
84 Edge *distinct_edges = array_new(Edge, 1);
85
86 qsort(edges, edge_count, sizeof(Edge),
87 (int(*)(const void*, const void*))entity_cmp);

Callers 1

DeleteConsumeFunction · 0.85

Calls 7

array_lenFunction · 0.85
Graph_EntityIsDeletedFunction · 0.85
Graph_GetNodeEdgesFunction · 0.85
QueryCtx_LockForCommitFunction · 0.85
DeleteEdgesFunction · 0.85
DeleteNodesFunction · 0.85
array_freeFunction · 0.85

Tested by

no test coverage detected