优化日线候选和成交量窗口索引
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user