]> git.puffer.fish Git - matthieu/gru.git/commitdiff
avoid divide par zero
authorMatthieu Pignolet <matthieu@matthieu-dev.xyz>
Thu, 6 Jun 2024 09:55:33 +0000 (13:55 +0400)
committerMatthieu Pignolet <matthieu@matthieu-dev.xyz>
Thu, 6 Jun 2024 09:55:33 +0000 (13:55 +0400)
autofeur_db/src/trie.rs

index 5ffd097becb30ee930f4c70e67363466fb848e24..b202a97a4a24b1e8c0196b74803bc17dd94a36ef 100644 (file)
@@ -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 {