Skip to content

Commit

Permalink
Update 'zdd_contains' API to use Generators/Iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
SSoelvsten committed Sep 24, 2023
1 parent e07cdfb commit 155344d
Show file tree
Hide file tree
Showing 4 changed files with 1,041 additions and 1,103 deletions.
28 changes: 24 additions & 4 deletions src/adiar/zdd.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ namespace adiar
__zdd zdd_project(zdd &&A, const std::function<zdd::label_t()> &dom);
/// \endcond


//////////////////////////////////////////////////////////////////////////////
/// \brief Project family of sets onto a domain, i.e. remove from every
/// set all variables not within the domain.
Expand All @@ -575,15 +574,15 @@ namespace adiar
template<typename IT>
__zdd zdd_project(const zdd &A, IT begin, IT end)
{
return zdd_project(A, internal::iterator_gen<bdd::label_t>(begin, end));
return zdd_project(A, internal::iterator_gen<zdd::label_t>(begin, end));
}

/// \cond
template<typename IT>
__zdd zdd_project(zdd &&A, IT begin, IT end)
{
return zdd_project(std::forward<zdd>(A),
internal::iterator_gen<bdd::label_t>(begin, end));
internal::iterator_gen<zdd::label_t>(begin, end));
}
/// \endcond

Expand Down Expand Up @@ -772,9 +771,30 @@ namespace adiar
//////////////////////////////////////////////////////////////////////////////
/// \brief Whether the family includes the given set of labels
///
/// \param A Set of interest
///
/// \param a Generator of a bit-vector in *ascending* order.
///
/// \returns Whether \f$ a \in A \f$
//////////////////////////////////////////////////////////////////////////////
bool zdd_contains(const zdd &A, const shared_file<zdd::label_t> &a);
bool zdd_contains(const zdd &A, const std::function<zdd::label_t()> &a);

//////////////////////////////////////////////////////////////////////////////
/// \brief Whether the family includes the given set of labels
///
/// \param A Set of interest
///
/// \param begin Iterator that provides the variables in *ascending* order.
///
/// \param end Iterator that marks the end for `begin`.
///
/// \returns Whether \f$ \{\mathit{begin}, \dots, \mathit{end}\} \in A \f$
//////////////////////////////////////////////////////////////////////////////
template<typename IT>
bool zdd_contains(const zdd &A, IT begin, IT end)
{
return zdd_contains(A, internal::iterator_gen<zdd::label_t>(begin, end));
}

//////////////////////////////////////////////////////////////////////////////
/// \brief Retrieves the lexicographically smallest set a in A.
Expand Down
17 changes: 9 additions & 8 deletions src/adiar/zdd/contains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace adiar
{
class zdd_contains_visitor
{
internal::file_stream<zdd::label_t> ls;
const std::function<zdd::label_t()> &gen;

bool has_l = false;
zdd::label_t l;
Expand All @@ -22,10 +22,11 @@ namespace adiar
bool terminal_val = false;

public:
zdd_contains_visitor(const shared_file<zdd::label_t> &labels) : ls(labels)
zdd_contains_visitor(const std::function<zdd::label_t()> &a)
: gen(a)
{
has_l = ls.can_pull();
l = has_l ? ls.pull() : 0;
l = gen();
has_l = l <= zdd::MAX_LABEL;
}

inline zdd::ptr_t visit(const zdd::node_t &n)
Expand All @@ -39,7 +40,7 @@ namespace adiar
if (is_first_visit && l < visited_label) { return zdd::ptr_t::NIL(); }

// Will we miss a label?
if (l == visited_label && ls.can_pull()) { l = ls.pull(); }
if (l == visited_label && l <= zdd::MAX_LABEL) { l = gen(); }
if (next_ptr.is_node() && visited_label < l && l < next_ptr.label()) {
return zdd::ptr_t::NIL();
}
Expand All @@ -53,12 +54,12 @@ namespace adiar
{ terminal_val = s; }

inline bool get_result()
{ return terminal_val && (!has_l || l <= visited_label) && !ls.can_pull(); }
{ return terminal_val && zdd::MAX_LABEL < l; }
};

bool zdd_contains(const zdd &zdd, const shared_file<zdd::label_t> &labels)
bool zdd_contains(const zdd &zdd, const std::function<zdd::label_t()> &a)
{
zdd_contains_visitor v(labels);
zdd_contains_visitor v(a);
internal::traverse(zdd, v);
return v.get_result();
}
Expand Down
Loading

0 comments on commit 155344d

Please sign in to comment.