Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VisitMap::unvisit as proposed in #610 #611

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/visit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,13 @@ pub trait VisitMap<N> {

/// Return whether `a` has been visited before.
fn is_visited(&self, a: &N) -> bool;

/// Mark `a` as unvisited.
///
/// Return **true** if this vertex was marked as visited at the time of unsetting it, false otherwise.
fn unvisit(&mut self, _a: N) -> bool {
unimplemented!("We don't know how to mark the node as unvisited.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be avoided to have a default implementation? Instead leave this out and let it be a breaking change, that's the principled approach at least.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we could totally get by without a default implementation. My initial idea was to not make this a breaking change but an additional feature that is backwards compatible. I don't have a strong preference but if breaking change is preferable, then lets go ahead with that.

}
}

impl<Ix> VisitMap<Ix> for FixedBitSet
Expand All @@ -410,6 +417,14 @@ where
fn is_visited(&self, x: &Ix) -> bool {
self.contains(x.index())
}

fn unvisit(&mut self, x: Ix) -> bool {
if self.is_visited(&x) {
self.toggle(x.index());
return true;
}
false
}
}

impl<N, S> VisitMap<N> for HashSet<N, S>
Expand All @@ -423,6 +438,10 @@ where
fn is_visited(&self, x: &N) -> bool {
self.contains(x)
}

fn unvisit(&mut self, x: N) -> bool {
self.remove(&x)
}
}

trait_template! {
Expand Down