From 25c1742d43e6e710ffb520525df6c31f684b0174 Mon Sep 17 00:00:00 2001 From: Matthieu Pignolet Date: Thu, 6 Jun 2024 13:55:33 +0400 Subject: [PATCH] avoid divide par zero --- autofeur_db/src/trie.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { -- 2.39.5