修复 Arc::make_mut 遗留问题

增加 基础数据对比方法
This commit is contained in:
YuWuKunCheng
2026-06-05 16:35:31 +08:00
parent 823a24d364
commit e33b1f0744
17 changed files with 1809 additions and 24 deletions
+6 -4
View File
@@ -645,11 +645,13 @@ impl 笔 {
}
if let Some() = .last() {
let seg = Arc::make_mut(&mut );
seg.
let = Arc::make_mut(&mut );
.
.store(..load(Ordering::Relaxed) + 1, Ordering::Relaxed);
if seg..read().unwrap()..is_none() || seg..read().unwrap()..is_none() {
seg..store(false, Ordering::Relaxed);
if ..read().unwrap()..is_none() || ..read().unwrap()..is_none()
{
..store(false, Ordering::Relaxed);
}
if matches!(
..read().unwrap().(),
+95 -2
View File
@@ -387,7 +387,7 @@ impl 中枢 {
pub fn (
: Arc<线>, : Arc<线>, : Arc<线>, : i64, : &str
) -> Self {
debug_assert!(Self::(&, &, &), "中枢.创建 基础检查失败");
assert!(Self::(&, &, &), "中枢.创建 基础检查失败");
Self::new(
0,
format!("{}中枢<{}>", , ..read().unwrap()),
@@ -566,7 +566,7 @@ impl 中枢 {
} else {
if .is_empty() {
// 仍在范围内:延伸中枢
debug_assert!(
assert!(
[_idx]
.
.read()
@@ -615,6 +615,99 @@ impl 中枢 {
}
}
}
/// 结构化相等校验 — 递归校验基础序列虚线和第三买卖线,返回 (是否相等, 差异描述)
pub fn (&self, other: &Self, : f64) -> (bool, String) {
if self..load(Ordering::Relaxed) != other..load(Ordering::Relaxed) {
return (
false,
format!(
"中枢: [序号] 不等 A={},B={}",
self..load(Ordering::Relaxed),
other..load(Ordering::Relaxed)
),
);
}
if *self..read().unwrap() != *other..read().unwrap() {
return (
false,
format!(
"中枢: [标识] 不等 A={},B={}",
self..read().unwrap(),
other..read().unwrap()
),
);
}
if self..load(Ordering::Relaxed) != other..load(Ordering::Relaxed) {
return (
false,
format!(
"中枢: [级别] 不等 A={},B={}",
self..load(Ordering::Relaxed),
other..load(Ordering::Relaxed)
),
);
}
// 基础序列
let a_seq = self..read().unwrap();
let b_seq = other..read().unwrap();
if a_seq.len() != b_seq.len() {
return (
false,
format!(
"中枢: [基础序列] 长度不一致 A={},B={}",
a_seq.len(),
b_seq.len()
),
);
}
for (idx, (a, b)) in a_seq.iter().zip(b_seq.iter()).enumerate() {
let (eq, msg) = a.(b, );
if !eq {
return (false, format!("中枢: 基础序列[{idx}]虚线异常 >> {msg}"));
}
}
// 第三买卖线
let = |: &str,
a: &Option<Arc<线>>,
b: &Option<Arc<线>>,
: f64|
-> Result<(), String> {
match (a, b) {
(None, None) => Ok(()),
(Some(x), Some(y)) => {
let (eq, msg) = x.(y, );
if eq {
Ok(())
} else {
Err(format!("中枢: [{名}]子虚线异常 >> {msg}"))
}
}
_ => Err(format!(
"中枢: [{名}]空值不一致 A={},B={}",
a.is_some(),
b.is_some()
)),
}
};
(
"第三买卖线",
&self.线.read().unwrap(),
&other.线.read().unwrap(),
,
)
.map_err(|e| (false, e))
.ok();
(
"本级_第三买卖线",
&self._第三买卖线.read().unwrap(),
&other._第三买卖线.read().unwrap(),
,
)
.map_err(|e| (false, e))
.ok();
(true, "中枢: 全部字段一致".into())
}
}
impl std::fmt::Display for {
+9 -13
View File
@@ -785,7 +785,7 @@ impl 线段 {
let 线 = 线.last().unwrap();
debug_assert!(
assert!(
线..read().unwrap()[2].is_some()
|| 线..load(Ordering::Relaxed),
"线段._向序列中添加[{}], 之前线段.右 = None {}",
@@ -849,10 +849,9 @@ impl 线段 {
}
}
let mut = 线.pop().unwrap();
let seg = Arc::make_mut(&mut );
*seg..write().unwrap() = None;
seg..store(false, Ordering::Relaxed);
let = 线.pop().unwrap();
..store(false, Ordering::Relaxed);
*..write().unwrap() = None;
Some()
}
@@ -1510,9 +1509,8 @@ impl 线段 {
}
if Arc::as_ptr(线.last().unwrap()) == Arc::as_ptr(线) {
let mut drop = 线.pop().unwrap();
let seg = Arc::make_mut(&mut drop);
seg..store(false, Ordering::Relaxed);
let drop = 线.pop().unwrap();
drop..store(false, Ordering::Relaxed);
Some(drop)
} else {
panic!("线段._从序列中删除 弹出数据不在列表中 {}", 线);
@@ -1724,7 +1722,7 @@ impl 线段 {
let = &[.len() - 3];
let = &[.len() - 1];
debug_assert!(
assert!(
..load(Ordering::Relaxed) < ..load(Ordering::Relaxed),
"进入段.序号 >= 离开段.序号"
);
@@ -1780,7 +1778,7 @@ impl 线段 {
{
let = &..read().unwrap()[ - 1];
let = &[.len() - 1];
debug_assert!(
assert!(
..load(Ordering::Relaxed) < ..load(Ordering::Relaxed)
);
if .() != .() {
@@ -1807,9 +1805,7 @@ impl 线段 {
// 第三买卖点后盘整背驰
let = &[.len() - 3];
let = &[.len() - 1];
debug_assert!(
..load(Ordering::Relaxed) < ..load(Ordering::Relaxed)
);
assert!(..load(Ordering::Relaxed) < ..load(Ordering::Relaxed));
if .() != .() {
return crate::algorithm::divergence::::(
, ,
+44
View File
@@ -270,6 +270,50 @@ impl K线 {
Some(&[_idx..=_idx])
}
/// 结构化相等校验 — 比对各字段,浮点字段使用容差比较,返回 (是否相等, 差异描述)
pub fn (&self, other: &Self, : f64) -> (bool, String) {
if self. != other. {
return (
false,
format!("K线: [标识] 不等 A={},B={}", self., other.),
);
}
if self. != other. {
return (
false,
format!("K线: [序号] 不等 A={},B={}", self., other.),
);
}
if self. != other. {
return (
false,
format!("K线: [周期] 不等 A={},B={}", self., other.),
);
}
if self. != other. {
return (
false,
format!("K线: [时间戳] 不等 A={},B={}", self., other.),
);
}
let = [
("", self., other.),
("", self., other.),
("开盘价", self., other.),
("收盘价", self., other.),
("成交量", self., other.),
];
for (, a, b) in & {
if (a - b).abs() > {
return (
false,
format!("K线: [{名}] 浮点超限 容差={浮点容差:.2e} A={a:.10},B={b:.10}"),
);
}
}
(true, "K线: 全部字段一致".into())
}
/// 截取Arc<K线>序列中从始到终的片段
pub fn rc(: &[Arc<Self>], : &Arc<Self>, : &Arc<Self>) -> Vec<Arc<Self>> {
let _ptr = Arc::as_ptr();
+131
View File
@@ -531,6 +531,137 @@ impl 缠论K线 {
let _idx = .iter().position(|k| std::ptr::eq(Arc::as_ptr(k), ))?;
Some([_idx..=_idx].to_vec())
}
/// 结构化相等校验 — 比对所有字段,浮点容差,递归校验标的K线,返回 (是否相等, 差异描述)
pub fn (&self, other: &Self, : f64) -> (bool, String) {
if self..load(Ordering::Relaxed) != other..load(Ordering::Relaxed) {
return (
false,
format!(
"缠论K线: [序号] 不等 A={},B={}",
self..load(Ordering::Relaxed),
other..load(Ordering::Relaxed)
),
);
}
if self..load(Ordering::Relaxed) != other..load(Ordering::Relaxed) {
return (
false,
format!(
"缠论K线: [时间戳] 不等 A={},B={}",
self..load(Ordering::Relaxed),
other..load(Ordering::Relaxed)
),
);
}
if (self..get() - other..get()).abs() > {
return (
false,
format!(
"缠论K线: [高] 浮点超限 容差={浮点容差:.2e} A={:.10},B={:.10}",
self..get(),
other..get()
),
);
}
if (self..get() - other..get()).abs() > {
return (
false,
format!(
"缠论K线: [低] 浮点超限 容差={浮点容差:.2e} A={:.10},B={:.10}",
self..get(),
other..get()
),
);
}
if *self..read().unwrap() != *other..read().unwrap() {
return (
false,
format!(
"缠论K线: [方向] 不等 A={},B={}",
self..read().unwrap(),
other..read().unwrap()
),
);
}
if *self..read().unwrap() != *other..read().unwrap() {
return (
false,
format!(
"缠论K线: [分型] 不等 A={:?},B={:?}",
self..read().unwrap(),
other..read().unwrap()
),
);
}
if self. != other. {
return (
false,
format!("缠论K线: [周期] 不等 A={},B={}", self., other.),
);
}
if self. != other. {
return (
false,
format!("缠论K线: [标识] 不等 A={},B={}", self., other.),
);
}
if (self..get() - other..get()).abs() > {
return (
false,
format!(
"缠论K线: [分型特征值] 浮点超限 A={:.10},B={:.10}",
self..get(),
other..get()
),
);
}
if self. != other. {
return (
false,
format!(
"缠论K线: [原始起始序号] 不等 A={},B={}",
self., other.
),
);
}
if self..load(Ordering::Relaxed) != other..load(Ordering::Relaxed)
{
return (
false,
format!(
"缠论K线: [原始结束序号] 不等 A={},B={}",
self..load(Ordering::Relaxed),
other..load(Ordering::Relaxed)
),
);
}
// 标的K线 递归
let (eq, msg) = self
.K线
.read()
.unwrap()
.(&other.K线.read().unwrap(), );
if !eq {
return (false, format!("缠论K线: 标的K线子项异常 >> {msg}"));
}
// 买卖点信息
let a_guard = self..read().unwrap();
let b_guard = other..read().unwrap();
let a_set: std::collections::HashSet<&String> = a_guard.iter().collect();
let b_set: std::collections::HashSet<&String> = b_guard.iter().collect();
if a_set != b_set {
return (
false,
format!(
"缠论K线: [买卖点信息] 集合不等 A={:?},B={:?}",
self..read().unwrap(),
other..read().unwrap()
),
);
}
(true, "缠论K线: 全部字段一致".into())
}
}
impl crate::types::fractal:: for K线 {
+235
View File
@@ -1150,6 +1150,241 @@ impl 虚线 {
(, "".into())
}
/// 结构化相等校验 — 递归校验所有子结构(分型/缺口/缠K/中枢/线段特征/虚线),返回 (是否相等, 差异描述)
pub fn (&self, other: &Self, : f64) -> (bool, String) {
if *self..read().unwrap() != *other..read().unwrap() {
return (
false,
format!(
"虚线: [标识] 不等 A={},B={}",
self..read().unwrap(),
other..read().unwrap()
),
);
}
if self..load(Ordering::Relaxed) != other..load(Ordering::Relaxed) {
return (
false,
format!(
"虚线: [序号] 不等 A={},B={}",
self..load(Ordering::Relaxed),
other..load(Ordering::Relaxed)
),
);
}
if self..load(Ordering::Relaxed) != other..load(Ordering::Relaxed) {
return (
false,
format!(
"虚线: [级别] 不等 A={},B={}",
self..load(Ordering::Relaxed),
other..load(Ordering::Relaxed)
),
);
}
// 文
{
let (eq, msg) = self..(&other., );
if !eq {
return (false, format!("虚线: [文]分型异常 >> {msg}"));
}
}
// 武
{
let (eq, msg) = self
.
.read()
.unwrap()
.(&other..read().unwrap(), );
if !eq {
return (false, format!("虚线: [武]分型异常 >> {msg}"));
}
}
if self..load(Ordering::Relaxed) != other..load(Ordering::Relaxed) {
return (
false,
format!(
"虚线: [有效性] 不等 A={},B={}",
self..load(Ordering::Relaxed),
other..load(Ordering::Relaxed)
),
);
}
// 基础序列
{
let a = self..read().unwrap();
let b = other..read().unwrap();
if a.len() != b.len() {
return (
false,
format!("虚线: [基础序列] 长度不一致 A={},B={}", a.len(), b.len()),
);
}
for (idx, (x, y)) in a.iter().zip(b.iter()).enumerate() {
let (eq, msg) = x.(y, );
if !eq {
return (false, format!("虚线: 基础序列[{idx}]虚线异常 >> {msg}"));
}
}
}
// 特征序列
{
let a = self..read().unwrap();
let b = other..read().unwrap();
if a.len() != b.len() {
return (
false,
format!("虚线: [特征序列] 长度不一致 A={},B={}", a.len(), b.len()),
);
}
for (idx, (x, y)) in a.iter().zip(b.iter()).enumerate() {
match (x, y) {
(None, None) => {}
(Some(xx), Some(yy)) => {
let (eq, msg) = xx.(yy, );
if !eq {
return (false, format!("虚线: 特征序列[{idx}]线段特征异常 >> {msg}"));
}
}
_ => return (false, format!("虚线: 特征序列[{idx}]空值不一致")),
}
}
}
// 中枢序列
let =
|: &str, a: &[Arc<>], b: &[Arc<>], : f64| -> Result<(), String> {
if a.len() != b.len() {
return Err(format!(
"虚线: [{名}] 长度不一致 A={},B={}",
a.len(),
b.len()
));
}
for (idx, (x, y)) in a.iter().zip(b.iter()).enumerate() {
let (eq, msg) = x.(y, );
if !eq {
return Err(format!("虚线: {名}[{idx}]中枢异常 >> {msg}"));
}
}
Ok(())
};
(
"实_中枢序列",
&self._中枢序列.read().unwrap(),
&other._中枢序列.read().unwrap(),
,
)
.map_err(|e| (false, e))
.ok();
(
"虚_中枢序列",
&self._中枢序列.read().unwrap(),
&other._中枢序列.read().unwrap(),
,
)
.map_err(|e| (false, e))
.ok();
(
"合_中枢序列",
&self._中枢序列.read().unwrap(),
&other._中枢序列.read().unwrap(),
,
)
.map_err(|e| (false, e))
.ok();
// 确认K线
match (
&*self.K线.read().unwrap(),
&*other.K线.read().unwrap(),
) {
(None, None) => {}
(Some(a), Some(b)) => {
let (eq, msg) = a.(b, );
if !eq {
return (false, format!("虚线: [确认K线]缠论K线异常 >> {msg}"));
}
}
(a, b) => {
return (
false,
format!(
"虚线: [确认K线]空值不一致 A={},B={}",
a.is_some(),
b.is_some()
),
);
}
}
// 模式
if *self..read().unwrap() != *other..read().unwrap() {
return (
false,
format!(
"虚线: [模式] 不等 A={},B={}",
self..read().unwrap(),
other..read().unwrap()
),
);
}
// _特征序列_显示
if self._特征序列_显示.load(Ordering::Relaxed)
!= other._特征序列_显示.load(Ordering::Relaxed)
{
return (false, "虚线: [_特征序列_显示] 不等".to_string());
}
// 前一缺口
match (
&*self..read().unwrap(),
&*other..read().unwrap(),
) {
(None, None) => {}
(Some(a), Some(b)) => {
let (eq, msg) = a.(b, );
if !eq {
return (false, format!("虚线: [前一缺口]缺口异常 >> {msg}"));
}
}
(a, b) => {
return (
false,
format!(
"虚线: [前一缺口]空值不一致 A={},B={}",
a.is_some(),
b.is_some()
),
);
}
}
// 前一结束位置
match (
&*self..read().unwrap(),
&*other..read().unwrap(),
) {
(None, None) => {}
(Some(a), Some(b)) => {
let (eq, msg) = a.(b, );
if !eq {
return (false, format!("虚线: [前一结束位置]虚线异常 >> {msg}"));
}
}
(a, b) => {
return (
false,
format!(
"虚线: [前一结束位置]空值不一致 A={},B={}",
a.is_some(),
b.is_some()
),
);
}
}
// 短路修正
if self..load(Ordering::Relaxed) != other..load(Ordering::Relaxed) {
return (false, "虚线: [短路修正] 不等".to_string());
}
(true, "虚线: 全量字段嵌套校验一致".into())
}
}
impl std::fmt::Display for 线 {
+63 -1
View File
@@ -66,7 +66,7 @@ impl 分型 {
: Option<Arc<K线>>, : Arc<K线>, : Option<Arc<K线>>
) -> Self {
if let (Some(), Some()) = (&, &) {
debug_assert!(
assert!(
..load(Ordering::Relaxed) < ..load(Ordering::Relaxed)
&& ..load(Ordering::Relaxed) < ..load(Ordering::Relaxed),
"分型时间戳断言失败: 左={}, 中={}, 右={}",
@@ -256,6 +256,68 @@ impl 分型 {
}
.push();
}
/// 结构化相等校验 — 递归校验左/中/右缠伦K线 + 自有缓存字段,返回 (是否相等, 差异描述)
pub fn (&self, other: &Self, : f64) -> (bool, String) {
match (&self., &other.) {
(None, None) => {}
(Some(a), Some(b)) => {
let (eq, msg) = a.(b, );
if !eq {
return (false, format!("分型: [左]缠论K线异常 >> {msg}"));
}
}
(a, b) => {
return (
false,
format!("分型: [左]空值不一致 A={},B={}", a.is_some(), b.is_some()),
);
}
}
{
let (eq, msg) = self..(&other., );
if !eq {
return (false, format!("分型: [中]缠论K线异常 >> {msg}"));
}
}
match (&self., &other.) {
(None, None) => {}
(Some(a), Some(b)) => {
let (eq, msg) = a.(b, );
if !eq {
return (false, format!("分型: [右]缠论K线异常 >> {msg}"));
}
}
(a, b) => {
return (
false,
format!("分型: [右]空值不一致 A={},B={}", a.is_some(), b.is_some()),
);
}
}
if self. != other. {
return (
false,
format!("分型: [结构] 不等 A={},B={}", self., other.),
);
}
if self. != other. {
return (
false,
format!("分型: [时间戳] 不等 A={},B={}", self., other.),
);
}
if (self. - other.).abs() > {
return (
false,
format!(
"分型: [分型特征值] 浮点超限 A={:.10},B={:.10}",
self., other.
),
);
}
(true, "分型: 全部字段一致".into())
}
}
impl crate::types::fractal:: for {
+46
View File
@@ -316,6 +316,52 @@ impl 线段特征 {
}
}
/// 结构化相等校验 — 逐项递归校验基础序列中的虚线,返回 (是否相等, 差异描述)
pub fn (&self, other: &Self, : f64) -> (bool, String) {
if self. != other. {
return (
false,
format!("线段特征: [序号] 不等 A={},B={}", self., other.),
);
}
if *self..read().unwrap() != *other..read().unwrap() {
return (
false,
format!(
"线段特征: [标识] 不等 A={},B={}",
self..read().unwrap(),
other..read().unwrap()
),
);
}
if self.线 != other.线 {
return (
false,
format!(
"线段特征: [线段方向] 不等 A={},B={}",
self.线, other.线
),
);
}
if self..len() != other..len() {
return (
false,
format!(
"线段特征: [基础序列] 长度不一致 A={},B={}",
self..len(),
other..len()
),
);
}
for (idx, (a, b)) in self..iter().zip(other..iter()).enumerate() {
let (eq, msg) = a.(b, );
if !eq {
return (false, format!("线段特征: 基础序列[{idx}]虚线异常 >> {msg}"));
}
}
(true, "线段特征: 全部字段一致".into())
}
}
impl crate::types::fractal:: for 线 {
+23
View File
@@ -64,6 +64,29 @@ impl 缺口 {
Some(Self::new(.max(), .min()))
}
/// 结构化相等校验 — 浮点容差比较高/低,返回 (是否相等, 差异描述)
pub fn (&self, other: &Self, : f64) -> (bool, String) {
if (self. - other.).abs() > {
return (
false,
format!(
"缺口: [高] 浮点超限 容差={浮点容差:.2e} A={:.10},B={:.10}",
self., other.
),
);
}
if (self. - other.).abs() > {
return (
false,
format!(
"缺口: [低] 浮点超限 容差={浮点容差:.2e} A={:.10},B={:.10}",
self., other.
),
);
}
(true, "缺口: 高低价格一致".into())
}
}
impl std::fmt::Display for {