Skip to content
GenericGraphSlot

GenericGraphSlot

Description

Type-erased slot layout used by the runtime helpers in Source/Misra/Std/Container/Graph.c. GraphSlot(T) below is the typed variant; both have identical layout (the data field is a pointer, and void * / T * share representation).

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    static bool graph_slot_is_occupied(const GenericGraphSlot *slot) {
        return (slot->flags & GRAPH_SLOT_OCCUPIED) != 0;
    }
    }
    
    static bool graph_slot_is_marked(const GenericGraphSlot *slot) {
        return (slot->flags & GRAPH_SLOT_MARKED) != 0;
    }
    }
    
    static GenericGraphSlot *graph_slot_ptr_raw(GenericGraph *graph, u32 index) {
        return VecPtrAt(&graph->slots, index);
    }
    }
    
    static const GenericGraphSlot *graph_slot_ptr_const_raw(const GenericGraph *graph, u32 index) {
        return VecPtrAt((GraphSlots *)&graph->slots, index);
    }
        u32                     index;
        u32                     generation;
        const GenericGraphSlot *slot;
    
        index      = GraphNodeIdIndex(node_id);
    }
    
    static GenericGraphSlot *graph_require_live_slot(GenericGraph *graph, GraphNodeId node_id) {
        graph_validate_node_id(graph, node_id);
        return graph_slot_ptr_raw(graph, GraphNodeIdIndex(node_id));
    }
    
    static const GenericGraphSlot *graph_require_live_slot_const(const GenericGraph *graph, GraphNodeId node_id) {
        graph_validate_node_id(graph, node_id);
        return graph_slot_ptr_const_raw(graph, GraphNodeIdIndex(node_id));
    }
    
    static void graph_ensure_slot_generation_available(GenericGraphSlot *slot) {
        if (slot->generation == UINT32_MAX) {
            LOG_FATAL("graph slot generation exhausted");
    }
    
    static void graph_release_slot(GenericGraph *graph, GenericGraphSlot *slot, size item_size) {
        if (!graph_slot_is_occupied(slot)) {
            return;
        while (idx < neighbors->length) {
            GraphNodeId             neighbor_id = VecAt(neighbors, idx);
            const GenericGraphSlot *slot;
    
            graph_validate_node_index_raw(graph, GraphNodeIdIndex(neighbor_id));
    
        for (slot_index = 0; slot_index < graph->slots.length; slot_index++) {
            const GenericGraphSlot *slot    = VecPtrAt((GraphSlots *)&graph->slots, slot_index);
            GraphNodeId             self_id = graph_make_node_id((u32)slot_index, slot->generation);
            u64                     neighbor_i;
                for (neighbor_i = 0; neighbor_i < slot->out_neighbors.length; neighbor_i++) {
                    GraphNodeId             neighbor_id = VecAt(&slot->out_neighbors, neighbor_i);
                    const GenericGraphSlot *target_slot;
    
                    graph_validate_node_id(graph, neighbor_id);
                for (neighbor_i = 0; neighbor_i < slot->in_neighbors.length; neighbor_i++) {
                    GraphNodeId             predecessor_id = VecAt(&slot->in_neighbors, neighbor_i);
                    const GenericGraphSlot *source_slot;
    
                    graph_validate_node_id(graph, predecessor_id);
    
        clear_graph(graph, item_size);
        deinit_vec(GENERIC_VEC(&graph->slots), sizeof(GenericGraphSlot));
        deinit_vec(GENERIC_VEC(&graph->free_indices), sizeof(u32));
        deinit_vec(GENERIC_VEC(&graph->pending_edge_removals), sizeof(GraphPendingEdgeRemoval));
    
        for (slot_index = 0; slot_index < graph->slots.length; slot_index++) {
            GenericGraphSlot *slot = VecPtrAt(&graph->slots, slot_index);
            if (graph_slot_is_occupied(slot)) {
                graph_release_slot(graph, slot, item_size);
    
        success = reserve_vec(GENERIC_VEC(&graph->free_indices), sizeof(u32), n) &&
                  reserve_vec(GENERIC_VEC(&graph->slots), sizeof(GenericGraphSlot), n);
        if (!success) {
            return false;
    GraphNodeId graph_push_node(GenericGraph *graph, const void *item_data, size item_size) {
        GraphNodeId       node_id;
        GenericGraphSlot  slot;
        GenericGraphSlot *slot_ptr;
        u32               slot_index;
        GraphNodeId       node_id;
        GenericGraphSlot  slot;
        GenericGraphSlot *slot_ptr;
        u32               slot_index;
                GENERIC_VEC(&graph->slots),
                (char *)&slot,
                sizeof(GenericGraphSlot),
                graph->slots.length,
                1
        u32               index;
        u32               generation;
        GenericGraphSlot *slot;
    
        if (!graph) {
    u64 graph_node_visit(GraphNode node) {
        GenericGraph     *graph;
        GenericGraphSlot *slot;
    
        node  = graph_validate_node_handle(node);
    void graph_node_unvisit(GraphNode node) {
        GenericGraph     *graph;
        GenericGraphSlot *slot;
    
        node  = graph_validate_node_handle(node);
    u64 graph_node_visit_count(GraphNode node) {
        GenericGraph           *graph;
        const GenericGraphSlot *slot;
    
        node  = graph_validate_node_handle(node);
    bool graph_mark_node_for_deletion(GraphNode node) {
        GenericGraph     *graph;
        GenericGraphSlot *slot;
    
        node  = graph_validate_node_handle(node);
    bool graph_node_marked_for_deletion(GraphNode node) {
        GenericGraph           *graph;
        const GenericGraphSlot *slot;
    
        node  = graph_validate_node_handle(node);
    bool graph_unmark_node_for_deletion(GraphNode node) {
        GenericGraph     *graph;
        GenericGraphSlot *slot;
    
        node  = graph_validate_node_handle(node);
    
        for (slot_index = 0; slot_index < graph->slots.length; slot_index++) {
            GenericGraphSlot *slot = VecPtrAt(&graph->slots, slot_index);
            if (graph_slot_is_occupied(slot) && graph_slot_is_marked(slot)) {
                GraphNodeId marked_id = graph_make_node_id((u32)slot_index, slot->generation);
    
        for (slot_index = 0; slot_index < graph->slots.length; slot_index++) {
            GenericGraphSlot *slot = VecPtrAt(&graph->slots, slot_index);
            if (graph_slot_is_occupied(slot) && !graph_slot_is_marked(slot)) {
                GraphNodeId live_id = graph_make_node_id((u32)slot_index, slot->generation);
    
        for (slot_index = 0; slot_index < graph->slots.length; slot_index++) {
            GenericGraphSlot *slot = VecPtrAt(&graph->slots, slot_index);
            if (graph_slot_is_occupied(slot) && graph_slot_is_marked(slot)) {
                if (slot->out_neighbors.length || slot->in_neighbors.length) {
        while (iter->slot_index < iter->graph->slots.length) {
            u32               index  = (u32)iter->slot_index;
            GenericGraphSlot *slot   = VecPtrAt(&iter->graph->slots, iter->slot_index);
            iter->slot_index        += 1;
            // `graph.slots` is the typed `Vec(GraphSlot(int))`, so iterate via
            // the runtime-shared layout to avoid an anonymous-struct annotation.
            GenericGraphSlot *slot = (GenericGraphSlot *)VecPtrAt(&GENERIC_GRAPH(&graph)->slots, slot_index);
            result                 = result && (slot->data == NULL);
            result                 = result && (slot->visit_count == 0);
        u32            generation;
        u32            flags;
    } GenericGraphSlot;
    
    typedef Vec(GenericGraphSlot) GraphSlots;
    } GenericGraphSlot;
    
    typedef Vec(GenericGraphSlot) GraphSlots;
    typedef Vec(u32) GraphFreeIndices;
Last updated on