summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Pignolet <matthieu@matthieu-dev.xyz>2024-06-06 14:13:41 +0400
committerMatthieu Pignolet <matthieu@matthieu-dev.xyz>2024-06-06 14:13:41 +0400
commite3f5437ed889dd7b736a891144b8123d2b92a81b (patch)
treeb72e069f78f17cc901649ae7a3e2dc35381ebb80
parentd46c5d9d7cd4398abe22d45fc2a47583658514ca (diff)
make weighted probabilities depending on node's children children count
-rw-r--r--autofeur_db/src/trie.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/autofeur_db/src/trie.rs b/autofeur_db/src/trie.rs
index bbc2a93..6d0867a 100644
--- a/autofeur_db/src/trie.rs
+++ b/autofeur_db/src/trie.rs
@@ -108,12 +108,13 @@ impl<'a> Trie<'a> {
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(
- current_node
+ let weighted = WeightedIndex::new(current_node.child_nodes.iter().map(|(_, node)| {
+ node.child_count / node
.child_nodes
.iter()
- .map(|(_, node)| node.child_count / (length + 1)),
- )
+ .map(|(_, b)| b.child_count)
+ .sum::<u64>()
+ }))
.expect("distribution creation should be valid");
let (key, node) = current_node