pub fn find_next_index(data: &[u8]) -> Result<u32, ProgramError> {
        let rec_active = RefDB::get_active_records(data)?;
        if rec_active == 0 {
            return Ok(0);
        }
        let rec_num = RefDB::get_total_records(data)?;
        let rec_size = RefDB::get_record_size(data)?;
        let mut offset = Header::LEN;
        let mut checked = 0;
        for index in 0..rec_num {
            let counter = RefDB::get_record_counter(data, offset)?;
            if counter == 0 {
                return Ok(index as u32);
            } else {
                checked += 1;
                if checked == rec_active {
                    return Ok((index + 1) as u32);
                }
            }
            offset += rec_size;
        }
        Err(ProgramError::InvalidAccountData)
    }
/// Returns the index of the next empty record to write to in the storage
Returns the index of the next empty record to write to in the storage
Returns the index of the next empty record to write to in the storage
pub fn find_next_index(data: &[u8]) -> Result<u32, ProgramError> {
        let rec_active = RefDB::get_active_records(data)?;
        if rec_active == 0 {
            return Ok(0);
        }
        let rec_num = RefDB::get_total_records(data)?;
        let rec_size = RefDB::get_record_size(data)?;
        let mut offset = Header::LEN;
        let mut checked = 0;
        for index in 0..rec_num {
            let counter = RefDB::get_record_counter(data, offset)?;
            if counter == 0 {
                return Ok(index as u32);
            } else {
                checked += 1;
                if checked == rec_active {
                    return Ok((index + 1) as u32);
                }
            }
            offset += rec_size;
        }
        Err(ProgramError::InvalidAccountData)
    }
pub fn find_next_index ( data : & [ u8 ] ) -> Result < u32 , ProgramError > { let rec_active = RefDB :: get_active_records ( data ) ? ; if rec_active == 0 { return Ok ( 0 ) ; } let rec_num = RefDB :: get_total_records ( data ) ? ; let rec_size = RefDB :: get_record_size ( data ) ? ; let mut offset = Header :: LEN ; let mut checked = 0 ; for index in 0 .. rec_num { let counter = RefDB :: get_record_counter ( data , offset ) ? ; if counter == 0 { return Ok ( index as u32 ) ; } else { checked += 1 ; if checked == rec_active { return Ok ( ( index + 1 ) as u32 ) ; } } offset += rec_size ; } Err ( ProgramError :: InvalidAccountData ) }
Returns the index of the next empty record to write to in the storage
Returns the index of the next empty record to write to in the storage
data
&[u8]
data
&[u8]