第二版

This commit is contained in:
YuWuKunCheng
2026-05-25 11:07:08 +08:00
parent f92eef11fb
commit bf96517c9d
21 changed files with 1599 additions and 1002 deletions
+240 -63
View File
@@ -35,7 +35,10 @@ impl 中枢 {
pub fn (&self) -> String {
format!(
"{}:{}:{}:{}",
self.().., self.().., self., self.
self.()..,
self.()..,
self.,
self.
)
}
@@ -91,6 +94,15 @@ impl 中枢 {
self.线 = Some(线);
}
/// 获取序列 — 基础序列 + 第三买卖线(若有)
pub fn (&self) -> Vec<Rc<线>> {
let mut : Vec<Rc<线>> = self..clone();
if let Some(ref ) = self.线 {
.push(Rc::clone());
}
}
pub fn (&self) -> String {
let 线_str = match &self.线 {
Some(x) => format!("{}", x),
@@ -115,24 +127,158 @@ impl 中枢 {
}
/// 校验中枢合法性
pub fn (&self, 线: &[Rc<线>], _中枢序列: &[Rc<>]) -> bool {
// 1. 检查基础序列中的元素是否仍在虚线序列中
pub fn (&mut self, : &[Rc<线>]) -> bool {
let mut = self..clone();
let mut : Vec<Rc<线>> = Vec::new();
for in &self. {
if !线.iter().any(|x| Rc::as_ptr(x) == Rc::as_ptr()) {
if !.iter().any(|x| Rc::as_ptr(x) == Rc::as_ptr()) {
.push(Rc::clone());
}
}
if !.is_empty() {
let = &[0];
if let Some(pos) = self
.
.iter()
.position(|x| Rc::as_ptr(x) == Rc::as_ptr())
{
= self.[..pos].to_vec();
}
}
if .len() < 3 {
self.线 = None;
self._第三买卖线 = None;
return false;
}
self. = ;
let = self.();
let = self.();
= Vec::new();
for in &self. {
if crate::types::::(, , .(), .()).()
{
break;
}
.push(Rc::clone());
}
self. = ;
if self..len() < 3 {
return false;
}
for i in 1..self..len() {
let = &self.[i - 1];
let = &self.[i];
if !.() {
return false;
}
}
// 2. 检查前三根重叠是否有效
if self..len() >= 3 {
let = self.();
let = self.();
if <= {
if !crate::types::::(
self.[0].(),
self.[0].(),
self.[2].(),
self.[2].(),
)
.()
{
let = self.();
let = self.();
if > {
return false;
}
}
if let Some(ref 线) = self.线.clone() {
if .iter().any(|x| Rc::as_ptr(x) == Rc::as_ptr(线)) {
if !self..last().unwrap().(线) {
self.线 = None;
} else if !crate::types::::(
self.(),
self.(),
线.(),
线.(),
)
.()
{
self.线(Rc::clone(线));
self.线 = None;
}
} else {
self.线 = None;
}
}
true
}
/// 完整性 — 详见教你炒股票43:有关背驰的补习课
/// 不完整时下一个中枢大概率会与当前中枢发生扩展
pub fn (&self, : &str) -> bool {
if self.[0]. == "" {
return self.线.is_some();
}
let 线 = if == "" {
&self..last().unwrap()._中枢序列
} else {
&self..last().unwrap()._中枢序列
};
for in 线 {
if crate::types::::(
self.(),
self.(),
.(),
.(),
)
.()
{
return true;
}
}
false
}
/// 获取扩展中枢 — 当基础序列 >= 9 时生成扩展中枢
pub fn (
&self, : &mut Vec<Rc<>>, : &crate::config::
) {
if self..len() >= 9 {
let mut 线: Vec<Rc<线>> = Vec::new();
crate::algorithm::segment::线::(&self., &mut 线, );
::(
&线,
,
false,
&format!("{}_扩展中枢_", self.),
0,
);
}
}
/// 当前状态 — 详见教你炒股票49:利润率最大的操作模式
/// 返回当前中枢最后一段所处的位置关系:中枢之中/中枢之上/中枢之下
pub fn (&self) -> &str {
let = self..last().unwrap();
let _中 = if . == "" {
&..
} else {
&..last().unwrap()..
};
let = crate::types::::(self.(), self.(), _中., _中.);
if == crate::types:::: {
"中枢之上"
} else if == crate::types:::: {
"中枢之下"
} else {
"中枢之中"
}
}
// ---- 关联函数 ----
/// 基础检查 — 三根虚线是否能形成中枢
@@ -140,22 +286,27 @@ impl 中枢 {
if !.() || !.() {
return false;
}
let = [.(), .(), .()]
.iter()
.copied()
.min_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
.unwrap_or(0.0);
let = [.(), .(), .()]
.iter()
.copied()
.max_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
.unwrap_or(0.0);
>
let = crate::types::::(.(), .(), .(), .());
matches!(
,
crate::types::::
| crate::types::::
| crate::types::::
| crate::types::::
| crate::types::::
)
}
/// 创建中枢
pub fn (: Rc<线>, : Rc<线>, : Rc<线>, : i64, : &str) -> Self {
Self::new(0, format!("{}中枢<{}>", , .), , vec![, , ])
pub fn (
: Rc<线>, : Rc<线>, : Rc<线>, : i64, : &str
) -> Self {
Self::new(
0,
format!("{}中枢<{}>", , .),
,
vec![, , ],
)
}
/// 从序列中获取中枢
@@ -177,27 +328,32 @@ impl 中枢 {
}
/// 向中枢序列尾部添加
pub fn (: &mut Vec<Rc<>>, : Rc<>) {
// Dedup
pub fn (
: &mut Vec<Rc<>>, mut : Rc<>
) {
if let Some() = .last() {
if .() == .() && .() == .() {
return;
let = Rc::make_mut(&mut );
. = . + 1;
// Python: assert seq[-1].获取序列()[-1].序号 <= new.获取序列()[-1].序号
let _seq = .();
let new_seq = .();
if let (Some(_last), Some(new_last)) = (_seq.last(), new_seq.last()) {
if _last. > new_last. {
panic!(
"向中枢序列尾部添加 序号错误 前last={} > new_last={}",
_last., new_last.
);
}
}
}
// Set序号: Python — if中枢序列: 待添加中枢.序号 = 中枢序列[-1].序号 + 1 else: stays 0
if let Some() = .last() {
let = . + 1;
// Clone to mutate since Rc is immutable
let mut cloned = (*).clone();
cloned. = ;
.push(Rc::new(cloned));
} else {
.push();
}
.push();
}
/// 从中枢序列尾部弹出
pub fn (: &mut Vec<Rc<>>, : &Rc<>) -> Option<Rc<>> {
pub fn (
: &mut Vec<Rc<>>,
: &Rc<>,
) -> Option<Rc<>> {
if .last().map(|x| Rc::as_ptr(x)) == Some(Rc::as_ptr()) {
.pop()
} else {
@@ -228,13 +384,17 @@ impl 中枢 {
if Self::(, , ) {
// Python: 序号 = 虚线序列.index(左)
let = 线.iter().position(|x| Rc::as_ptr(x) == Rc::as_ptr()).unwrap_or(i - 1);
let = 线
.iter()
.position(|x| Rc::as_ptr(x) == Rc::as_ptr())
.unwrap_or(i - 1);
if && (. == 0 || == 0) {
continue;
}
if >= 2 {
let = &线[ - 2];
let = crate::types::::(.(), .(), .(), .());
let =
crate::types::::(.(), .(), .(), .());
if .() && .().() {
continue;
}
@@ -259,46 +419,58 @@ impl 中枢 {
}
// 增量更新
let _idx = .len() - 1;
let = Rc::clone(&[_idx]);
let mut _idx = .len() - 1;
if !.(线, ) {
// Validate in-place via Rc::make_mut — avoids full中枢 struct clone
let needs_pop = {
let cur = Rc::make_mut(&mut [_idx]);
!cur.(线)
};
if needs_pop {
let = Rc::clone(&[_idx]);
Self::(, &);
Self::(线, , , , );
return;
}
// 找到当前中枢最后一个元素在虚线序列中的位置
let = &.[..len() - 1];
let = match 线
.iter()
.position(|x| Rc::as_ptr(x) == Rc::as_ptr())
{
Some(idx) => idx + 1,
None => return,
let = {
let cur = &[_idx];
let = &cur.[cur..len() - 1];
match 线
.iter()
.position(|x| Rc::as_ptr(x) == Rc::as_ptr())
{
Some(idx) => idx + 1,
None => return,
}
};
let = .();
let = .();
let mut = [_idx].();
let mut = [_idx].();
let mut : Vec<Rc<线>> = Vec::new();
let mut = (*).clone();
for i in ..线.len() {
let 线 = Rc::clone(&线[i]);
// 检查是否超出中枢范围(缺口)
if crate::types::::(, , 线.(), 线.()).() {
if crate::types::::(, , 线.(), 线.()).()
{
.push(线.clone());
// Python: if 当前中枢.基础序列[-1].之后是(当前虚线):
if ..last().unwrap().(&线) {
.线(线.clone());
let needs_三买 = {
let cur = &[_idx];
cur..last().unwrap().(&线)
};
if needs_三买 {
Rc::make_mut(&mut [_idx])
.线(线.clone());
}
} else {
if .is_empty() {
// 仍在范围内:延伸中枢
.线(线);
Rc::make_mut(&mut [_idx]).线(线);
} else {
.push(线);
}
@@ -306,12 +478,20 @@ impl 中枢 {
// 候选序列积满3个:尝试创建新中枢
while .len() >= 3 {
let = ..last().unwrap().().();
let = [_idx]
.
.last()
.unwrap()
.()
.();
match Self::(&, , ) {
Some() => {
[_idx] = Rc::new(.clone());
Self::(, );
return;
// Python: 当前中枢 = 新中枢
_idx = .len() - 1;
= [_idx].();
= [_idx].();
.clear();
}
None => {
.remove(0); // 滑动窗口
@@ -319,9 +499,6 @@ impl 中枢 {
}
}
}
// 更新当前中枢
[_idx] = Rc::new();
}
}