Skip to content

Commit

Permalink
sdd: children of SddOr stored in BTreeSet instead of Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfpdn committed Mar 2, 2024
1 parent ef01de2 commit 29d82e7
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ pub mod literal;
pub mod manager;
pub mod options;
pub mod sdd;
#[macro_use]
pub mod util;
pub mod vtree;
10 changes: 6 additions & 4 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ pub struct SddManager {

var_label_manager: VarLabelManager,

nodes: HashMap<u64, Node>,
// Unique table holding all the decision nodes.
// More details can be found in [Algorithms and Data Structures in VLSI Design](https://link.springer.com/book/10.1007/978-3-642-58940-9).
unqiue_table: HashMap<u64, Node>,
}

impl SddManager {
Expand All @@ -24,7 +26,7 @@ impl SddManager {
options,
vtree_manager: VTreeManager::new(),
var_label_manager: VarLabelManager::new(),
nodes: HashMap::new(),
unqiue_table: HashMap::new(),
}
}

Expand All @@ -34,13 +36,13 @@ impl SddManager {
options,
vtree_manager: VTreeManager::new(),
var_label_manager: VarLabelManager::new(),
nodes,
unqiue_table: nodes,
}
}

#[must_use]
pub fn get_node(&self, id: &u64) -> Option<&Node> {
self.nodes.get(id)
self.unqiue_table.get(id)
}

pub fn conjoin(&self, _fst: &Sdd, _snd: &Sdd) {}
Expand Down
9 changes: 4 additions & 5 deletions src/sdd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use std::collections::{BTreeSet, HashSet};
use std::hash::Hash;

use crate::literal::Literal;
Expand All @@ -10,14 +10,13 @@ mod sdd_test;

type NodeIndex = u64;

#[derive(PartialEq, Eq, Clone)]
// TODO: Implement custom hashing scheme.
#[derive(PartialEq, Eq, Clone, Hash)]
pub struct Node {
sdd: Sdd,

// Index of the parent node in the SDDManager.nodes vector.
parent: Option<NodeIndex>,
index: NodeIndex,
index: NodeIndex, // index == sdd::hash
}

impl Node {
Expand Down Expand Up @@ -123,7 +122,7 @@ impl Sdd {
#[derive(Hash, PartialEq, Eq, Clone)]
#[allow(clippy::module_name_repetitions)]
pub struct SddOr {
elements: Vec<NodeIndex>,
elements: BTreeSet<NodeIndex>,
}

impl SddOr {
Expand Down
44 changes: 35 additions & 9 deletions src/sdd_test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
mod tests {
#[allow(clippy::module_inception)]
mod sdd_test {
use std::collections::HashMap;

use crate::{
literal::{Literal, VarLabel},
options::SddOptions,
sdd::{Node, Sdd, SddAnd, SddManager, SddOr},
util::btreeset,
};

#[test]
Expand All @@ -25,7 +27,13 @@ mod tests {
// Decomposition `{(true, false)}`.
(
3_u64,
Node::new(Sdd::Decision(SddOr { elements: vec![2] }), None, 3),
Node::new(
Sdd::Decision(SddOr {
elements: btreeset!(2),
}),
None,
3,
),
),
]),
);
Expand Down Expand Up @@ -59,7 +67,13 @@ mod tests {
// Decomposition `{(true, A)}`.
(
3_u64,
Node::new(Sdd::Decision(SddOr { elements: vec![2] }), None, 3),
Node::new(
Sdd::Decision(SddOr {
elements: btreeset!(2),
}),
None,
3,
),
),
]),
);
Expand Down Expand Up @@ -111,7 +125,7 @@ mod tests {
6_u64,
Node::new(
Sdd::Decision(SddOr {
elements: vec![4, 5],
elements: btreeset!(4, 5),
}),
Some(42),
6,
Expand Down Expand Up @@ -158,7 +172,13 @@ mod tests {
// Decomposition `{(true, !B)}`. This is where the SDD stops being trimmed.
(
4_u64,
Node::new(Sdd::Decision(SddOr { elements: vec![3] }), Some(42), 4),
Node::new(
Sdd::Decision(SddOr {
elements: btreeset!(3),
}),
Some(42),
4,
),
),
// Element `(A, true)`.
(
Expand All @@ -177,7 +197,7 @@ mod tests {
8_u64,
Node::new(
Sdd::Decision(SddOr {
elements: vec![4, 7],
elements: btreeset!(4, 7),
}),
Some(42),
8,
Expand Down Expand Up @@ -251,7 +271,7 @@ mod tests {
6_u64,
Node::new(
Sdd::Decision(SddOr {
elements: vec![3, 5],
elements: btreeset!(3, 5),
}),
None,
6,
Expand Down Expand Up @@ -305,7 +325,13 @@ mod tests {
// Decomposition `{(!B, true)}`.
(
6_u64,
Node::new(Sdd::Decision(SddOr { elements: vec![4] }), Some(42), 6),
Node::new(
Sdd::Decision(SddOr {
elements: btreeset!(4),
}),
Some(42),
6,
),
),
// Element `(ptr, false)` where ptr is `{(!B, true)}`.
(
Expand All @@ -317,7 +343,7 @@ mod tests {
8_u64,
Node::new(
Sdd::Decision(SddOr {
elements: vec![5, 7],
elements: btreeset!(5, 7),
}),
Some(42),
8,
Expand Down
16 changes: 16 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[allow(unused_macros)]
macro_rules! btreeset {
( $( $x:expr ),* ) => {
{
use std::collections::BTreeSet;
let mut temp_btreeset = BTreeSet::new();
$(
temp_btreeset.insert($x);
)*
temp_btreeset
}
};
}

#[allow(unused_imports)]
pub(crate) use btreeset;

0 comments on commit 29d82e7

Please sign in to comment.