summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Pignolet <matthieu@matthieu-dev.xyz>2024-06-06 13:53:41 +0400
committerMatthieu Pignolet <matthieu@matthieu-dev.xyz>2024-06-06 13:53:41 +0400
commit32f051856bd097ec9b1118c792c0f7d8cde09bc7 (patch)
treef4529b143f691826e4db90a51ef136617c9d73ea
parent76939f7e11dd032f32b47fe57d8075b87036880d (diff)
prefer current words instead of longer words depending on length
-rw-r--r--autofeur_db/src/trie.rs4
1 files changed, 3 insertions, 1 deletions
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