From: Matthieu Pignolet Date: Thu, 6 Jun 2024 10:15:04 +0000 (+0400) Subject: make weighted probabilities depending on node's children children count X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=16e9f11a3dd313dbc3f10f66a73fd4d36cd89e0d;p=matthieu%2Fgru.git make weighted probabilities depending on node's children children count --- diff --git a/autofeur_db/src/trie.rs b/autofeur_db/src/trie.rs index 6d0867a..a14c56e 100644 --- a/autofeur_db/src/trie.rs +++ b/autofeur_db/src/trie.rs @@ -109,11 +109,11 @@ impl<'a> Trie<'a> { while current_node.child_nodes.len() != 0 { // We need to choose a random child based on weights let weighted = WeightedIndex::new(current_node.child_nodes.iter().map(|(_, node)| { - node.child_count / node + node.child_count / (node .child_nodes .iter() .map(|(_, b)| b.child_count) - .sum::() + .sum::() + 1) })) .expect("distribution creation should be valid");