pub fn insert(&mut self, snapshot: BeaconSnapshot<T>, pre_state: Option<BeaconState<T>>) {
        let item = CacheItem {
            beacon_block: snapshot.beacon_block,
            beacon_block_root: snapshot.beacon_block_root,
            beacon_state: snapshot.beacon_state,
            pre_state,
        };

        if self.snapshots.len() < self.max_len {
            self.snapshots.push(item);
        } else {
            let insert_at = self
                .snapshots
                .iter()
                .enumerate()
                .filter_map(|(i, snapshot)| {
                    if snapshot.beacon_block_root != self.head_block_root {
                        Some((i, snapshot.beacon_state.slot))
                    } else {
                        None
                    }
                })
                .min_by_key(|(_i, slot)| *slot)
                .map(|(i, _slot)| i);

            if let Some(i) = insert_at {
                self.snapshots[i] = item;
            }
        }
    }
/// Insert a snapshot, potentially removing an existing snapshot if `self` is at capacity (see
/// struct-level documentation for more info).
Insert a snapshot, potentially removing an existing snapshot if `self` is at capacity (see
struct-level documentation for more info).
Insert a snapshot potentially removing an existing snapshot if ` self ` is at capacity ( see struct - level documentation for more info ) .
pub fn insert(&mut self, snapshot: BeaconSnapshot<T>, pre_state: Option<BeaconState<T>>) {
        let item = CacheItem {
            beacon_block: snapshot.beacon_block,
            beacon_block_root: snapshot.beacon_block_root,
            beacon_state: snapshot.beacon_state,
            pre_state,
        };
        if self.snapshots.len() < self.max_len {
            self.snapshots.push(item);
        } else {
            let insert_at = self
                .snapshots
                .iter()
                .enumerate()
                .filter_map(|(i, snapshot)| {
                    if snapshot.beacon_block_root != self.head_block_root {
                        Some((i, snapshot.beacon_state.slot))
                    } else {
                        None
                    }
                })
                .min_by_key(|(_i, slot)| *slot)
                .map(|(i, _slot)| i);
            if let Some(i) = insert_at {
                self.snapshots[i] = item;
            }
        }
    }
pub fn insert ( & mut self , snapshot : BeaconSnapshot < T > , pre_state : Option < BeaconState < T > > ) { let item = CacheItem { beacon_block : snapshot . beacon_block , beacon_block_root : snapshot . beacon_block_root , beacon_state : snapshot . beacon_state , pre_state , } ; if self . snapshots . len ( ) < self . max_len { self . snapshots . push ( item ) ; } else { let insert_at = self . snapshots . iter ( ) . enumerate ( ) . filter_map ( | ( i , snapshot ) | { if snapshot . beacon_block_root != self . head_block_root { Some ( ( i , snapshot . beacon_state . slot ) ) } else { None } } ) . min_by_key ( | ( _i , slot ) | * slot ) . map ( | ( i , _slot ) | i ) ; if let Some ( i ) = insert_at { self . snapshots [ i ] = item ; } } }
Insert a snapshot, potentially removing an existing snapshot if `self` is at capacity (see
struct-level documentation for more info).
Insert a snapshot potentially removing an existing snapshot if ` self ` is at capacity ( see struct - level documentation for more info ) .
&mut self
snapshot
BeaconSnapshot<T>
pre_state
Option<BeaconState<T>>