Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Extract add_leaf to its own ops function #53

Open
lsetiawan opened this issue Dec 11, 2024 · 0 comments
Open

refactor: Extract add_leaf to its own ops function #53

lsetiawan opened this issue Dec 11, 2024 · 0 comments

Comments

@lsetiawan
Copy link
Member

Need to extract the following add_leaf method to its own ops function and then call it here so it can be used independently of TreeVec

pub fn add_leaf(&mut self, leaf: usize, branch: usize) {
self.data.push(branch);
let mut ancestry_add = self.get_ancestry();
println!("{:?}", ancestry_add);
let mut found_first_leaf = false;
for r in 0..ancestry_add.len() {
for c in 0..3 {
if !found_first_leaf && ancestry_add[r][c] == self.data.len() {
// Find the indices of the first leaf
// and then set the value to the new leaf
ancestry_add[r][c] = leaf;
found_first_leaf = true;
} else if ancestry_add[r][c] >= leaf {
ancestry_add[r][c] += 1;
}
}
}
// ancestry_add[leaf_coords][leaf_col] = leaf as isize;
// let ancestry_add_ref = &mut ancestry_add;
ops::order_cherries(&mut ancestry_add);
ops::order_cherries_no_parents(&mut ancestry_add);
self.data = ops::build_vector(ancestry_add);
}

@lsetiawan lsetiawan changed the title refactor: Extract add_leaf to it's own ops function refactor: Extract add_leaf to its own ops function Dec 11, 2024
@lsetiawan lsetiawan changed the title refactor: Extract add_leaf to its own ops function refactor: Extract add_leaf to its own ops function Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant