优化日线候选和成交量窗口索引

This commit is contained in:
boris
2026-08-24 11:34:20 +08:00
parent 555f2ab9bd
commit 911074ae95
2 changed files with 52 additions and 21 deletions
+26 -3
View File
@@ -487,6 +487,7 @@ struct SymbolPriceSeries {
last_prefix: Vec<f64>,
valid_volume_sum_prefix: Vec<f64>,
valid_volume_count_prefix: Vec<usize>,
valid_volume_start_by_count: Vec<usize>,
}
#[derive(Debug, Clone)]
@@ -706,6 +707,14 @@ impl SymbolPriceSeries {
+ usize::from(valid),
);
}
let valid_volume_count = valid_volume_count_prefix
.last()
.copied()
.unwrap_or_default();
let mut valid_volume_start_by_count = vec![0usize; valid_volume_count + 1];
for (index, count) in valid_volume_count_prefix.iter().copied().enumerate() {
valid_volume_start_by_count[count] = index;
}
Self {
symbol,
@@ -735,6 +744,7 @@ impl SymbolPriceSeries {
last_prefix,
valid_volume_sum_prefix,
valid_volume_count_prefix,
valid_volume_start_by_count,
}
}
@@ -883,9 +893,8 @@ impl SymbolPriceSeries {
return None;
}
let target_count = valid_count - lookback;
let start = self.valid_volume_count_prefix[..=end]
.partition_point(|count| *count <= target_count)
.saturating_sub(1);
let start = *self.valid_volume_start_by_count.get(target_count)?;
debug_assert!(start <= end);
Some((start, end))
}
@@ -2326,6 +2335,20 @@ impl DataSet {
.unwrap_or_default()
}
pub fn factor_snapshot_rows_on(&self, date: NaiveDate) -> &[Arc<DailyFactorSnapshot>] {
self.factor_by_date
.get(&date)
.map(Vec::as_slice)
.unwrap_or(&[])
}
pub fn factor_symbol_ids_on(&self, date: NaiveDate) -> &[u32] {
self.factor_symbol_ids_by_date
.get(&date)
.map(Vec::as_slice)
.unwrap_or(&[])
}
pub fn factor_text_snapshots_on(&self, date: NaiveDate) -> Vec<&FactorTextValue> {
self.factor_text_by_date
.get(&date)