fn next_bucket_index(num_buckets: usize, start_index: usize, curr_index: usize) -> Option<usize> {
    // Since we prefer going right first, that means if we are on the right side then we want to go
    // to the same offset on the left, however, if we are on the left we want to go 1 past the offset
    // to the right. All assuming we can actually do this without going out of bounds.
    match curr_index.cmp(&start_index) {
        Ordering::Equal => {
            let right_index = start_index.checked_add(1);
            let left_index = start_index.checked_sub(1);

            if index_is_in_bounds(num_buckets, right_index) {
                Some(right_index.unwrap())
            } else if index_is_in_bounds(num_buckets, left_index) {
                Some(left_index.unwrap())
            } else {
                None
            }
        }
        Ordering::Greater => {
            let offset = curr_index - start_index;

            let left_index = start_index.checked_sub(offset);
            let right_index = curr_index.checked_add(1);

            if index_is_in_bounds(num_buckets, left_index) {
                Some(left_index.unwrap())
            } else if index_is_in_bounds(num_buckets, right_index) {
                Some(right_index.unwrap())
            } else {
                None
            }
        }
        Ordering::Less => {
            let offset = (start_index - curr_index) + 1;

            let right_index = start_index.checked_add(offset);
            let left_index = curr_index.checked_sub(1);

            if index_is_in_bounds(num_buckets, right_index) {
                Some(right_index.unwrap())
            } else if index_is_in_bounds(num_buckets, left_index) {
                Some(left_index.unwrap())
            } else {
                None
            }
        }
    }
}
/// Computes the next bucket index that should be visited given the number of buckets, the starting index
/// and the current index.
///
/// Returns None if all of the buckets have been visited.
Computes the next bucket index that should be visited given the number of buckets, the starting index
and the current index.

Returns None if all of the buckets have been visited.
Computes the next bucket index that should be visited given the number of buckets the starting index and the current index . Returns None if all of the buckets have been visited .
fn next_bucket_index(num_buckets: usize, start_index: usize, curr_index: usize) -> Option<usize> {
    // Since we prefer going right first, that means if we are on the right side then we want to go
    // to the same offset on the left, however, if we are on the left we want to go 1 past the offset
    // to the right. All assuming we can actually do this without going out of bounds.
    match curr_index.cmp(&start_index) {
        Ordering::Equal => {
            let right_index = start_index.checked_add(1);
            let left_index = start_index.checked_sub(1);
            if index_is_in_bounds(num_buckets, right_index) {
                Some(right_index.unwrap())
            } else if index_is_in_bounds(num_buckets, left_index) {
                Some(left_index.unwrap())
            } else {
                None
            }
        }
        Ordering::Greater => {
            let offset = curr_index - start_index;
            let left_index = start_index.checked_sub(offset);
            let right_index = curr_index.checked_add(1);
            if index_is_in_bounds(num_buckets, left_index) {
                Some(left_index.unwrap())
            } else if index_is_in_bounds(num_buckets, right_index) {
                Some(right_index.unwrap())
            } else {
                None
            }
        }
        Ordering::Less => {
            let offset = (start_index - curr_index) + 1;
            let right_index = start_index.checked_add(offset);
            let left_index = curr_index.checked_sub(1);
            if index_is_in_bounds(num_buckets, right_index) {
                Some(right_index.unwrap())
            } else if index_is_in_bounds(num_buckets, left_index) {
                Some(left_index.unwrap())
            } else {
                None
            }
        }
    }
}
fn next_bucket_index ( num_buckets : usize , start_index : usize , curr_index : usize ) -> Option < usize > { // Since we prefer going right first, that means if we are on the right side then we want to go // to the same offset on the left, however, if we are on the left we want to go 1 past the offset // to the right. All assuming we can actually do this without going out of bounds. match curr_index . cmp ( & start_index ) { Ordering :: Equal => { let right_index = start_index . checked_add ( 1 ) ; let left_index = start_index . checked_sub ( 1 ) ; if index_is_in_bounds ( num_buckets , right_index ) { Some ( right_index . unwrap ( ) ) } else if index_is_in_bounds ( num_buckets , left_index ) { Some ( left_index . unwrap ( ) ) } else { None } } Ordering :: Greater => { let offset = curr_index - start_index ; let left_index = start_index . checked_sub ( offset ) ; let right_index = curr_index . checked_add ( 1 ) ; if index_is_in_bounds ( num_buckets , left_index ) { Some ( left_index . unwrap ( ) ) } else if index_is_in_bounds ( num_buckets , right_index ) { Some ( right_index . unwrap ( ) ) } else { None } } Ordering :: Less => { let offset = ( start_index - curr_index ) + 1 ; let right_index = start_index . checked_add ( offset ) ; let left_index = curr_index . checked_sub ( 1 ) ; if index_is_in_bounds ( num_buckets , right_index ) { Some ( right_index . unwrap ( ) ) } else if index_is_in_bounds ( num_buckets , left_index ) { Some ( left_index . unwrap ( ) ) } else { None } } } }
Computes the next bucket index that should be visited given the number of buckets, the starting index
and the current index.
Computes the next bucket index that should be visited given the number of buckets the starting index and the current index .
num_buckets
usize
start_index
usize
curr_index
usize
num_buckets
usize
start_index
usize
curr_index
usize