38 lines
2.7 KiB
Markdown
38 lines
2.7 KiB
Markdown
# 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.cmake` declaring `INTERNAL_DEPS Core Math`.
|
|
- New `include/Void/Algorithms/Graph.hpp` defining `Void::Algorithms::{WorkLimits, AlgorithmError, Topology, TraversalResult, ShortestPathResult, IndexedGraphView, HasVersionStamp, AdjacencyView}` and iterative `bfs`, `dfs`, `shortest_path_unweighted`, and `topological_order`.
|
|
- Comprehensive unit and edge-case tests in `tests/standalone/Algorithms/Graph.cpp`.
|
|
- Package consumer `tests/package/AlgorithmsOnly/{CMakeLists.txt,main.cpp}` registered in `tests/package/InstalledComponents.cmake` (`Algorithms Math Core`).
|
|
|
|
## 3. Exact files and interfaces
|
|
- `src/Algorithms/module.cmake`
|
|
- `include/Void/Algorithms/Graph.hpp`
|
|
- `tests/standalone/Algorithms/Graph.cpp`
|
|
- `tests/package/AlgorithmsOnly/CMakeLists.txt`
|
|
- `tests/package/AlgorithmsOnly/main.cpp`
|
|
- `tests/package/InstalledComponents.cmake`
|
|
|
|
## 4. Edge cases
|
|
- Out-of-range source/target vertex IDs or `vertex_count()` exceeding `WorkLimits` rejected 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 (`> 100k` vertices / chains) execute strictly iteratively with no stack overflow.
|
|
- `topological_order` uses Kahn's algorithm and, on cycle detection, runs iterative 3-color DFS to extract a deterministic cycle witness `[u0, ..., uk, u0]`.
|
|
- Periodic `std::stop_token` and `HasVersionStamp::version()` checks abort mid-traversal with `cancelled` / `concurrent_modification`.
|
|
|
|
## 5. Acceptance criteria
|
|
- `Graph*` tests and `VoidInstalledComponentConsumers` (`AlgorithmsOnly`) pass under `-DVOID_WARNINGS_AS_ERRORS=ON` and ASan/UBSan.
|
|
|
|
## 6. Verification commands
|
|
```sh
|
|
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'
|
|
``` |