]> 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:17:27 +0000 (14:17 +0400)
committerMatthieu Pignolet <matthieu@matthieu-dev.xyz>
Thu, 6 Jun 2024 10:17:27 +0000 (14:17 +0400)
autofeur_db/src/trie.rs

index a14c56e89e5573713df4a3c0ff12bc34e834bdf1..1788d527fa58a9b078ec80b42024001107a2bb17 100644 (file)
@@ -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");