2.7 KiB
2.7 KiB
Algorithms Indexed Graph Views, Work Budgets, and Iterative Traversals/Topology
Task ID: S-ALGORITHMS-02 Phase: P1 Status: APPROVED Contracts: C-01, C-05, C-07
1. Context and baseline
VoidLibrary currently has no Algorithms module (src/Algorithms/module.cmake, include/Void/Algorithms/). Graph algorithms are needed as a standalone header-only module with strict dependency discipline (INTERNAL_DEPS Core Math), zero unbounded recursion, pre-checked scratch memory budgets, overflow-safe sizing via Void::Numeric, and safe cancellation / concurrent graph mutation detection.
2. Deliverables
src/Algorithms/module.cmakedeclaringINTERNAL_DEPS Core Math.- New
include/Void/Algorithms/Graph.hppdefiningVoid::Algorithms::{WorkLimits, AlgorithmError, Topology, TraversalResult, ShortestPathResult, IndexedGraphView, HasVersionStamp, AdjacencyView}and iterativebfs,dfs,shortest_path_unweighted, andtopological_order. - Comprehensive unit and edge-case tests in
tests/standalone/Algorithms/Graph.cpp. - Package consumer
tests/package/AlgorithmsOnly/{CMakeLists.txt,main.cpp}registered intests/package/InstalledComponents.cmake(Algorithms Math Core).
3. Exact files and interfaces
src/Algorithms/module.cmakeinclude/Void/Algorithms/Graph.hpptests/standalone/Algorithms/Graph.cpptests/package/AlgorithmsOnly/CMakeLists.txttests/package/AlgorithmsOnly/main.cpptests/package/InstalledComponents.cmake
4. Edge cases
- Out-of-range source/target vertex IDs or
vertex_count()exceedingWorkLimitsrejected before scratch allocations. - Overflowing edge/vertex scratch budget calculations rejected using
Void::Numeric::checked_mul/checked_add. - Out-of-range neighbor IDs in adjacency lists diagnosed cleanly without out-of-bounds vector access.
- Deep graphs (
> 100kvertices / chains) execute strictly iteratively with no stack overflow. topological_orderuses Kahn's algorithm and, on cycle detection, runs iterative 3-color DFS to extract a deterministic cycle witness[u0, ..., uk, u0].- Periodic
std::stop_tokenandHasVersionStamp::version()checks abort mid-traversal withcancelled/concurrent_modification.
5. Acceptance criteria
Graph*tests andVoidInstalledComponentConsumers(AlgorithmsOnly) pass under-DVOID_WARNINGS_AS_ERRORS=ONand ASan/UBSan.
6. Verification commands
dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-w4a-alg -G Ninja -DVOID_ENABLED_MODULES="Algorithms;Testing" -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-w4a-alg && /tmp/void-w4a-alg/tests/VoidTests --filter "Graph*" && ctest --test-dir /tmp/void-w4a-alg --output-on-failure --timeout 60'