ValidateGraph
Description
Validate whether a given Graph object is valid. Aborts if provided graph is uninitialized or corrupted.
Parameters
| Name | Direction | Description |
|---|---|---|
g |
in | Pointer to Graph object to validate. |
Success
Continue execution, meaning given graph is most probably valid.
Failure
abort
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Memory.h:48:
/// TAGS: Graph, Memory, Reserve
///
#define GraphReserve(g, n) (ValidateGraph(g), reserve_graph(GENERIC_GRAPH(g), sizeof(GRAPH_NODE_TYPE(g)), (n)))
///
- In
Foreach.h:36:
#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) \- In
Insert.h:40:
///
#define GraphAddNodeL(g, lval) \
(ValidateGraph(g), \
CHECK_TYPE_EQUIVALENCE(TYPE_OF(lval), GRAPH_NODE_TYPE(g)), \
graph_push_node_owned(GENERIC_GRAPH(g), &(lval), sizeof(GRAPH_NODE_TYPE(g))))- In
Insert.h:63:
///
#define GraphAddNodeR(g, rval) \
(ValidateGraph(g), \
CHECK_TYPE_CONVERTIBLE(GRAPH_NODE_TYPE(g), rval), \
graph_push_node(GENERIC_GRAPH(g), &LVAL_AS(GRAPH_NODE_TYPE(g), rval), sizeof(GRAPH_NODE_TYPE(g))))- In
Insert.h:104:
/// TAGS: Graph, AddEdge, Directed
///
#define GraphAddEdge(g, from, to) (ValidateGraph(g), graph_add_edge(GENERIC_GRAPH(g), (from), (to)))
///
- In
Graph.c:106:
}
ValidateGraph(graph);
graph_validate_node_id(graph, node._id_);
return node;- In
Graph.c:458:
void deinit_graph(GenericGraph *graph, size item_size) {
ValidateGraph(graph);
clear_graph(graph, item_size);- In
Graph.c:471:
u64 slot_index;
ValidateGraph(graph);
for (slot_index = 0; slot_index < VecLen(&graph->slots); slot_index++) {- In
Graph.c:506:
(void)item_size;
ValidateGraph(graph);
old_capacity = VecCapacity(&graph->slots);- In
Graph.c:532:
}
ValidateGraph(graph);
if (VecLen(&graph->free_indices)) {- In
Graph.c:633:
}
ValidateGraph(graph);
index = GraphNodeIdIndex(node_id);- In
Graph.c:649:
GraphNode node;
ValidateGraph(graph);
graph_validate_node_id(graph, node_id);- In
Graph.c:690:
GraphNeighbors *neighbors;
ValidateGraph(graph);
graph_validate_node_id(graph, from);
neighbors = graph_out_neighbors_ptr(graph, from);- In
Graph.c:704:
GraphNeighbors *neighbors;
ValidateGraph(graph);
graph_validate_node_id(graph, to);
neighbors = graph_in_neighbors_ptr(graph, to);- In
Graph.c:718:
GraphNeighbors *neighbors;
ValidateGraph(graph);
graph_validate_node_id(graph, from);
graph_validate_node_id(graph, to);- In
Graph.c:730:
GraphNeighbors *in_neighbors;
ValidateGraph(graph);
graph_validate_node_id(graph, from);
graph_validate_node_id(graph, to);- In
Graph.c:853:
GraphPendingEdgeRemoval pending;
ValidateGraph(graph);
graph_validate_node_id(graph, from);
graph_validate_node_id(graph, to);- In
Graph.c:877:
bool graph_edge_marked_for_removal(GenericGraph *graph, GraphNodeId from, GraphNodeId to) {
ValidateGraph(graph);
graph_validate_node_id(graph, from);
graph_validate_node_id(graph, to);- In
Graph.c:887:
size idx;
ValidateGraph(graph);
graph_validate_node_id(graph, from);
graph_validate_node_id(graph, to);- In
Graph.c:906:
u64 explicit_edge_removal_count;
ValidateGraph(graph);
if (!graph->pending_delete_count && !VecLen(&graph->pending_edge_removals)) {- In
Graph.c:956:
GenericGraphNodeIter iter;
ValidateGraph(graph);
iter.graph = graph;- In
Graph.c:973:
}
ValidateGraph(iter->graph);
if (iter->expected_mutation_epoch != iter->graph->mutation_epoch) {
LOG_FATAL("graph structure changed during node iteration");- In
Graph.c:1018:
}
ValidateGraph(iter->graph);
if (iter->expected_mutation_epoch != iter->graph->mutation_epoch) {
LOG_FATAL("graph structure changed during neighbor iteration");- In
Graph.c:1065:
}
ValidateGraph(iter->graph);
if (iter->expected_mutation_epoch != iter->graph->mutation_epoch) {
LOG_FATAL("graph structure changed during predecessor iteration");- In
Ops.c:689:
// Clear the memoized validated bit on a consistent graph so commit's entry
// ValidateGraph skips the deep accounting scan.
ValidateGraph(&graph);
// Hide the last slot (c, occupied + unmarked) at index == new length.
- In
Ops.c:743:
// Clear the memoized validated bit on a consistent graph.
ValidateGraph(&graph);
// Hide c (occupied + marked) at index == new length.
- In
Init.c:24:
GraphReserve(&graph, 8);
ValidateGraph(&graph);
bool result = VecCapacity(&graph.slots) >= 8;- In
Insert.c:233:
bool result = GraphAddEdge(&graph, a, c);
ValidateGraph(&graph);
result = result && GraphContainsNode(&graph, a) && GraphContainsNode(&graph, c);- In
Type.c:23:
IntGraph graph = GraphInit(&alloc);
ValidateGraph(&graph);
// intentional bypass: the inner `slots` / `free_indices` /
- In
Type.c:71:
// validating this valid graph does NOT abort. NORMAL test.
static bool test_graph_validate_passes_with_marked_node(void) {
WriteFmt("Testing deep ValidateGraph accepts a valid graph that has a marked node\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Type.c:90:
(void)d;
ValidateGraph(&graph);
bool result = (graph.pending_delete_count == 1);- In
Type.c:110:
// > 1), re-arm the deep validator, and assert ValidateGraph aborts. DEADEND.
static bool test_graph_non_pow2_alignment_rejected_deadend(void) {
WriteFmt("Testing ValidateGraph rejects a non-power-of-two allocator alignment (should abort)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Type.c:127:
GraphAllocator(&graph)->alignment = 3;
ValidateGraph(&graph);
GraphDeinit(&graph);- In
Type.c:146:
// real code while removing the mask for the mutant). DEADEND.
static bool test_graph_validate_catches_corrupt_slots_vec_deadend(void) {
WriteFmt("Testing ValidateGraph catches a corrupted slots vector (should abort)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Type.c:161:
GENERIC_GRAPH(&graph)->slots.__magic = 0;
ValidateGraph(&graph);
return false;- In
Type.c:172:
// does not mask the removed in-validator check (see slots-vec test). DEADEND.
static bool test_graph_validate_catches_corrupt_free_indices_vec_deadend(void) {
WriteFmt("Testing ValidateGraph catches a corrupted free_indices vector (should abort)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Type.c:186:
GENERIC_GRAPH(&graph)->free_indices.__magic = 0;
ValidateGraph(&graph);
return false;- In
Type.c:197:
// check (see slots-vec test). DEADEND.
static bool test_graph_validate_catches_corrupt_pending_edges_vec_deadend(void) {
WriteFmt("Testing ValidateGraph catches a corrupted pending_edge_removals vector (should abort)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Type.c:212:
GENERIC_GRAPH(&graph)->pending_edge_removals.__magic = 0;
ValidateGraph(&graph);
return false;- In
Type.c:253:
MAGIC_MARK_DIRTY(GENERIC_GRAPH(&graph));
ValidateGraph(&graph);
GraphDeinit(&graph);- In
Type.c:285:
MAGIC_MARK_DIRTY(GENERIC_GRAPH(&graph));
ValidateGraph(&graph);
GraphDeinit(&graph);- In
Type.c:319:
MAGIC_MARK_DIRTY(GENERIC_GRAPH(&graph));
ValidateGraph(&graph);
GraphDeinit(&graph);- In
Type.c:351:
MAGIC_MARK_DIRTY(GENERIC_GRAPH(&graph));
ValidateGraph(&graph);
GraphDeinit(&graph);- In
Type.c:384:
MAGIC_MARK_DIRTY(g);
ValidateGraph(&graph);
GraphDeinit(&graph);- In
Type.c:414:
MAGIC_MARK_DIRTY(g);
ValidateGraph(&graph);
GraphDeinit(&graph);- In
Type.c:446:
MAGIC_MARK_DIRTY(g);
ValidateGraph(&graph);
GraphDeinit(&graph);- In
Type.c:479:
MAGIC_MARK_DIRTY(g);
ValidateGraph(&graph);
GraphDeinit(&graph);- In
Type.c:512:
MAGIC_MARK_DIRTY(g);
ValidateGraph(&graph);
GraphDeinit(&graph);- In
Type.c:525:
// is not an out-neighbor and force re-validation; real code aborts.
static bool test_graph_validate_rejects_missing_pending_edge_deadend(void) {
WriteFmt("Testing ValidateGraph rejects pending removal of a missing edge (should abort)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Type.c:549:
MAGIC_MARK_DIRTY(GENERIC_GRAPH(&graph));
ValidateGraph(&graph);
GraphDeinit(&graph);- In
Foreach.c:586:
// memoized validated bit; subsequent ValidateGraph calls skip the deep
// accounting scan that would otherwise reject the length tweak below.
ValidateGraph(&graph);
// intentional bypass: no public setter shrinks the slot array. Hiding the
- In
Access.c:32:
GraphAddEdge(&graph, c, a);
ValidateGraph(&graph);
node_b = GraphGetNode(&graph, b);
Last updated on