Skip to content

Commit

Permalink
Rename 'attach(...)' -> 'open(...)', 'attached()' -> 'is_open()', and…
Browse files Browse the repository at this point in the history
… 'detach()' -> 'close()'
  • Loading branch information
SSoelvsten committed Feb 28, 2025
1 parent 2079303 commit a7812da
Show file tree
Hide file tree
Showing 18 changed files with 322 additions and 322 deletions.
14 changes: 7 additions & 7 deletions src/adiar/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,12 @@ namespace adiar
throw domain_error("There must be at least one node or terminal in the decision diagram");
}
}
nw.detach();
nw.close();

if (unref_nodes > 1) { throw domain_error("Decision diagram has more than one root"); }

const typename Policy::dd_type res(nf);
detach();
close();
return res;
}

Expand All @@ -441,7 +441,7 @@ namespace adiar
void
clear() noexcept
{
detach();
close();
}

private:
Expand All @@ -452,12 +452,12 @@ namespace adiar
attach_if_needed() noexcept
{
if (!nf) {
adiar_assert(!nw.attached(),
adiar_assert(!nw.is_open(),
"`nw`'s attachment should be consistent with existence of `nf`");

// Initialise file
nf = internal::make_shared_levelized_file<node_type>();
nw.attach(nf);
nw.open(nf);

// Initialise state variables
current_label = Policy::max_label;
Expand All @@ -475,9 +475,9 @@ namespace adiar
/// \brief Detaches the node writer and releases the pointer to the file.
/////////////////////////////////////////////////////////////////////////////////////////////////
inline void
detach() noexcept
close() noexcept
{
nw.detach();
nw.close();
nf.reset();
}

Expand Down
10 changes: 5 additions & 5 deletions src/adiar/internal/algorithms/nested_sweeping.h
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,7 @@ namespace adiar::internal
#endif
adiar_assert(outer_roots.size() > 0, "Nested Sweep needs some number of requests");

outer_ofstream.detach();
outer_ofstream.close();

#ifdef ADIAR_STATS
nested_sweeping::stats.inner_down.inputs.acc_size += outer_file->size();
Expand Down Expand Up @@ -1957,7 +1957,7 @@ namespace adiar::internal
inner_unreduced.template get<shared_arc_file_type>();

outer_file = __reduce_init_output<nesting_policy>();
outer_ofstream.attach(outer_file);
outer_ofstream.open(outer_file);

if (is_last_inner) {
nested_sweeping::inner::up<nesting_policy>(
Expand Down Expand Up @@ -2009,9 +2009,9 @@ namespace adiar::internal
nested_sweeping::stats.outer_up.skipped_nested_levels__prune += 1u;
#endif
if (outer_ofstream.size() != 0) {
outer_ofstream.detach();
outer_ofstream.close();
outer_file = __reduce_init_output<nesting_policy>();
outer_ofstream.attach(outer_file);
outer_ofstream.open(outer_file);
}
}

Expand Down Expand Up @@ -2059,7 +2059,7 @@ namespace adiar::internal
}

// Return (now not anymore 'intermediate') output
outer_ofstream.detach();
outer_ofstream.close();
return outer_file;
}

Expand Down
8 changes: 4 additions & 4 deletions src/adiar/internal/algorithms/reduce.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ namespace adiar::internal
if (reduction_rule_ret != n.uid()) {
// Open red1_mapping first (and create file on disk) when at least one
// element is written to it.
if (!red1_mapping.attached()) { red1_mapping.attach(); }
if (!red1_mapping.is_open()) { red1_mapping.open(); }
#ifdef ADIAR_STATS
stats.removed_by_rule_1 += 1u;
#endif
Expand Down Expand Up @@ -370,7 +370,7 @@ namespace adiar::internal

// Merging of red1_mapping and red2_mapping
mapping next_red1 = { node::uid_type(), node::uid_type() }; // <-- dummy value
bool has_next_red1 = red1_mapping.attached() && red1_mapping.size() > 0;
bool has_next_red1 = red1_mapping.is_open() && red1_mapping.size() > 0;
if (has_next_red1) {
red1_mapping.seek_begin();
next_red1 = red1_mapping.next();
Expand Down Expand Up @@ -416,7 +416,7 @@ namespace adiar::internal
}

// Move on to the next level
red1_mapping.detach();
red1_mapping.close();

// Update with new possible maximum 1-level cut (the one below the current level)
out.unsafe_max_1level_cut(local_1level_cut);
Expand Down Expand Up @@ -509,7 +509,7 @@ namespace adiar::internal
out.unsafe_set_number_of_terminals(!terminal_val, terminal_val);

// NOTE: We do not need to update the cuts, since this is taken care of in
// `~out() = out.detach()`.
// `~out() = out.close()`.
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/adiar/internal/io/arc_ifstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ namespace adiar::internal
////////////////////////////////////////////////////////////////////////////
arc_ifstream(const levelized_file<arc>& file)
{
attach(file);
open(file);
}

////////////////////////////////////////////////////////////////////////////
/// \brief Construct a stream unattached to a shared arc file.
////////////////////////////////////////////////////////////////////////////
arc_ifstream(const shared_ptr<levelized_file<arc>>& file)
{
attach(file);
open(file);
}

////////////////////////////////////////////////////////////////////////////
Expand All @@ -72,29 +72,29 @@ namespace adiar::internal

public:
////////////////////////////////////////////////////////////////////////////
/// \brief Attach to a levelized arc file.
/// \brief Open a levelized arc file.
///
/// \pre No `levelized_ofstream` is currently attached to this file.
////////////////////////////////////////////////////////////////////////////
void
attach(const levelized_file<arc>& f)
open(const levelized_file<arc>& f)
{
// adiar_assert(f.semi_transposed);
parent_t::attach(f);
parent_t::open(f);
_unread_terminals[false] = f.number_of_terminals[false];
_unread_terminals[true] = f.number_of_terminals[true];
}

////////////////////////////////////////////////////////////////////////////
/// \brief Attach to a shared levelized arc file.
/// \brief Open a shared levelized arc file.
///
/// \pre No `levelized_ofstream` is currently attached to this file.
////////////////////////////////////////////////////////////////////////////
void
attach(const shared_ptr<levelized_file<arc>>& f)
open(const shared_ptr<levelized_file<arc>>& f)
{
// adiar_assert(f->semi_transposed);
parent_t::attach(f);
parent_t::open(f);
_unread_terminals[false] = f->number_of_terminals[false];
_unread_terminals[true] = f->number_of_terminals[true];
}
Expand Down
48 changes: 24 additions & 24 deletions src/adiar/internal/io/arc_ofstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace adiar::internal
arc_ofstream(levelized_file<arc>& af)
: levelized_ofstream<arc>()
{
attach(af);
open(af);
}

////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -55,77 +55,77 @@ namespace adiar::internal
arc_ofstream(shared_ptr<levelized_file<arc>> af)
: levelized_ofstream<arc>()
{
attach(af);
open(af);
}

////////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Detaches and cleans up from the levelized file (if need be).
////////////////////////////////////////////////////////////////////////////////////////////////
~arc_ofstream()
{
// Sort the out-of-order terminals with 'detach()'.
detach();
// Sort the out-of-order terminals with 'close()'.
close();
}

public:
////////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Attach to a levelized file of arcs.
/// \brief Open a levelized file of arcs.
///
/// \warning Since ownership is \em not shared with this writer, you have to ensure, that the
/// file in question is not destructed before `.detach()` is called.
/// file in question is not destructed before `.close()` is called.
///
/// \pre The file is empty.
////////////////////////////////////////////////////////////////////////////////////////////////
void
attach(levelized_file<arc>& af)
open(levelized_file<arc>& af)
{
if (attached()) detach();
if (is_open()) close();
adiar_assert(af.empty());

// TODO: remove precondition and set up __latest_terminal.

return levelized_ofstream::attach(af);
return levelized_ofstream::open(af);
}

////////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Attach to a shared levelized file of arcs.
/// \brief Open a shared levelized file of arcs.
///
/// \pre The file is empty.
////////////////////////////////////////////////////////////////////////////////////////////////
void
attach(shared_ptr<levelized_file<arc>>& af)
open(shared_ptr<levelized_file<arc>>& af)
{
if (attached()) detach();
if (is_open()) close();
adiar_assert(af->empty());

// TODO: remove precondition and set up __latest_terminal.

return levelized_ofstream::attach(af);
return levelized_ofstream::open(af);
}

//////////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Detaches after having sort the out-of-order terminals.
//////////////////////////////////////////////////////////////////////////////////////////////////
void
detach()
close()
{
if (!attached()) return;
if (!is_open()) return;

#ifdef ADIAR_STATS
if (_elem_ofstreams[idx__terminals__out_of_order].size() != 0u) {
stats_arc_file.sort_out_of_order += 1;
}
#endif
_elem_ofstreams[idx__terminals__out_of_order].sort<arc_source_lt>();
levelized_ofstream::detach();
levelized_ofstream::close();
}

//////////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Write directly to the level_info file.
///
/// \param li Level information to push.
///
/// \pre `attached() == true`.
/// \pre `is_open() == true`.
//////////////////////////////////////////////////////////////////////////////////////////////////
void
push(const level_info& li)
Expand All @@ -142,7 +142,7 @@ namespace adiar::internal
///
/// \param li Level information to push.
///
/// \pre `attached() == true`.
/// \pre `is_open() == true`.
////////////////////////////////////////////////////////////////////////////////////////////////
arc_ofstream&
operator<<(const level_info& li)
Expand All @@ -156,7 +156,7 @@ namespace adiar::internal
///
/// \param a An arc with `a.target() != a::pointer_type::nil`.
///
/// \pre `attached() == true`.
/// \pre `is_open() == true`.
///
/// \see unsafe_push_internal unsafe_push_terminal
//////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -174,7 +174,7 @@ namespace adiar::internal
////////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Push an ac to the relevant underlying file.
///
/// \pre `attached() == true`.
/// \pre `is_open() == true`.
////////////////////////////////////////////////////////////////////////////////////////////////
arc_ofstream&
operator<<(const arc& a)
Expand All @@ -186,12 +186,12 @@ namespace adiar::internal
//////////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Push an internal arc to its file, i.e. where the target is a node.
///
/// \pre `attached() == true`.
/// \pre `is_open() == true`.
//////////////////////////////////////////////////////////////////////////////////////////////////
void
push_internal(const arc& a)
{
adiar_assert(attached());
adiar_assert(is_open());
adiar_assert(a.target().is_node());
adiar_assert(!a.source().is_nil());
#ifdef ADIAR_STATS
Expand All @@ -203,12 +203,12 @@ namespace adiar::internal
//////////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Push a terminal arc to its file, i.e. where the target is a terminal.
///
/// \pre `attached() == true`.
/// \pre `is_open() == true`.
//////////////////////////////////////////////////////////////////////////////////////////////////
void
push_terminal(const arc& a)
{
adiar_assert(attached());
adiar_assert(is_open());
adiar_assert(a.target().is_terminal());
adiar_assert(!a.source().is_nil());

Expand Down
Loading

0 comments on commit a7812da

Please sign in to comment.