pub fn new(
        mut available_bytes: u64,
        stored_accounts: &'a HashMap<Pubkey, FoundStoredAccount>,
        slot: Slot,
    ) -> Self {
        let num_accounts = stored_accounts.len();
        let mut hashes = Vec::with_capacity(num_accounts);
        let mut accounts = Vec::with_capacity(num_accounts);
        // index of the first account that doesn't fit in the current append vec
        let mut index_first_item_overflow = num_accounts; // assume all fit
        stored_accounts.iter().for_each(|account| {
            let account_size = account.1.account_size as u64;
            if available_bytes >= account_size {
                available_bytes = available_bytes.saturating_sub(account_size);
            } else if index_first_item_overflow == num_accounts {
                available_bytes = 0;
                // the # of accounts we have so far seen is the most that will fit in the current ancient append vec
                index_first_item_overflow = hashes.len();
            }
            hashes.push(account.1.account.hash);
            // we have to specify 'slot' here because we are writing to an ancient append vec and squashing slots,
            // so we need to update the previous accounts index entry for this account from 'slot' to 'ancient_slot'
            accounts.push((&account.1.account.meta.pubkey, &account.1.account, slot));
        });
        Self {
            hashes,
            accounts,
            index_first_item_overflow,
        }
    }
/// break 'stored_accounts' into primary and overflow
/// available_bytes: how many bytes remain in the primary storage. Excess accounts will be directed to an overflow storage
break 'stored_accounts' into primary and overflow
available_bytes: how many bytes remain in the primary storage. Excess accounts will be directed to an overflow storage
break ' stored_accounts ' into primary and overflow available_bytes : how many bytes remain in the primary storage . Excess accounts will be directed to an overflow storage
pub fn new(
        mut available_bytes: u64,
        stored_accounts: &'a HashMap<Pubkey, FoundStoredAccount>,
        slot: Slot,
    ) -> Self {
        let num_accounts = stored_accounts.len();
        let mut hashes = Vec::with_capacity(num_accounts);
        let mut accounts = Vec::with_capacity(num_accounts);
        // index of the first account that doesn't fit in the current append vec
        let mut index_first_item_overflow = num_accounts; // assume all fit
        stored_accounts.iter().for_each(|account| {
            let account_size = account.1.account_size as u64;
            if available_bytes >= account_size {
                available_bytes = available_bytes.saturating_sub(account_size);
            } else if index_first_item_overflow == num_accounts {
                available_bytes = 0;
                // the # of accounts we have so far seen is the most that will fit in the current ancient append vec
                index_first_item_overflow = hashes.len();
            }
            hashes.push(account.1.account.hash);
            // we have to specify 'slot' here because we are writing to an ancient append vec and squashing slots,
            // so we need to update the previous accounts index entry for this account from 'slot' to 'ancient_slot'
            accounts.push((&account.1.account.meta.pubkey, &account.1.account, slot));
        });
        Self {
            hashes,
            accounts,
            index_first_item_overflow,
        }
    }
pub fn new ( mut available_bytes : u64 , stored_accounts : & ' a HashMap < Pubkey , FoundStoredAccount > , slot : Slot , ) -> Self { let num_accounts = stored_accounts . len ( ) ; let mut hashes = Vec :: with_capacity ( num_accounts ) ; let mut accounts = Vec :: with_capacity ( num_accounts ) ; // index of the first account that doesn't fit in the current append vec let mut index_first_item_overflow = num_accounts ; // assume all fit stored_accounts . iter ( ) . for_each ( | account | { let account_size = account . 1 . account_size as u64 ; if available_bytes >= account_size { available_bytes = available_bytes . saturating_sub ( account_size ) ; } else if index_first_item_overflow == num_accounts { available_bytes = 0 ; // the # of accounts we have so far seen is the most that will fit in the current ancient append vec index_first_item_overflow = hashes . len ( ) ; } hashes . push ( account . 1 . account . hash ) ; // we have to specify 'slot' here because we are writing to an ancient append vec and squashing slots, // so we need to update the previous accounts index entry for this account from 'slot' to 'ancient_slot' accounts . push ( ( & account . 1 . account . meta . pubkey , & account . 1 . account , slot ) ) ; } ) ; Self { hashes , accounts , index_first_item_overflow , } }
break 'stored_accounts' into primary and overflow
available_bytes: how many bytes remain in the primary storage.
break ' stored_accounts ' into primary and overflow available_bytes : how many bytes remain in the primary storage .
available_bytes
u64
stored_accounts
&'a HashMap<Pubkey, FoundStoredAccount>
slot
Slot
available_bytes
u64
stored_accounts
&'a HashMap<Pubkey, FoundStoredAccount>
slot
Slot