Skip to content

GraphGetNode

Description

Get a traversal handle for a live node id.

Parameters

Name Direction Description
g in,out Graph owning the node.
node_id in Live node id to wrap as a GraphNode.

Success

Returns a GraphNode handle that resolves back to the same slot and generation. The graph is not modified. The handle is valid until the slot is committed for deletion.

Failure

Does not return - aborts via LOG_FATAL for an invalid or stale node id (caller bug).

Usage example (Cross-references)

Usage examples (Cross-references)
        ValidateGraph(&graph);
    
        node_b                            = GraphGetNode(&graph, b);
        *GraphNodeDataPtr(&graph, node_b) = 25;
        IntGraph  graph_a = GraphInit(&alloc);
        IntGraph  graph_b = GraphInit(&alloc);
        GraphNode node    = GraphGetNode(&graph_a, GraphAddNodeR(&graph_a, 10));
    
        (void)GraphNodeData(&graph_b, node);
    
        GraphNodeId node_id = GraphAddNodeR(&graph, 11);
        GraphNode   node    = GraphGetNode(&graph, node_id);
    
        bool result = GraphAllocator(&graph)->alignment == 32 && GraphNodeIdIndex(node_id) == 0 &&
    
        GraphNodeId a    = GraphAddNodeR(&graph, 10);
        GraphNode   node = GraphGetNode(&graph, a);
    
        bool result = !GraphNodeVisited(node) && (GraphNodeVisitCount(node) == 0);
        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));
        result = result && (GraphNodeIdGeneration(d) == (GraphNodeIdGeneration(b) + 1));
        result = result && (GraphNodeData(&graph, GraphGetNode(&graph, d)) == 40);
        result = result && !GraphNodeVisited(GraphGetNode(&graph, d));
    
        GraphDeinit(&graph);
    
        GraphNodeId a    = GraphAddNodeR(&graph, 10);
        GraphNode   node = GraphGetNode(&graph, a);
    
        bool result = !GraphNodeMarkedForDeletion(node);
    
        bool result = GraphMarkEdgeForRemoval(&graph, a, b);
        result      = result && GraphMarkNodeForDeletion(GraphGetNode(&graph, b));
        result      = result && GraphEdgeMarkedForRemoval(&graph, a, b);
        result      = result && GraphNodeMarkedForDeletion(GraphGetNode(&graph, b));
        result      = result && GraphMarkNodeForDeletion(GraphGetNode(&graph, b));
        result      = result && GraphEdgeMarkedForRemoval(&graph, a, b);
        result      = result && GraphNodeMarkedForDeletion(GraphGetNode(&graph, b));
        result      = result && (GraphCommitChanges(&graph) == 2);
        result      = result && !GraphContainsNode(&graph, b);
        counts[GraphNodeIdIndex(b)] = 29;
    
        bool result = GraphMarkNodeForDeletion(GraphGetNode(&graph, b));
        result      = result && (GraphCommitChanges(&graph) == 1);
        result      = result && !GraphContainsNode(&graph, b);
    
        GraphNodeId a    = GraphAddNodeR(&graph, 10);
        GraphNode   node = GraphGetNode(&graph, a);
    
        (void)GraphMarkNodeForDeletion(node);
        result = result && GraphAddEdge(&graph, third_id, first_id);
        result = result && GraphAddEdge(&graph, third_id, third_id);
        result = result && (GraphNodeVisit(GraphGetNode(&graph, first_id)) == 1);
        result = result && GraphMarkNodeForDeletion(GraphGetNode(&graph, second_id));
        result = result && GraphMarkEdgeForRemoval(&graph, third_id, third_id);
        result = result && GraphAddEdge(&graph, third_id, third_id);
        result = result && (GraphNodeVisit(GraphGetNode(&graph, first_id)) == 1);
        result = result && GraphMarkNodeForDeletion(GraphGetNode(&graph, second_id));
        result = result && GraphMarkEdgeForRemoval(&graph, third_id, third_id);
    
        node_id     = GraphAddNodeL(&graph, name);
        node        = GraphGetNode(&graph, node_id);
        stored_name = GraphNodeDataPtr(&graph, node);
    
        node_id     = GraphAddNodeR(&graph, StrZ("alpha", &alloc));
        node        = GraphGetNode(&graph, node_id);
        stored_name = GraphNodeDataPtr(&graph, node);
    
        city_reset_visits(graph);
        return city_reachable_from(GraphGetNode(graph, *from_id), *to_id);
    }
        u64 predecessor_count = 0;
    
        GraphNodeForeachPredecessor(GraphGetNode(&graph, d), predecessor) {
            predecessor_sum   += GraphNodeData(&graph, predecessor);
            predecessor_count += 1;
        GraphAddEdge(&graph, a, b);
    
        GraphNodeForeachNeighbor(GraphGetNode(&graph, a), neighbor) {
            (void)neighbor;
            (void)GraphAddEdge(&graph, a, c);
        GraphAddEdge(&graph, b, c);
    
        GraphNodeForeachPredecessor(GraphGetNode(&graph, c), predecessor) {
            (void)predecessor;
            (void)GraphAddEdge(&graph, d, c);
Last updated on