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

left_child_with_depth and right_child_with_depth #15

Open
ralphtheninja opened this issue Apr 6, 2018 · 0 comments
Open

left_child_with_depth and right_child_with_depth #15

ralphtheninja opened this issue Apr 6, 2018 · 0 comments
Labels

Comments

@ralphtheninja
Copy link
Contributor

If it turns out that left_child_with_depth and right_child_with_depth can be private, there's a few things we could change after that

  1. If they aren't used internally (which I suspect they aren't), then we could merge them, so body of left_child_with_depth is moved to left_child (and similarly for right_child)
  2. The depth == 0 check is no longer needed, since this only happens for even indices

So

pub fn left_child_with_depth(i: usize, depth: usize) -> Option<usize> {
  if is_even(i) {
    None
  } else if depth == 0 {
    Some(i)
  } else {
    Some(index(
      depth - 1,
      offset_with_depth(i, depth) << 1,
    ))
  }
}

pub fn left_child(i: usize) -> Option<usize> {
  left_child_with_depth(i, depth(i))
}

Could be

pub fn left_child(i: usize) -> Option<usize> {
  if is_even(i) {
    None
  } else {
    let d = depth(i)
    Some(index(
      d - 1,
      offset_with_depth(i, d) << 1,
    ))
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant