pub fn find_last_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 {
                checked += 1;
                if checked == rec_active {
                    return Ok((index + 1) as u32);
                }
            }
            offset += rec_size;
        }
        Err(ProgramError::InvalidAccountData)
    }
/// Returns the index of the first empty record at the back of the storage,
/// i.e. there will be no active records after the index
Returns the index of the first empty record at the back of the storage,
i.e. there will be no active records after the index
Returns the index of the first empty record at the back of the storage i . e . there will be no active records after the index
pub fn find_last_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 {
                checked += 1;
                if checked == rec_active {
                    return Ok((index + 1) as u32);
                }
            }
            offset += rec_size;
        }
        Err(ProgramError::InvalidAccountData)
    }
pub fn find_last_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 { checked += 1 ; if checked == rec_active { return Ok ( ( index + 1 ) as u32 ) ; } } offset += rec_size ; } Err ( ProgramError :: InvalidAccountData ) }
Returns the index of the first empty record at the back of the storage,
i.e.
Returns the index of the first empty record at the back of the storage i . e .
data
&[u8]
data
&[u8]