tawasuyu

tawasuyu/arje

> Standalone repository, extracted from the tawasuyu monorepo at tag v0.3.3. The domain's code lives under 03ukupacha/arje/; the foundational crates it shares with the rest of the suite come in as git dependencies pinned to that tag. cargo…

Rust 38TOML 12Markdown 1395 Definiciones

⎇ d6b8f18b43c9bd9bf7268e48b61392a2d62bb229 crates/ente-zero/src/graph/topology.rs Rust · 35 líneas · 1.3 KB Historia Quién tocó qué crudo

Pausa: 11 crates del fractal Ente #0 con cerebro completo d6b8f18b4 · Sergio ·

1//! Topología del fractal: índice de hijos por lineage y orden topológico
2//! para shutdown.
3
4use super::EnteGraph;
5use std::collections::BTreeSet;
6use ulid::Ulid;
7
8impl EnteGraph {
9    /// DFS post-order desde la Semilla. Hojas primero, raíz al final.
10    /// Garantiza que SIGTERM va a un padre sólo cuando sus hijos ya recibieron
11    /// la señal (evita orfandad transitoria que confunda Restart supervisors).
12    pub(in crate::graph) fn topo_order(&self) -> Vec<Ulid> {
13        let mut visited = BTreeSet::new();
14        let mut order = Vec::new();
15        self.dfs_post(self.seed.id, &mut visited, &mut order);
16        // Entes encarnados sin lineage hacia el seed (no debería pasar pero
17        // protege contra grafos huérfanos): añadirlos al final.
18        for id in self.incarnated.keys() {
19            if !visited.contains(id) {
20                self.dfs_post(*id, &mut visited, &mut order);
21            }
22        }
23        order
24    }
25
26    fn dfs_post(&self, node: Ulid, visited: &mut BTreeSet<Ulid>, order: &mut Vec<Ulid>) {
27        if !visited.insert(node) { return; }
28        if let Some(children) = self.children.get(&node) {
29            for c in children.clone() {
30                self.dfs_post(c, visited, order);
31            }
32        }
33        order.push(node);
34    }
35}