Deterministic, memory-safe Directed Acyclic Graph (DAG) for C++ runtime module lifecycle management.
LifeTree is a lightweight, zero-dependency C++ library for modeling dependency relationships between runtime-owned objects and enforcing safe deletion semantics.
- Add and remove modules securely.
- Add logically directed dependency edges (
consumer -> provider). - Strict rejection of self-dependencies.
- Strict cycle-rejection on insertion (forces DAG compliance).
- Pre-compute whether a module can be deleted safely without mutating state (
analyzeDelete). - Report direct downstream blockers preventing deletion.
- Analyze transitive blast-radius prior to destructive actions.
- Compute a deterministic dependents-first cascade order (Topological Sorting).
- Explicit safety separation:
unregisterModule(name)followed bydestroyModule(id).
deleteModule(name)remains non-mutating and atomically fails if blocked by active dependents.- When permitted,
deleteModule(name)performs unregister + destroy sequentially. unregisterModule(name)makes a module name-invisible but safely buffers the node via stableModuleId.destroyModule(id)strictly enforces that nodes are unregistered with zero active dependents before memory is purged.garbageCollect()safely detects and purges isolated, deferred nodes.
- Resolve names to stable integer IDs via
lookupModuleId. - Inspect internal node attributes by ID with
getModuleById. - Check live namespace availability with
isModuleRegistered. - Track active memory footprint with
registeredModuleCount.
- Granular dependency and dependent edge queries (
getDependencies,getDependents). - Transitive traversal using Depth-First Search (DFS).
- Strict topological ordering guaranteed by
std::setstructures. - Roots, leaves, isolated-node, and total edge-count helper endpoints.
- Native Graphviz DOT export utilizing resilient
ModuleId-keyed edges. - Deterministic JSON export for programmatic CI/CD integration.
- Invariant validation engine for internal stress testing.
#include "lifetree.h"
#include <iostream>
int main() {
lifetree::LifeTree tree;
std::string error;
tree.addModule("core.runtime", &error);
tree.addModule("core.auth", &error);
tree.addModule("api.gateway", &error);
tree.addDependency("core.auth", "core.runtime", &error);
tree.addDependency("api.gateway", "core.auth", &error);
lifetree::DeleteAnalysis analysis;
tree.analyzeDelete("core.runtime", &analysis, &error);
std::cout << "Can delete runtime safely? "
<< (analysis.CanSafelyDelete ? "Yes" : "No - Blocked by consumers") << "\n";
std::cout << tree.toDot();
return 0;
}lifetree/
|-- CMakeLists.txt
|-- README.md
|-- TEST_RESULTS.md
|-- BENCHMARK_RESULTS.md
|-- benchmarks/
| |-- lifetree_bench.cpp
|-- include/
| |-- lifetree.h
|-- src/
| |-- lifetree.cpp
|-- tests/
| |-- lifetree_tests.cpp
| |-- lifetree_stress_tests.cpp
cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failure
./build/lifetree_benchmkdir -p build
g++ -std=c++17 -Wall -Wextra -Wpedantic -Iinclude src/lifetree.cpp tests/lifetree_tests.cpp -o build/lifetree_tests
./build/lifetree_testsExecute the optimized benchmark configuration:
g++ -O2 -std=c++17 -Wall -Wextra -Wpedantic -Iinclude src/lifetree.cpp benchmarks/lifetree_bench.cpp -o build/lifetree_bench
./build/lifetree_bench(Verified baseline metrics are available in BENCHMARK_RESULTS.md.)
The test suite rigorously verifies 17 distinct operational domains:
- Base module addition, duplicate rejection, and empty-string handling.
- Linear dependency structural deletion constraints.
- Complex diamond dependency DAG traversal.
- Mathematical cycle insertion detection and rejection.
- Absolute topological ordering consistency.
- Missing-node and invalid ID error diagnostics.
- Dependency edge removal and memory decrements.
- Transitive search accuracy (DFS).
- Predictive
analyzeDelete()non-mutation correctness. - System-level
forceDeleteWithCascadetracking. - Statistical extraction APIs.
- Deep invariant validation constraints.
unregisteranddestroydeferred lifecycle boundaries.- Safe-mapping logic isolating
ModuleIds against "Ghost Edge" string shadowing. - Garbage Collector sweeps for deferred memory isolation logic.
- Unload mutation lock contracts during blocked unregister attempts.
- Heavy randomized mutation fuzzer tracking with fixed RNG seeds.
(Refer to TEST_RESULTS.md for output signatures).