Skip to content

Commit 3083895

Browse files
committed
add: top-level gc, fix docs
1 parent f0367d4 commit 3083895

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

sddrs/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sddrs"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
edition = "2021"
55
authors = ["Josef Podany"]
66
repository = "https://github.com/jsfpdn/sdd-rs"

sddrs/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
//! use sddrs::manager::{options, GCStatistics, SddManager};
2020
//! use sddrs::literal::literal::Polarity;
2121
//! use bon::arr;
22+
//! use std::fs::File;
23+
//! use std::io::BufWriter;
2224
//!
2325
//! let options = options::SddOptions::builder()
2426
//! // Create right-linear vtree.
25-
//! .vtree_strategy(options::VTreeStragey::RightLinear)
27+
//! .vtree_strategy(options::VTreeStrategy::RightLinear)
2628
//! // Initialize the manager with variables A, B, and C.
2729
//! .variables(["A".to_string(), "B".to_string(), "C".to_string()])
2830
//! .build();
29-
//! let manager = SddManager::new(options);
31+
//! let manager = SddManager::new(&options);
3032
//!
3133
//! // Retrieve SDDs for literals A, B, and C.
3234
//! let a = manager.literal("A", Polarity::Positive).unwrap();
@@ -44,14 +46,14 @@
4446
//! println!("'(A ∧ B) ∨ C' has {model_count} models.");
4547
//! println!("They are:\n{models}");
4648
//!
47-
//! let sdd_path = "my_formula.dot"
49+
//! let sdd_path = "my_formula.dot";
4850
//! let f = File::create(sdd_path).unwrap();
4951
//! let mut b = BufWriter::new(f);
5052
//! manager
51-
//! .draw_sdd(&mut b as &mut dyn std::io::Write, &sdd)
52-
//! .unwrap();
53+
//! .draw_sdd(&mut b as &mut dyn std::io::Write, &a_and_b_or_c)
54+
//! .unwrap();
5355
//!
54-
//! let vtree_path = "my_vtree.dot"
56+
//! let vtree_path = "my_vtree.dot";
5557
//! let f = File::create(vtree_path).unwrap();
5658
//! let mut b = BufWriter::new(f);
5759
//! manager

sddrs/manager/manager.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ pub struct SddManager {
116116
rotating: RefCell<bool>,
117117

118118
gc_stats: RefCell<GCStatistics>,
119+
120+
apply_level: RefCell<u32>,
119121
}
120122

121123
// True and false SDDs have indicies 0 and 1 throughout the whole computation.
@@ -164,6 +166,7 @@ impl SddManager {
164166
vtree_manager: RefCell::new(VTreeManager::new(options.vtree_strategy, &variables)),
165167
literal_manager: RefCell::new(LiteralManager::new()),
166168
rotating: RefCell::new(false),
169+
apply_level: RefCell::new(0),
167170
gc_stats: RefCell::new(GCStatistics {
168171
nodes_collected: 0,
169172
gc_triggered: 0,
@@ -246,13 +249,6 @@ impl SddManager {
246249
)?;
247250
tracing::info!(sdd_id = sdd.id().0, size = sdd.size(), "after minimizing");
248251
}
249-
250-
// TODO: Remove this once garbage is collected from within
251-
// top-level apply.
252-
if self.should_collect_garbage() {
253-
self.collect_garbage();
254-
}
255-
256252
i += 1;
257253
}
258254
}
@@ -867,7 +863,7 @@ impl SddManager {
867863
matches!(
868864
self.options.garbage_collection,
869865
GarbageCollection::Automatic
870-
)
866+
) && *self.apply_level.borrow() == 0
871867
}
872868

873869
#[instrument(skip_all, level = tracing::Level::DEBUG)]
@@ -1073,6 +1069,8 @@ impl SddManager {
10731069
.borrow()
10741070
.least_common_ancestor(fst.vtree().unwrap().index(), snd.vtree().unwrap().index());
10751071

1072+
*self.apply_level.borrow_mut() += 1;
1073+
10761074
let elements = match order {
10771075
VTreeOrder::Equal => self._apply_eq(fst, snd, op),
10781076
VTreeOrder::Inequal => self._apply_ineq(fst, snd, op),
@@ -1088,7 +1086,11 @@ impl SddManager {
10881086
self.insert_node(&sdd);
10891087
self.cache_operation(&CachedOperation::BinOp(fst.id(), op, snd.id()), sdd.id());
10901088

1091-
// TODO: collect garbage for top-level apply if conditions are met.
1089+
*self.apply_level.borrow_mut() -= 1;
1090+
1091+
if self.should_collect_garbage() {
1092+
self.collect_garbage();
1093+
}
10921094

10931095
sdd
10941096
}

0 commit comments

Comments
 (0)