Skip to content

GraphClear

Description

Remove all nodes and edges from the graph but keep allocated storage. Node payloads are deinitialized via the configured copy_deinit handler when present.

Parameters

Name Direction Description
g in,out Graph handle.

Success

Returns to the caller. live_count, edge_count, and the pending-delete count are now 0. Every node slot is marked free; every adjacency list is reset. When copy_deinit is configured it has been invoked on each previously-stored payload. The slot array and free-index array keep their allocated capacity.

Failure

Function cannot fail.

Usage example (Cross-references)

Usage examples (Cross-references)
    // succeeds.
    static bool test_graph_clear_resets_free_slot_visit_count(void) {
        WriteFmt("Testing GraphClear resets free-slot visit_count\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        (void)a;
    
        GraphClear(&graph);
    
        // A valid op after clear runs ValidateGraph; on the mutant the pre-free
    // deletion).
    static bool test_graph_clear_empties_free_indices(void) {
        WriteFmt("Testing GraphClear empties free_indices before repopulating\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        result      = result && (GraphCommitChanges(&graph) == 1);
    
        GraphClear(&graph);
    
        // Valid op runs ValidateGraph; on the mutant free_indices is over-long and
    
    static bool test_graph_reserve_clear(void) {
        WriteFmt("Testing GraphReserve and GraphClear\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        result = result && GraphMarkEdgeForRemoval(&graph, third_id, third_id);
    
        GraphClear(&graph);
    
        result = result && GraphNodeCount(&graph) == 0 && GraphEdgeCount(&graph) == 0 && GraphEmpty(&graph);
    // code aborts on the next iteration step.
    static bool test_graph_clear_during_traversal_aborts_deadend(void) {
        WriteFmt("Testing GraphClear during traversal invalidates iterator (should abort)\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
                // Structural mutation mid-iteration: the next iterator step must
                // detect the epoch change and abort.
                GraphClear(&graph);
            }
            visited += 1;
Last updated on