Skip to content

GraphNodeData

Description

Access payload through a GraphNode traversal handle.

Parameters

Name Direction Description
g in Graph owning the node.
node in GraphNode handle to access.

Success

Returns the payload as a value of type GRAPH_NODE_TYPE(g). The graph is not modified. The handle is also validated against g so a handle from a different graph aborts.

Failure

Does not return - aborts via LOG_FATAL for an invalid handle or graph/handle mismatch (caller bug).

Usage example (Cross-references)

Usage examples (Cross-references)
        result = result && GraphContainsNode(&graph, a) && GraphContainsNode(&graph, b) && GraphContainsNode(&graph, c);
        result = result && GraphNodeAt(&graph, b) == 25;
        result = result && GraphNodeData(&graph, node_b) == 25;
        result = result && GraphNodeGetId(node_b) == b;
        result = result && GraphNodeIndex(node_b) == GraphNodeIdIndex(b);
    
    static bool test_graph_cross_graph_node_handle_deadend(void) {
        WriteFmt("Testing GraphNodeData rejects foreign graph node handles (should abort)\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        GraphNode node    = GraphGetNode(&graph_a, GraphAddNodeR(&graph_a, 10));
    
        (void)GraphNodeData(&graph_b, node);
    
        GraphDeinit(&graph_b);
    
        GraphForeachNode(&graph, node) {
            if (GraphNodeData(&graph, node) == 20) {
                GraphMarkNodeForDeletion(node);
            }
        result = result && (GraphNodeIdIndex(d) == GraphNodeIdIndex(b));
        result = result && (GraphNodeIdGeneration(d) == (GraphNodeIdGeneration(b) + 1));
        result = result && (GraphNodeData(&graph, GraphGetNode(&graph, d)) == 40);
        result = result && !GraphNodeVisited(GraphGetNode(&graph, d));
    
        GraphNodeForeachPredecessor(GraphGetNode(&graph, d), predecessor) {
            predecessor_sum   += GraphNodeData(&graph, predecessor);
            predecessor_count += 1;
        }
Last updated on