Skip to content

left_child_with_depth and right_child_with_depth #15

Description

@ralphtheninja

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,
    ))
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions