Skip to content
GraphNodeCount

GraphNodeCount

Description

Number of live nodes currently stored in graph. Includes nodes marked for deletion but not yet committed.

Parameters

Name Direction Description
g in Graph to query.

Success

Returns the live-node count as a u64. The graph is not modified.

Failure

Function cannot fail.

Usage example (Cross-references)

Usage examples (Cross-references)
        *GraphNodeDataPtr(&graph, node_b) = 25;
    
        bool result = GraphNodeCount(&graph) == 3 && GraphEdgeCount(&graph) == 3 && !GraphEmpty(&graph);
        result = result && GraphContainsNode(&graph, a) && GraphContainsNode(&graph, b) && GraphContainsNode(&graph, c);
        result = result && GraphNodeAt(&graph, b) == 25;
        // are read directly here to verify the default-constructed graph has
        // every internal cursor / table empty.
        bool result = GraphNodeCount(&graph) == 0 && GraphEdgeCount(&graph) == 0 && GraphEmpty(&graph) &&
                      VecBegin(&graph.slots) == NULL && VecBegin(&graph.free_indices) == NULL &&
                      VecBegin(&graph.pending_edge_removals) == NULL && GraphCopyInit(&graph) == NULL &&
    
        result = result && (removed == 1);
        result = result && (GraphNodeCount(&graph) == 2);
        result = result && (GraphEdgeCount(&graph) == 1);
        result = result && !GraphContainsNode(&graph, b);
        result      = result && (GraphCommitChanges(&graph) == 0);
        result      = result && GraphContainsNode(&graph, a);
        result      = result && (GraphNodeCount(&graph) == 1);
    
        GraphDeinit(&graph);
        result      = result && (GraphCommitChanges(&graph) == 2);
        result      = result && !GraphContainsNode(&graph, b);
        result      = result && (GraphNodeCount(&graph) == 3);
        result      = result && (GraphEdgeCount(&graph) == 0);
        result      = result && (GraphOutDegree(&graph, a) == 0);
        GraphClear(&graph);
    
        result = result && GraphNodeCount(&graph) == 0 && GraphEdgeCount(&graph) == 0 && GraphEmpty(&graph);
        result = result && !GraphContainsNode(&graph, first_id) && !GraphContainsNode(&graph, second_id);
        result = result && !GraphContainsNode(&graph, third_id);
        stored_name = GraphNodeDataPtr(&graph, node);
    
        bool result = GraphNodeIdIndex(node_id) == 0 && StrBegin(&name) != NULL && GraphNodeCount(&graph) == 1 &&
                      ZstrCompare(StrBegin(stored_name), "alpha") == 0 && StrBegin(stored_name) != StrBegin(&name);
        stored_name = GraphNodeDataPtr(&graph, node);
    
        bool result = GraphNodeIdIndex(node_id) == 0 && GraphNodeCount(&graph) == 1 && StrBegin(stored_name) != NULL &&
                      ZstrCompare(StrBegin(stored_name), "alpha") == 0;
    /// TAGS: Graph, Empty, Query
    ///
    #define GraphEmpty(g) (GraphNodeCount(g) == 0)
    
    ///
    #define GraphForeachNode(g, node)                                                                                      \
        for (TYPE_OF(g) UNPL(pg) = (g); UNPL(pg); UNPL(pg) = NULL)                                                         \
            if ((ValidateGraph(UNPL(pg)), 1) && GraphNodeCount(UNPL(pg)) > 0)                                              \
                for (GenericGraphNodeIter UNPL(iter) = graph_node_iter_begin(GENERIC_GRAPH(UNPL(pg))); UNPL(iter).graph;  \
                     UNPL(iter).graph = NULL)                                                                              \
Last updated on