Skip to content
GraphPredecessorAt

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.

Failure

Does not return on invalid node id or out-of-bounds predecessor index.

Usage example (Cross-references)

Usage examples (Cross-references)
        result = result && (GraphInDegree(&graph, c) == 0);
        result = result && GraphHasEdge(&graph, c, a);
        result = result && (GraphPredecessorAt(&graph, a, 0) == c);
    
        GraphNodeId d = GraphAddNodeR(&graph, 40);
        result = result && (GraphInDegree(&graph, c) == 1);
        result = result && (GraphNeighborAt(&graph, a, 0) == c);
        result = result && (GraphPredecessorAt(&graph, c, 0) == a);
    
        GraphDeinit(&graph);
        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 && 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");
    
        typedef Graph(int) IntGraph;
    
        GraphAddEdge(&graph, a, b);
        (void)GraphPredecessorAt(&graph, a, 0);
    
        GraphDeinit(&graph);
        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