修复 rust 引用问题

This commit is contained in:
YuWuKunCheng
2026-05-28 01:07:16 +08:00
parent 4908870245
commit 52823e6c75
19 changed files with 1777 additions and 323 deletions
+62 -21
View File
@@ -55,6 +55,18 @@ pub struct 虚线 {
pub : bool,
}
/// MACD行为统计 — 统计MACD行为 方法的返回类型
#[derive(Debug, Clone)]
pub struct MACD行为统计 {
pub DIF上穿0: i64,
pub DIF下穿0: i64,
pub DEA上穿0: i64,
pub DEA下穿0: i64,
pub : i64,
pub : i64,
pub : Vec<(usize, usize, usize)>,
}
impl 线 {
pub fn new(
: i64,
@@ -144,12 +156,27 @@ impl 虚线 {
/// 获取该虚线范围内的普K序列
pub fn K序列(&self, K序列: &[Rc<K线>]) -> Vec<Rc<K线>> {
let = self... as usize;
let = self... as usize;
if < K序列.len() && < K序列.len() && <= {
K序列[..=].to_vec()
} else {
Vec::new()
// 使用指针查找(与 Python list.index 身份匹配行为一致),
// 而非序号切片——因为序号可能与实际位置不一致。
let = K序列
.iter()
.position(|k| Rc::as_ptr(k) == Rc::as_ptr(&self...K线));
let = K序列
.iter()
.position(|k| Rc::as_ptr(k) == Rc::as_ptr(&self...K线));
match (, ) {
(Some(s), Some(e)) if s <= e => K序列[s..=e].to_vec(),
_ => {
// 指针查找失败时回退到序号方式
println!("[警告]虚线.获取普K序列 <指针查找失败时回退到序号方式>");
let = self... as usize;
let = self... as usize;
if < K序列.len() && < K序列.len() && <= {
K序列[..=].to_vec()
} else {
Vec::new()
}
}
}
}
@@ -158,6 +185,18 @@ impl 虚线 {
K线::(K序列, &self.., &self..).unwrap_or_default()
}
/// 获取_武 — 递归获取虚线的终点分型(笔直接返回武,线段递归到底层笔的武)
pub fn _武(&self) -> Rc<> {
if self. == "" {
return Rc::clone(&self.);
}
let mut current: &线 = self;
while current. != "" {
current = &*current..last().unwrap();
}
Rc::clone(&current.)
}
/// 获取数据文本(用于保存/调试)
pub fn (&self) -> String {
use crate::utils::format_f64_g;
@@ -693,9 +732,7 @@ impl 虚线 {
K序列: &[Rc<K线>],
: usize,
: usize,
) -> std::collections::HashMap<String, String> {
use std::collections::HashMap;
) -> MACD行为统计 {
let mut dif_up = 0;
let mut dif_down = 0;
let mut dea_up = 0;
@@ -759,17 +796,17 @@ impl 虚线 {
}
}
let = Self::(&, , );
let = Self::(&, , );
let mut map = HashMap::new();
map.insert("DIF上穿0".into(), dif_up.to_string());
map.insert("DIF下穿0".into(), dif_down.to_string());
map.insert("DEA上穿0".into(), dea_up.to_string());
map.insert("DEA下穿0".into(), dea_down.to_string());
map.insert("金叉次数".into(), golden.to_string());
map.insert("死叉次数".into(), death.to_string());
map.insert("密集交叉区域".into(), format!("{:?}", ));
map
MACD行为统计 {
DIF上穿0: dif_up,
DIF下穿0: dif_down,
DEA上穿0: dea_up,
DEA下穿0: dea_down,
: golden,
: death,
,
}
}
// ---- 买卖意义 ----
@@ -797,7 +834,7 @@ impl 虚线 {
let = Self::K买卖点模式(&._指标模式, &线.., );
let = false;
let : Vec<Rc<>> = if 线. == "" {
let : Vec<Rc<K线>> = if 线. == "" {
crate::algorithm::bi::::(线, )
} else {
crate::algorithm::segment::线::(线, )
@@ -816,7 +853,11 @@ impl 虚线 {
format!(
"背驰过:{},极值:{},柱子分型匹配",
.len(),
Self::MACD极值(K序列, 线)
if Self::MACD极值(K序列, 线) {
"True"
} else {
"False"
}
),
);
}