Skip to content

Commit 3d62fa8

Browse files
feat(deep_causality_uncertain): Migrated internal compute graph to ConsTree from deep_causality_ast crate. (#372)
* doc(deep_causality_ast): updated README.md Signed-off-by: Marvin Hansen <[email protected]> * feat(deep_causality_ast): Added get_id method Signed-off-by: Marvin Hansen <[email protected]> * Updated plan to add higher-kinded types to uncertain crate. Signed-off-by: Marvin Hansen <[email protected]> * feat(deep_causality_ast): code optimization. Signed-off-by: Marvin Hansen <[email protected]> * Removed extensions from uncertain crate Signed-off-by: Marvin Hansen <[email protected]> * Trying a new approach with HKT-like traits with type bounds. Signed-off-by: Marvin Hansen <[email protected]> * Trying a new approach for HKT traits and extensions for Uncertain type Signed-off-by: Marvin Hansen <[email protected]> * feat(deep_causality_uncertain): Migrated internal compute graph to ConsTree from deep_causality_ast crate. Signed-off-by: Marvin Hansen <[email protected]> * Added a verdict to feature 008 HKT uncertain. Signed-off-by: Marvin Hansen <[email protected]> * test(deep_causality_uncertain): Increased test coverage. Signed-off-by: Marvin Hansen <[email protected]> --------- Signed-off-by: Marvin Hansen <[email protected]>
1 parent 1dbd497 commit 3d62fa8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2025
-2345
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deep_causality/src/traits/contextuable/datable_uncertain.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
44
*/
55
use crate::Identifiable;
6-
use deep_causality_uncertain::Uncertain;
6+
use deep_causality_uncertain::{ProbabilisticType, Uncertain};
77

88
/// Represents uncertain data entities in a context graph.
99
///
@@ -15,7 +15,10 @@ use deep_causality_uncertain::Uncertain;
1515
/// in how data is modeled. You may wrap sensor input, encoded strings,
1616
/// discrete values, or even external references.
1717
///
18-
pub trait UncertainDatable<T>: Identifiable {
18+
pub trait UncertainDatable<T>: Identifiable
19+
where
20+
T: ProbabilisticType,
21+
{
1922
/// Returns the contained data.
2023
///
2124
/// If `Self::Data` is `Copy`, this will typically return a copy. Otherwise, it may

deep_causality/tests/types/reasoning_types/propagating_effect/display_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ fn test_display() {
2929

3030
let point = Uncertain::<bool>::point(true);
3131
let effect4 = UncertainBool(point);
32-
assert!(format!("{effect4}").contains("Point(true)"));
32+
assert!(format!("{effect4}").contains("Value(Bool(true))"));
3333

3434
let point = Uncertain::<f64>::point(4.0f64);
3535
let effect5 = UncertainFloat(point);
36-
assert!(format!("{effect5}").contains("Point(4.0)"));
36+
assert!(format!("{effect5}").contains("Value(Float(4.0))"));
3737
}

deep_causality_ast/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
# `deep_causality_ast`
22

3-
[![Crates.io](https://img.shields.io/crates/v/deep_causality_ast.svg)](https://crates.io/crates/deep_causality_ast)
4-
[![Docs.rs](https://docs.rs/deep_causality_ast/badge.svg)](https://docs.rs/deep_causality_ast)
5-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3+
[![Crates.io][crates-badge]][crates-url]
4+
[![Docs.rs][docs-badge]][docs-url]
5+
[![MIT licensed][mit-badge]][mit-url]
6+
![Tests][test-url]
7+
8+
[crates-badge]: https://img.shields.io/badge/Crates.io-Latest-blue
9+
[crates-url]: https://crates.io/crates/deep_causality_ast
10+
11+
[docs-badge]: https://img.shields.io/badge/Docs.rs-Latest-blue
12+
[docs-url]: https://docs.rs/deep_causality_ast/latest/deep_causality_ast/
13+
14+
[mit-badge]: https://img.shields.io/badge/License-MIT-blue.svg
15+
[mit-url]: https://github.com/deepcausality-rs/deep_causality/blob/main/LICENSE
16+
17+
[test-url]: https://github.com/deepcausality-rs/deep_causality/actions/workflows/run_tests.yml/badge.svg
18+
619

720
A persistent, immutable, thread-safe tree data structure for the `deep_causality` project.
821

deep_causality_ast/src/const_tree/accessors.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ impl<T> ConstTree<T> {
5454
self.node.children.get(index)
5555
}
5656

57+
/// Returns a unique identifier for the node pointed to by this `ConstTree`.
58+
///
59+
/// The ID is the memory address of the underlying `Arc`'s allocation.
60+
pub fn get_id(&self) -> usize {
61+
Arc::as_ptr(&self.node) as usize
62+
}
63+
5764
/// Checks if the tree is a leaf node (i.e., has no children).
5865
pub fn is_leaf(&self) -> bool {
5966
self.node.children.is_empty()
@@ -102,7 +109,7 @@ impl<T> ConstTree<T> {
102109
/// # Examples
103110
/// ```
104111
/// use deep_causality_ast::ConstTree;
105-
/// let tree = ConstTree::with_children(10, vec![ConstTree::new(20), ConstTree::new(30)]);
112+
/// let tree = ConstTree::with_children(10, vec![ConstTree::from(20), ConstTree::from(30)]);
106113
/// let found_node = tree.find(|v| *v > 25).unwrap();
107114
/// assert_eq!(*found_node.value(), 30);
108115
/// ```

deep_causality_ast/src/const_tree/display.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,17 @@ impl<T: fmt::Display> fmt::Display for ConstTree<T> {
1111
self.fmt_recursive(f, 0)
1212
}
1313
}
14+
15+
impl<T> ConstTree<T> {
16+
// Private helper for Display trait to recursively print the tree with indentation.
17+
pub(super) fn fmt_recursive(&self, f: &mut fmt::Formatter<'_>, indent: usize) -> fmt::Result
18+
where
19+
T: fmt::Display,
20+
{
21+
writeln!(f, "{:indent$}{}", "", self.node.value, indent = indent * 4)?; // 4 spaces per indent level
22+
for child in &self.node.children {
23+
child.fmt_recursive(f, indent + 1)?;
24+
}
25+
Ok(())
26+
}
27+
}

deep_causality_ast/src/const_tree/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ mod into_iter;
1616
mod iter;
1717
mod map;
1818
mod partial_eq;
19-
mod utils;
2019

2120
// The internal, private representation of a single node in the tree.
2221
// Deriving Debug is useful for internal debugging.

deep_causality_ast/src/const_tree/utils.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

deep_causality_ast/tests/const_tree/const_tree_tests.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#![allow(unused_imports)]
88

99
use deep_causality_ast::ConstTree;
10-
use std::sync::{Arc, Mutex};
10+
use std::sync::Arc;
1111
use std::thread;
1212

1313
#[test]
@@ -71,6 +71,30 @@ fn test_depth() {
7171
assert_eq!(empty_children_tree.depth(), 1);
7272
}
7373

74+
#[test]
75+
fn test_get_id() {
76+
let tree1 = ConstTree::new(10);
77+
let tree2 = ConstTree::new(10); // Same value, different allocation
78+
let tree1_clone = tree1.clone();
79+
80+
// IDs should be non-zero memory addresses
81+
assert_ne!(tree1.get_id(), 0);
82+
assert_ne!(tree2.get_id(), 0);
83+
84+
// A clone should have the same ID as the original
85+
assert_eq!(tree1.get_id(), tree1_clone.get_id());
86+
87+
// Independently created trees should have different IDs
88+
assert_ne!(tree1.get_id(), tree2.get_id());
89+
90+
// Verify that ptr_eq and get_id are consistent
91+
assert!(tree1.ptr_eq(&tree1_clone));
92+
assert_eq!(tree1.get_id(), tree1_clone.get_id());
93+
94+
assert!(!tree1.ptr_eq(&tree2));
95+
assert_ne!(tree1.get_id(), tree2.get_id());
96+
}
97+
7498
#[test]
7599
fn test_modification_methods() {
76100
let original = ConstTree::with_children(10, vec![ConstTree::new(11)]);

deep_causality_uncertain/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ rust_library(
1313
deps = [
1414
# Internal crates
1515
"//deep_causality_rand",
16-
"//deep_causality_haft",
16+
"//deep_causality_ast",
17+
"//deep_causality_num",
1718
],
1819
)
1920

0 commit comments

Comments
 (0)