GraphAddEdge
Description
Add a directed edge from one node to another. Both endpoints must be existing node ids in the same graph.
Parameters
| Name | Direction | Description |
|---|---|---|
g |
in,out | Graph handle. |
from |
in | Source GraphNodeId. |
to |
in | Destination GraphNodeId. |
Success
Returns true. The edge entry has been appended to the outgoing-neighbour list of from and to the reverse predecessor list of to; edge_count grows by one.
Failure
Returns false on allocation failure for either side of the adjacency entry. The graph is unchanged. A reference to a non-live from or to node id is a caller bug and aborts via LOG_FATAL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Insert.h:172:
#define GraphMustAddEdge(g, from, to) \
do { \
if (!GraphAddEdge((g), (from), (to))) { \
LOG_FATAL("GraphMustAddEdge failed"); \
} \- In
Ops.c:45:
GraphNodeId c = GraphAddNodeR(&graph, 30);
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, b, c);
GraphAddEdge(&graph, c, a);- In
Ops.c:46:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, b, c);
GraphAddEdge(&graph, c, a);- In
Ops.c:47:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, b, c);
GraphAddEdge(&graph, c, a);
GraphForeachNode(&graph, node) {- In
Ops.c:119:
GraphNodeId c = GraphAddNodeR(&graph, 30);
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, b, c);- In
Ops.c:120:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, b, c);- In
Ops.c:121:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, b, c);
GraphForeachNode(&graph, node) {- In
Ops.c:167:
GraphNodeId b = GraphAddNodeR(&graph, 20);
GraphAddEdge(&graph, a, b);
bool result = !GraphEdgeMarkedForRemoval(&graph, a, b);- In
Ops.c:197:
GraphNodeId c = GraphAddNodeR(&graph, 30);
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);- In
Ops.c:198:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
bool result = GraphMarkEdgeForRemoval(&graph, a, b);- In
Ops.c:229:
GraphNodeId a = GraphAddNodeR(&graph, 10);
bool result = GraphAddEdge(&graph, a, a);
result = result && (GraphOutDegree(&graph, a) == 1);
result = result && (GraphInDegree(&graph, a) == 1);- In
Ops.c:258:
GraphNodeId d = GraphAddNodeR(&graph, 40);
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, b, c);
GraphAddEdge(&graph, d, b);- In
Ops.c:259:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, b, c);
GraphAddEdge(&graph, d, b);- In
Ops.c:260:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, b, c);
GraphAddEdge(&graph, d, b);
bool result = GraphMarkEdgeForRemoval(&graph, a, b);- In
Ops.c:359:
// marked node (a->b) comes second, so the loop must advance past the kept
// edge to reach and drop a->b.
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, a, b);- In
Ops.c:360:
// edge to reach and drop a->b.
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, a, b);
GraphMarkNodeForDeletion(GraphGetNode(&graph, b));- In
Ops.c:467:
GraphNodeId c = GraphAddNodeR(&graph, 30);
GraphAddEdge(&graph, a, c);
// First commit frees b's slot (free-list entry, generation bumped).
- In
Ops.c:624:
// a.out = [b]; b.in = [a]; the buffers physically hold those ids.
bool result = GraphAddEdge(&graph, a, b);
// Stage a pending removal for a->b (the edge is present so this validates).
- In
Init.c:37:
u64 slot_index;
result = result && GraphAddEdge(&graph, first_id, second_id);
result = result && GraphAddEdge(&graph, second_id, third_id);
result = result && GraphAddEdge(&graph, third_id, first_id);- In
Init.c:38:
result = result && GraphAddEdge(&graph, first_id, second_id);
result = result && GraphAddEdge(&graph, second_id, third_id);
result = result && GraphAddEdge(&graph, third_id, first_id);
result = result && GraphAddEdge(&graph, third_id, third_id);- In
Init.c:39:
result = result && GraphAddEdge(&graph, first_id, second_id);
result = result && GraphAddEdge(&graph, second_id, third_id);
result = result && GraphAddEdge(&graph, third_id, first_id);
result = result && GraphAddEdge(&graph, third_id, third_id);
result = result && (GraphNodeVisit(GraphGetNode(&graph, first_id)) == 1);- In
Init.c:40:
result = result && GraphAddEdge(&graph, second_id, third_id);
result = result && GraphAddEdge(&graph, third_id, first_id);
result = result && GraphAddEdge(&graph, third_id, third_id);
result = result && (GraphNodeVisit(GraphGetNode(&graph, first_id)) == 1);
result = result && GraphMarkNodeForDeletion(GraphGetNode(&graph, second_id));- In
Init.c:226:
GraphNodeId b = GraphAddNodeR(&graph, 20);
GraphAddEdge(&graph, a, b);
GraphMarkEdgeForRemoval(&graph, a, b); // pending_edge_removals gains backing
- In
Insert.c:55:
static bool test_graph_add_edge_dedup(void) {
WriteFmt("Testing GraphAddEdge deduplication\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Insert.c:66:
GraphNodeId c = GraphAddNodeR(&graph, 3);
bool result = GraphAddEdge(&graph, a, b);
result = result && GraphAddEdge(&graph, a, c);
result = result && !GraphAddEdge(&graph, a, b);- In
Insert.c:67:
bool result = GraphAddEdge(&graph, a, b);
result = result && GraphAddEdge(&graph, a, c);
result = result && !GraphAddEdge(&graph, a, b);
result = result && GraphEdgeCount(&graph) == 2;- In
Insert.c:68:
bool result = GraphAddEdge(&graph, a, b);
result = result && GraphAddEdge(&graph, a, c);
result = result && !GraphAddEdge(&graph, a, b);
result = result && GraphEdgeCount(&graph) == 2;
result = result && GraphOutDegree(&graph, a) == 2;- In
Insert.c:96:
GraphNodeId c = GraphAddNodeR(&graph, 3);
bool result = GraphAddEdge(&graph, a, a);
result = result && GraphAddEdge(&graph, b, a);
result = result && GraphAddEdge(&graph, c, a);- In
Insert.c:97:
bool result = GraphAddEdge(&graph, a, a);
result = result && GraphAddEdge(&graph, b, a);
result = result && GraphAddEdge(&graph, c, a);
result = result && !GraphAddEdge(&graph, a, a);- In
Insert.c:98:
bool result = GraphAddEdge(&graph, a, a);
result = result && GraphAddEdge(&graph, b, a);
result = result && GraphAddEdge(&graph, c, a);
result = result && !GraphAddEdge(&graph, a, a);
result = result && (GraphEdgeCount(&graph) == 3);- In
Insert.c:99:
result = result && GraphAddEdge(&graph, b, a);
result = result && GraphAddEdge(&graph, c, a);
result = result && !GraphAddEdge(&graph, a, a);
result = result && (GraphEdgeCount(&graph) == 3);
result = result && (GraphOutDegree(&graph, a) == 1);- In
Insert.c:231:
// Re-dirty the validator so the next ValidateGraph deep-scans every slot.
bool result = GraphAddEdge(&graph, a, c);
ValidateGraph(&graph);- In
Type.c:245:
GraphNodeId c = GraphAddNodeR(&graph, 30);
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, c, b);- In
Type.c:246:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, c, b);
GenericGraphSlot *b_slot = mutant_slot(&graph, b);- In
Type.c:276:
GraphNodeId c = GraphAddNodeR(&graph, 30);
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, b, c);- In
Type.c:277:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, b, c);- In
Type.c:278:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, b, c);
GenericGraphSlot *c_slot = mutant_slot(&graph, c);- In
Type.c:311:
GraphNodeId c = GraphAddNodeR(&graph, 30);
GraphAddEdge(&graph, b, a);
GraphAddEdge(&graph, b, c);- In
Type.c:312:
GraphAddEdge(&graph, b, a);
GraphAddEdge(&graph, b, c);
GenericGraphSlot *b_slot = mutant_slot(&graph, b);- In
Type.c:342:
GraphNodeId c = GraphAddNodeR(&graph, 30);
GraphAddEdge(&graph, b, a);
GraphAddEdge(&graph, c, a);
GraphAddEdge(&graph, c, b);- In
Type.c:343:
GraphAddEdge(&graph, b, a);
GraphAddEdge(&graph, c, a);
GraphAddEdge(&graph, c, b);- In
Type.c:344:
GraphAddEdge(&graph, b, a);
GraphAddEdge(&graph, c, a);
GraphAddEdge(&graph, c, b);
GenericGraphSlot *c_slot = mutant_slot(&graph, c);- In
Type.c:471:
GraphNodeId d = GraphAddNodeR(&graph, 40);
GraphAddEdge(&graph, a, b);
(void)GraphMarkEdgeForRemoval(&graph, a, b);- In
Type.c:502:
GraphNodeId d = GraphAddNodeR(&graph, 40);
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
(void)GraphMarkEdgeForRemoval(&graph, a, b);- In
Type.c:503:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
(void)GraphMarkEdgeForRemoval(&graph, a, b);
(void)GraphMarkEdgeForRemoval(&graph, a, c);- In
Type.c:536:
GraphNodeId c = GraphAddNodeR(&graph, 30);
(void)GraphAddEdge(&graph, a, b);
(void)GraphMarkEdgeForRemoval(&graph, a, b);- In
Foreach.c:102:
GraphNodeId echo = city_add_intersection(&graph, &index, &s_echo, &alloc);
GraphAddEdge(&graph, alpha, beta);
GraphAddEdge(&graph, beta, gamma);
GraphAddEdge(&graph, gamma, delta);- In
Foreach.c:103:
GraphAddEdge(&graph, alpha, beta);
GraphAddEdge(&graph, beta, gamma);
GraphAddEdge(&graph, gamma, delta);
GraphAddEdge(&graph, gamma, echo);- In
Foreach.c:104:
GraphAddEdge(&graph, alpha, beta);
GraphAddEdge(&graph, beta, gamma);
GraphAddEdge(&graph, gamma, delta);
GraphAddEdge(&graph, gamma, echo);
GraphAddEdge(&graph, echo, beta);- In
Foreach.c:105:
GraphAddEdge(&graph, beta, gamma);
GraphAddEdge(&graph, gamma, delta);
GraphAddEdge(&graph, gamma, echo);
GraphAddEdge(&graph, echo, beta);- In
Foreach.c:106:
GraphAddEdge(&graph, gamma, delta);
GraphAddEdge(&graph, gamma, echo);
GraphAddEdge(&graph, echo, beta);
bool result = city_reachable(&graph, &index, &s_alpha, &s_delta);- In
Foreach.c:147:
GraphNodeId d = GraphAddNodeR(&graph, 4);
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, b, d);- In
Foreach.c:148:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, b, d);
GraphAddEdge(&graph, c, d);- In
Foreach.c:149:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, b, d);
GraphAddEdge(&graph, c, d);- In
Foreach.c:150:
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, b, d);
GraphAddEdge(&graph, c, d);
GraphForeachNode(&graph, node) {- In
Foreach.c:184:
GraphNodeId d = GraphAddNodeR(&graph, 4);
GraphAddEdge(&graph, a, d);
GraphAddEdge(&graph, b, d);
GraphAddEdge(&graph, c, d);- In
Foreach.c:185:
GraphAddEdge(&graph, a, d);
GraphAddEdge(&graph, b, d);
GraphAddEdge(&graph, c, d);
GraphAddEdge(&graph, a, b);- In
Foreach.c:186:
GraphAddEdge(&graph, a, d);
GraphAddEdge(&graph, b, d);
GraphAddEdge(&graph, c, d);
GraphAddEdge(&graph, a, b);- In
Foreach.c:187:
GraphAddEdge(&graph, b, d);
GraphAddEdge(&graph, c, d);
GraphAddEdge(&graph, a, b);
u64 predecessor_sum = 0;- In
Foreach.c:240:
GraphNodeId c = GraphAddNodeR(&graph, 3);
GraphAddEdge(&graph, a, b);
GraphNodeForeachNeighbor(GraphGetNode(&graph, a), neighbor) {- In
Foreach.c:244:
GraphNodeForeachNeighbor(GraphGetNode(&graph, a), neighbor) {
(void)neighbor;
(void)GraphAddEdge(&graph, a, c);
}- In
Foreach.c:265:
GraphNodeId d = GraphAddNodeR(&graph, 4);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, b, c);- In
Foreach.c:266:
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, b, c);
GraphNodeForeachPredecessor(GraphGetNode(&graph, c), predecessor) {- In
Foreach.c:270:
GraphNodeForeachPredecessor(GraphGetNode(&graph, c), predecessor) {
(void)predecessor;
(void)GraphAddEdge(&graph, d, c);
}- In
Foreach.c:372:
GraphNodeId b = GraphAddNodeR(&graph, 20);
GraphAddEdge(&graph, a, b);
// Begin runs the deep validator (clears the validated bit) and snapshots
- In
Foreach.c:409:
GraphNodeId b = GraphAddNodeR(&graph, 20);
GraphAddEdge(&graph, a, b);
GenericGraphPredecessorIter iter = graph_predecessor_iter_begin(GraphGetNode(&graph, b));- In
Access.c:28:
GraphNodeId c = GraphAddNodeR(&graph, 30);
GraphNode node_b;
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, c, a);- In
Access.c:29:
GraphNode node_b;
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, c, a);- In
Access.c:30:
GraphAddEdge(&graph, a, b);
GraphAddEdge(&graph, a, c);
GraphAddEdge(&graph, c, a);
ValidateGraph(&graph);- In
Access.c:70:
GraphNodeId blue = GraphAddNodeR(&graph, "blue");
GraphAddEdge(&graph, red, green);
GraphAddEdge(&graph, green, blue);- In
Access.c:71:
GraphAddEdge(&graph, red, green);
GraphAddEdge(&graph, green, blue);
bool result = GraphHasEdge(&graph, red, green);- In
Access.c:113:
GraphNodeId b = GraphAddNodeR(&graph, 20);
GraphAddEdge(&graph, a, b);
(void)GraphPredecessorAt(&graph, a, 0);- In
Access.c:132:
GraphNodeId b = GraphAddNodeR(&graph, 20);
GraphAddEdge(&graph, a, b);
(void)GraphNeighborAt(&graph, b, 0);
Last updated on