]> git.puffer.fish Git - matthieu/gru.git/commitdiff
make weighted probabilities depending on node's children children count
authorMatthieu Pignolet <matthieu@matthieu-dev.xyz>
Thu, 6 Jun 2024 10:13:41 +0000 (14:13 +0400)
committerMatthieu Pignolet <matthieu@matthieu-dev.xyz>
Thu, 6 Jun 2024 10:13:41 +0000 (14:13 +0400)
autofeur_db/src/trie.rs

index bbc2a93b32f592ade57a6f724b547d2a6c3ec14b..6d0867a99705a50534ee16d754e441f2a837cb95 100644 (file)
@@ -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