Skip to content
GraphNodeForeachPredecessor

GraphNodeForeachPredecessor

Description

Iterate over each incoming predecessor of a node handle.

The predecessor loop variable is also a GraphNode handle. Structural graph mutation is not allowed while the iterator is active.

Parameters

Name Direction Description
node in Destination node handle.
predecessor in Name of the GraphNode loop variable used for incoming predecessors.

Success

Loop body runs once per incoming predecessor of node in insertion order.

Failure

Aborts the traversal on a structural mutation (epoch mismatch) or when node carries no owning graph handle.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    static bool test_graph_foreach_predecessors(void) {
        WriteFmt("Testing GraphNodeForeachPredecessor\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        u64 predecessor_count = 0;
    
        GraphNodeForeachPredecessor(GraphGetNode(&graph, d), predecessor) {
            predecessor_sum   += GraphNodeData(&graph, predecessor);
            predecessor_count += 1;
    
    static bool test_graph_predecessor_iteration_rejects_structural_mutation_deadend(void) {
        WriteFmt("Testing GraphNodeForeachPredecessor rejects structural mutation (should abort)\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        GraphAddEdge(&graph, b, c);
    
        GraphNodeForeachPredecessor(GraphGetNode(&graph, c), predecessor) {
            (void)predecessor;
            (void)GraphAddEdge(&graph, d, c);
Last updated on