Skip to content

Commit

Permalink
Fix a division by zero when deleting trees
Browse files Browse the repository at this point in the history
  • Loading branch information
irevoire committed Jan 15, 2024
1 parent c0e66c6 commit 444ab21
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,13 @@ impl<D: Distance> Writer<D> {
nb_tree_nodes: u64,
nb_items: u64,
) -> Result<()> {
if roots.is_empty() {
return Ok(());
}
let nb_trees = match nb_trees {
Some(nb_trees) => nb_trees,
None => {
// 1. Estimate the number of nodes per tree
// 1. Estimate the number of nodes per tree; the division is safe because we ensured there was at least one root node above.
let nodes_per_tree = nb_tree_nodes / roots.len() as u64;
// 2. Estimate the number of tree we need to have AT LEAST as much tree-nodes than items
(nb_items / nodes_per_tree) as usize
Expand Down

0 comments on commit 444ab21

Please sign in to comment.