From 32f051856bd097ec9b1118c792c0f7d8cde09bc7 Mon Sep 17 00:00:00 2001 From: Matthieu Pignolet Date: Thu, 6 Jun 2024 13:53:41 +0400 Subject: [PATCH] prefer current words instead of longer words depending on length --- autofeur_db/src/trie.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/autofeur_db/src/trie.rs b/autofeur_db/src/trie.rs index 047c7ec..5ffd097 100644 --- a/autofeur_db/src/trie.rs +++ b/autofeur_db/src/trie.rs @@ -105,6 +105,7 @@ impl<'a> Trie<'a> { builder = String::new(); let mut rng = thread_rng(); + let mut length = 0; while current_node.child_nodes.len() != 0 { // We need to choose a random child based on weights let weighted = WeightedIndex::new( @@ -128,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]) + let weighted = WeightedIndex::new(&[1, current_node.child_count / length]) .expect("distribution seems impossible"); if weighted.sample(&mut rng) == 0 { @@ -137,6 +138,7 @@ impl<'a> Trie<'a> { break; } } + length += 1; } // If we only added -- 2.39.5