From: Matthieu Pignolet Date: Thu, 6 Jun 2024 09:55:33 +0000 (+0400) Subject: avoid divide par zero X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=25c1742d43e6e710ffb520525df6c31f684b0174;p=matthieu%2Fgru.git avoid divide par zero --- diff --git a/autofeur_db/src/trie.rs b/autofeur_db/src/trie.rs index 5ffd097..b202a97 100644 --- a/autofeur_db/src/trie.rs +++ b/autofeur_db/src/trie.rs @@ -129,7 +129,7 @@ impl<'a> Trie<'a> { // If this node is final and has childrens if current_node.is_final && current_node.child_count > 0 { // choose from current node or continue with childrens - let weighted = WeightedIndex::new(&[1, current_node.child_count / length]) + let weighted = WeightedIndex::new(&[1, current_node.child_count / (length + 1)]) .expect("distribution seems impossible"); if weighted.sample(&mut rng) == 0 {