Skip to content

Commit

Permalink
Merge pull request #54 from zao111222333/master
Browse files Browse the repository at this point in the history
support `serde` serialize/deserialize for `BooleanExpression` & `Bdd`
  • Loading branch information
daemontus authored May 15, 2024
2 parents 249c905 + f8ad672 commit c0aabb2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ maintenance = { status = "actively-developed" }
fxhash = "0.2.1"
rand = "0.8.5"
num-bigint = "0.4.4"
serde = { version = "1.0", optional = true, features = ["derive"] }

# Enable rich docs for some online docs autogen services.
[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "./res/docs-head.html"]
rustdoc-args = ["--html-in-header", "./res/docs-head.html"]

[features]
default = []
serde = ["dep:serde"]
1 change: 1 addition & 0 deletions src/boolean_expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod _impl_boolean_expression;
mod _impl_parser;

/// Recursive type for boolean expression tree.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum BooleanExpression {
Const(bool),
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ const NOT_IN_VAR_NAME: [char; 11] = ['!', '&', '|', '^', '=', '<', '>', '(', ')'
///
/// To create `Bdd`s for atomic formulas, use a `BddVariableSet`.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Bdd(Vec<BddNode>);

/// Identifies one of the variables that can appear as a decision condition in the `Bdd`.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BddVariable(u16);

/// Exactly describes one assignment of boolean values to variables of a `Bdd`.
Expand Down Expand Up @@ -209,6 +211,7 @@ pub struct BddVariableSetBuilder {
/// represented as `u32` instead of `usize`, because `usize` can be 64-bits and pointers
/// represent most of the memory consumed by our BDDs.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BddPointer(u32);

/// **(internal)** Representation of individual vertices of the `Bdd` directed acyclic graph.
Expand All @@ -231,6 +234,7 @@ pub struct BddPointer(u32);
/// `BddVariableSet`. This is consistent with the fact that we first condition on smallest
/// variable ids. It can be also used for consistency checks inside the library.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BddNode {
pub var: BddVariable,
pub low_link: BddPointer,
Expand Down

0 comments on commit c0aabb2

Please sign in to comment.