pub struct StoragePrefetchEngine {
pub config: PeConfig,
pub access_history: VecDeque<PeAccessEvent>,
pub coaccesses: HashMap<String, CoAccessPair>,
pub recent_cids: VecDeque<String>,
pub pattern_state: HashMap<String, Vec<u64>>,
/* private fields */
}Expand description
Intelligent prefetch engine: records access events, identifies co-access pairs, detects per-CID access patterns, and generates prioritised prefetch hints.
Fields§
§config: PeConfigEngine configuration (immutable after construction).
access_history: VecDeque<PeAccessEvent>Ordered history of recent access events (front = oldest).
coaccesses: HashMap<String, CoAccessPair>Co-access pairs keyed by "<cid_a>:<cid_b>" (cid_a < cid_b).
recent_cids: VecDeque<String>CIDs seen in recent accesses (last config.pattern_window entries).
pattern_state: HashMap<String, Vec<u64>>Per-CID list of recent access timestamps (last pattern_window entries).
Implementations§
Source§impl StoragePrefetchEngine
impl StoragePrefetchEngine
Sourcepub fn record_access(&mut self, event: PeAccessEvent) -> Vec<PePrefetchHint>
pub fn record_access(&mut self, event: PeAccessEvent) -> Vec<PePrefetchHint>
Record an access event.
Side effects:
- Appends
eventtoaccess_history. - Updates co-access pairs for every event within
coaccess_window_ms. - Updates
pattern_statefor the accessed CID. - Returns prefetch hints for the accessed CID.
Sourcepub fn generate_hints(&self, cid: &str, now: u64) -> Vec<PePrefetchHint>
pub fn generate_hints(&self, cid: &str, now: u64) -> Vec<PePrefetchHint>
Generate prefetch hints for cid at the given now timestamp.
Returns up to config.max_prefetch_hints hints sorted by descending
coaccess_count * recency_weight.
Sourcepub fn detect_pattern(&self, cid: &str) -> PeAccessPattern
pub fn detect_pattern(&self, cid: &str) -> PeAccessPattern
Detect the access pattern for a given CID using the last pattern_window
recorded timestamps.
Decision logic (in order):
Repeated— ≥ 3 timestamps in the pattern state.Sequential— inter-access std-dev < 20 % of the mean interval.Unknown— otherwise.
Sourcepub fn top_coaccessed<'a>(
&'a self,
cid: &str,
n: usize,
) -> Vec<&'a CoAccessPair>
pub fn top_coaccessed<'a>( &'a self, cid: &str, n: usize, ) -> Vec<&'a CoAccessPair>
Return the top n co-access pairs involving cid, sorted by
coaccess_count descending.
Sourcepub fn evict_stale_pairs(&mut self, max_age_ms: u64, now: u64) -> usize
pub fn evict_stale_pairs(&mut self, max_age_ms: u64, now: u64) -> usize
Remove co-access pairs not seen within the last max_age_ms milliseconds.
Returns the number of pairs removed.
Sourcepub fn total_pairs(&self) -> usize
pub fn total_pairs(&self) -> usize
Return the total number of co-access pairs currently tracked.
Sourcepub fn history_len(&self) -> usize
pub fn history_len(&self) -> usize
Return the number of events in the access history buffer.
Sourcepub fn most_accessed_cids(&self, n: usize) -> Vec<(String, usize)>
pub fn most_accessed_cids(&self, n: usize) -> Vec<(String, usize)>
Return the top n most-accessed CIDs by total appearance in
access_history, as (cid, count) pairs sorted by count descending.
Sourcepub fn stats(&self) -> PePrefetchStats
pub fn stats(&self) -> PePrefetchStats
Return aggregate statistics.
Auto Trait Implementations§
impl Freeze for StoragePrefetchEngine
impl RefUnwindSafe for StoragePrefetchEngine
impl Send for StoragePrefetchEngine
impl Sync for StoragePrefetchEngine
impl Unpin for StoragePrefetchEngine
impl UnsafeUnpin for StoragePrefetchEngine
impl UnwindSafe for StoragePrefetchEngine
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more