Skip to content

Commit

Permalink
Add 'make_generator(value)'
Browse files Browse the repository at this point in the history
  • Loading branch information
SSoelvsten committed Nov 17, 2023
1 parent 25b0c05 commit e327179
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
13 changes: 3 additions & 10 deletions src/adiar/bdd/restrict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,9 @@ namespace adiar
__bdd bdd_restrict(const exec_policy &ep,
const bdd &f, bdd::label_type var, bool val)
{
bool gen_called = false;
auto gen = [&gen_called, &var, &val]() -> optional<pair<bdd::label_type, bool>> {
if (gen_called) {
return make_optional<pair<bdd::label_type, bool>>();
}
gen_called = true;
return make_pair<bdd::label_type, bool>(var, val);
};

return bdd_restrict(ep, f, gen);
return bdd_restrict(ep,
f,
make_generator(make_pair<bdd::label_type, bool>(var, val)));
}

__bdd bdd_restrict(const bdd &f, bdd::label_type var, bool val)
Expand Down
18 changes: 18 additions & 0 deletions src/adiar/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ namespace adiar
};
}

// TODO: Add make_generator(begin, end) for rvalue iterators; they go out of
// scope at return!

////////////////////////////////////////////////////////////////////////////
/// \brief Wrap an `adiar::internal::file_stream` into a generator function.
////////////////////////////////////////////////////////////////////////////
Expand All @@ -128,6 +131,21 @@ namespace adiar
};
}

////////////////////////////////////////////////////////////////////////////
/// \brief Wrap a single value into a generator.
////////////////////////////////////////////////////////////////////////////
template<typename RetType>
inline generator<RetType>
make_generator(const RetType &r)
{
return [=, end = false]() mutable {
if (end) { return make_optional<RetType>(); }

end = true;
return make_optional(r);
};
}

/// \}
//////////////////////////////////////////////////////////////////////////////

Expand Down
19 changes: 2 additions & 17 deletions src/adiar/zdd/subset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@

namespace adiar
{
// TODO: Merge with the generator in `bdd_restrict(f, var, val)`.
inline auto make_generator(const zdd::label_type &var, bool &gen_called)
{
adiar_assert(!gen_called);
return [&gen_called, &var]() -> optional<zdd::label_type> {
if (gen_called) {
return make_optional<zdd::label_type>();
}
gen_called = true;
return var;
};
}

template<assignment FIX_VALUE>
class zdd_subset_labels
{
Expand Down Expand Up @@ -152,8 +139,7 @@ namespace adiar

__zdd zdd_offset(const exec_policy &ep, const zdd &A, zdd::label_type var)
{
bool gen_called = false;
return zdd_offset(ep, A, make_generator(var, gen_called));
return zdd_offset(ep, A, make_generator(var));
}

__zdd zdd_offset(const zdd &A, zdd::label_type var)
Expand Down Expand Up @@ -251,8 +237,7 @@ namespace adiar

__zdd zdd_onset(const exec_policy &ep, const zdd &A, zdd::label_type var)
{
bool gen_called = false;
return zdd_onset(ep, A, make_generator(var, gen_called));
return zdd_onset(ep, A, make_generator(var));
}

__zdd zdd_onset(const zdd &A, zdd::label_type var)
Expand Down

0 comments on commit e327179

Please sign in to comment.