fn head_index(
        indices: &[usize],
        dependent: usize,
        mut relative_head_position: isize,
    ) -> Result<usize, DecodeError> {
        let dependent_position = match indices.binary_search(&dependent) {
            Ok(idx) => idx,
            Err(idx) => {
                // Consider e.g. the indices
                //
                // [3, 6, 9]
                //     ^--- insertion point of 4.
                //
                // Suppose that 4 is the dependent and +2 the relative
                // position of the head. The relative position takes
                // both succeeding elements (6, 9) into
                // account. However, the insertion point is the
                // element at +1. So, compensate for this in the
                // relative position.
                if relative_head_position > 0 {
                    relative_head_position -= 1
                }
                idx
            }
        };

        let head_position = dependent_position as isize + relative_head_position;
        if head_position < 0 || head_position >= indices.len() as isize {
            return Err(DecodeError::PositionOutOfBounds);
        }

        Ok(indices[head_position as usize])
    }
/// Get the index of the head of `dependent`.
///
/// Get index of the head of `dependent`, given the relative
/// position of `dependent` to the head in `indices`.
Get the index of the head of `dependent`.
Get the index of the head of ` dependent ` .
fn head_index(
        indices: &[usize],
        dependent: usize,
        mut relative_head_position: isize,
    ) -> Result<usize, DecodeError> {
        let dependent_position = match indices.binary_search(&dependent) {
            Ok(idx) => idx,
            Err(idx) => {
                // Consider e.g. the indices
                //
                // [3, 6, 9]
                //     ^--- insertion point of 4.
                //
                // Suppose that 4 is the dependent and +2 the relative
                // position of the head. The relative position takes
                // both succeeding elements (6, 9) into
                // account. However, the insertion point is the
                // element at +1. So, compensate for this in the
                // relative position.
                if relative_head_position > 0 {
                    relative_head_position -= 1
                }
                idx
            }
        };
        let head_position = dependent_position as isize + relative_head_position;
        if head_position < 0 || head_position >= indices.len() as isize {
            return Err(DecodeError::PositionOutOfBounds);
        }
        Ok(indices[head_position as usize])
    }
fn head_index ( indices : & [ usize ] , dependent : usize , mut relative_head_position : isize , ) -> Result < usize , DecodeError > { let dependent_position = match indices . binary_search ( & dependent ) { Ok ( idx ) => idx , Err ( idx ) => { // Consider e.g. the indices // // [3, 6, 9] //     ^--- insertion point of 4. // // Suppose that 4 is the dependent and +2 the relative // position of the head. The relative position takes // both succeeding elements (6, 9) into // account. However, the insertion point is the // element at +1. So, compensate for this in the // relative position. if relative_head_position > 0 { relative_head_position -= 1 } idx } } ; let head_position = dependent_position as isize + relative_head_position ; if head_position < 0 || head_position >= indices . len ( ) as isize { return Err ( DecodeError :: PositionOutOfBounds ) ; } Ok ( indices [ head_position as usize ] ) }
Get the index of the head of `dependent`.
Get the index of the head of ` dependent ` .
indices
&[usize]
dependent
usize
relative_head_position
isize