GraphNeighborAt
Description
Access outgoing neighbor id at given offset.
Parameters
| Name | Direction | Description |
|---|---|---|
g |
in | Graph to query. |
node_id |
in | Source node id. |
neighbor_idx |
in | Index in outgoing neighbor list, [0, out_degree). |
Success
Returns the GraphNodeId at the requested position in the outgoing adjacency 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 neighbor_idx.
Usage example (Cross-references)
Usage examples (Cross-references)
result = result && GraphInDegree(&graph, b) == 1;
result = result && GraphInDegree(&graph, c) == 1;
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 && GraphInDegree(&graph, c) == 1;
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;
static bool test_graph_neighbor_access_oob_deadend(void) {
WriteFmt("Testing GraphNeighborAt out-of-bounds access (should abort)\n");
DefaultAllocator alloc = DefaultAllocatorInit();
GraphAddEdge(&graph, a, b);
(void)GraphNeighborAt(&graph, b, 0);
GraphDeinit(&graph);- In
Graph.Ops.c:148:
result = result && (GraphInDegree(&graph, b) == 0);
result = result && (GraphInDegree(&graph, c) == 1);
result = result && (GraphNeighborAt(&graph, a, 0) == c);
result = result && (GraphPredecessorAt(&graph, c, 0) == a);- In
Graph.Ops.c:232:
result = result && (GraphOutDegree(&graph, a) == 1);
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 && GraphInDegree(&graph, b) == 1;
result = result && GraphInDegree(&graph, c) == 1;
result = result && GraphNeighborAt(&graph, a, 0) == b;
result = result && GraphNeighborAt(&graph, a, 1) == c;
result = result && GraphPredecessorAt(&graph, b, 0) == a; result = result && GraphInDegree(&graph, c) == 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 && (GraphOutDegree(&graph, a) == 1);
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);
Last updated on