summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Pignolet <matthieu@matthieu-dev.xyz>2024-06-06 14:17:27 +0400
committerMatthieu Pignolet <matthieu@matthieu-dev.xyz>2024-06-06 14:17:27 +0400
commit7698cd57a9db15aaf5d2f13affb001b4832033a4 (patch)
treeb4c3c52f696a652df6af8ecdbd342ae810db6434
parent16e9f11a3dd313dbc3f10f66a73fd4d36cd89e0d (diff)
make weighted probabilities depending on node's children children count
-rw-r--r--autofeur_db/src/trie.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/autofeur_db/src/trie.rs b/autofeur_db/src/trie.rs
index a14c56e..1788d52 100644
--- a/autofeur_db/src/trie.rs
+++ b/autofeur_db/src/trie.rs
@@ -109,11 +109,14 @@ impl<'a> Trie<'a> {
while current_node.child_nodes.len() != 0 {
// We need to choose a random child based on weights
let weighted = WeightedIndex::new(current_node.child_nodes.iter().map(|(_, node)| {
- node.child_count / (node
- .child_nodes
- .iter()
- .map(|(_, b)| b.child_count)
- .sum::<u64>() + 1)
+ (node.child_count
+ / (node
+ .child_nodes
+ .iter()
+ .map(|(_, b)| b.child_count)
+ .sum::<u64>()
+ + 1)
+ + 1)
}))
.expect("distribution creation should be valid");