Skip to content

Commit

Permalink
Add '-' operator as an alias for 'bdd_diff'
Browse files Browse the repository at this point in the history
  • Loading branch information
SSoelvsten committed May 30, 2024
1 parent 2097f51 commit 35bad41
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/adiar/bdd.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,33 @@ namespace adiar
__bdd
bdd_diff(const exec_policy& ep, const bdd& f, const bdd& g);

//////////////////////////////////////////////////////////////////////////////////////////////////
/// \see bdd_diff, bdd_not
//////////////////////////////////////////////////////////////////////////////////////////////////
bdd
operator-(const bdd& f);

//////////////////////////////////////////////////////////////////////////////////////////////////
/// \see bdd_diff, bdd_not
//////////////////////////////////////////////////////////////////////////////////////////////////
__bdd
operator-(__bdd&& f);

//////////////////////////////////////////////////////////////////////////////////////////////////
/// \see bdd_diff
//////////////////////////////////////////////////////////////////////////////////////////////////
__bdd
operator-(const bdd& lhs, const bdd& rhs);

/// \cond
__bdd
operator-(const bdd&, __bdd&&);
__bdd
operator-(__bdd&&, const bdd&);
__bdd
operator-(__bdd&&, __bdd&&);
/// \endcond

//////////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Logical 'less than' operator.
///
Expand Down
33 changes: 33 additions & 0 deletions src/adiar/bdd/bdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace adiar
__BDD_OPER(__bdd, &);
__BDD_OPER(__bdd, |);
__BDD_OPER(__bdd, ^);
__BDD_OPER(__bdd, -);
__BDD_OPER(bool, ==);
__BDD_OPER(bool, !=);

Expand Down Expand Up @@ -140,6 +141,20 @@ namespace adiar
return (*this = std::move(temp));
}

bdd&
bdd::operator-=(const bdd& other)
{
return (*this = bdd_diff(*this, other));
}

bdd&
bdd::operator-=(bdd&& other)
{
__bdd temp = bdd_diff(*this, other);
other.deref();
return (*this = std::move(temp));
}

bool
operator==(const bdd& lhs, const bdd& rhs)
{
Expand Down Expand Up @@ -182,6 +197,24 @@ namespace adiar
return bdd_xor(lhs, rhs);
}

bdd
operator-(const bdd& f)
{
return bdd_not(f);
}

__bdd
operator-(__bdd&& f)
{
return bdd_not(std::move(f));
}

__bdd
operator-(const bdd& lhs, const bdd& rhs)
{
return bdd_diff(lhs, rhs);
}

//////////////////////////////////////////////////////////////////////////////
// Input variables
bdd::label_type
Expand Down
11 changes: 11 additions & 0 deletions src/adiar/bdd/bdd.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ namespace adiar
bdd&
operator^=(bdd&& other);
/// \endcond

////////////////////////////////////////////////////////////////////////////////////////////////
/// \see bdd_diff
////////////////////////////////////////////////////////////////////////////////////////////////
bdd&
operator-=(const bdd& other);

/// \cond
bdd&
operator-=(bdd&& other);
/// \endcond
};
}

Expand Down
38 changes: 38 additions & 0 deletions test/adiar/bdd/test_bdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,44 @@ go_bandit([]() {
it("checks two derivations of different __bdd&& [!=]",
[&]() { AssertThat((x0 | x1) != ((x0 & x1) | (~x0 & x1)), Is().True()); });
});

describe("-", [&]() {
it("negates with '-(bdd&)' [x0]", [&]() { AssertThat(-x0 == ~x0, Is().True()); });

it("negates with '-(bdd&)' [x0 & x1]",
[&]() { AssertThat(-x0_and_x1 == ~x0_and_x1, Is().True()); });

it("negates with '-(__bdd&) [x0 & x1]",
[&]() { AssertThat(-(x0 & x1) == ~x0_and_x1, Is().True()); });

it("computes 'x0 - x1'", [&]() {
const bdd f = x0 - x1;
AssertThat(f == (x0 & ~x1), Is().True());
});

it("accumulates with '-=(bdd&)' operator", [&]() {
bdd f = x0;
f -= x1;
AssertThat(f == (x0 & ~x1), Is().True());
AssertThat(f != (x0 & ~x1), Is().False());

f -= x0;
AssertThat(f == terminal_F, Is().True());
});

it("accumulates with '-=(__bdd&&)' operator", [&]() {
bdd f = terminal_T;
f -= x0 & x1;
AssertThat(f == ~(x0 & x1), Is().True());
AssertThat(f != ~(x0 & x1), Is().False());
});

it("computes with __bdd&& and bdd& operators", [&]() {
const bdd f = x0_and_x1 - x0 - x1;
AssertThat(f == terminal_F, Is().True());
AssertThat(terminal_F == f, Is().True());
});
});
});
});
});

0 comments on commit 35bad41

Please sign in to comment.