GraphPredecessorAt
Description
Access incoming predecessor id at given offset.
Parameters
| Name | Direction | Description |
|---|---|---|
g |
in | Graph to query. |
node_id |
in | Destination node id. |
predecessor_idx |
in | Index in incoming predecessor list, [0, in_degree). |
Success
Returns the GraphNodeId at the requested position in the reverse predecessor list. The graph is not modified.
Failure
Does not return - aborts via LOG_FATAL for an invalid or stale node_id or out-of-bounds predecessor_idx.
Usage example (Cross-references)
Usage examples (Cross-references)
result = result && GraphNeighborAt(&graph, a, 0) == b && GraphNeighborAt(&graph, a, 1) == c;
result = result && GraphNeighborAt(&graph, c, 0) == a;
result = result && GraphPredecessorAt(&graph, a, 0) == c;
result = result && GraphPredecessorAt(&graph, b, 0) == a;
result = result && GraphPredecessorAt(&graph, c, 0) == a; result = result && GraphNeighborAt(&graph, c, 0) == a;
result = result && GraphPredecessorAt(&graph, a, 0) == c;
result = result && GraphPredecessorAt(&graph, b, 0) == a;
result = result && GraphPredecessorAt(&graph, c, 0) == a; result = result && GraphPredecessorAt(&graph, a, 0) == c;
result = result && GraphPredecessorAt(&graph, b, 0) == a;
result = result && GraphPredecessorAt(&graph, c, 0) == a;
GraphDeinit(&graph);
static bool test_graph_predecessor_access_oob_deadend(void) {
WriteFmt("Testing GraphPredecessorAt out-of-bounds access (should abort)\n");
DefaultAllocator alloc = DefaultAllocatorInit();
GraphAddEdge(&graph, a, b);
(void)GraphPredecessorAt(&graph, a, 0);
GraphDeinit(&graph);- In
Graph.Ops.c:66:
result = result && (GraphInDegree(&graph, c) == 0);
result = result && GraphHasEdge(&graph, c, a);
result = result && (GraphPredecessorAt(&graph, a, 0) == c);
GraphNodeId d = GraphAddNodeR(&graph, 40);- In
Graph.Ops.c:149:
result = result && (GraphInDegree(&graph, c) == 1);
result = result && (GraphNeighborAt(&graph, a, 0) == c);
result = result && (GraphPredecessorAt(&graph, c, 0) == a);
GraphDeinit(&graph);- In
Graph.Ops.c:233:
result = result && (GraphInDegree(&graph, a) == 1);
result = result && (GraphNeighborAt(&graph, a, 0) == a);
result = result && (GraphPredecessorAt(&graph, a, 0) == a);
result = result && GraphMarkEdgeForRemoval(&graph, a, a);
result = result && (GraphCommitChanges(&graph) == 1); result = result && GraphNeighborAt(&graph, a, 0) == b;
result = result && GraphNeighborAt(&graph, a, 1) == c;
result = result && GraphPredecessorAt(&graph, b, 0) == a;
result = result && GraphPredecessorAt(&graph, c, 0) == a; result = result && GraphNeighborAt(&graph, a, 1) == c;
result = result && GraphPredecessorAt(&graph, b, 0) == a;
result = result && GraphPredecessorAt(&graph, c, 0) == a;
GraphDeinit(&graph); result = result && (GraphInDegree(&graph, a) == 3);
result = result && (GraphNeighborAt(&graph, a, 0) == a);
result = result && (GraphPredecessorAt(&graph, a, 0) == a);
result = result && (GraphPredecessorAt(&graph, a, 1) == b);
result = result && (GraphPredecessorAt(&graph, a, 2) == c); result = result && (GraphNeighborAt(&graph, a, 0) == a);
result = result && (GraphPredecessorAt(&graph, a, 0) == a);
result = result && (GraphPredecessorAt(&graph, a, 1) == b);
result = result && (GraphPredecessorAt(&graph, a, 2) == c); result = result && (GraphPredecessorAt(&graph, a, 0) == a);
result = result && (GraphPredecessorAt(&graph, a, 1) == b);
result = result && (GraphPredecessorAt(&graph, a, 2) == c);
GraphDeinit(&graph);
Last updated on