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

feat: Require Clone instead of Copy in ConvexChecker, add Copy to filters #104

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Release notes

## Unreleased (2023-XX-XX)

### Changed

- `algorithms::ConvexChecker` now requires `Clone` instead of `Copy` ([#104][])

[#104]: https://github.com/CQCL/portgraph/issues/104

## v0.8.0 (2023-08-08)

### Added
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/convex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ pub struct ConvexChecker<G> {

impl<G> ConvexChecker<G>
where
G: LinkView + Copy,
G: LinkView + Clone,
{
/// Create a new ConvexChecker.
pub fn new(graph: G) -> Self {
let inputs = graph
.nodes_iter()
.filter(|&n| graph.input_neighbours(n).count() == 0);
let topsort: TopoSort<_> = toposort(graph, inputs, Direction::Outgoing);
let topsort: TopoSort<_> = toposort(graph.clone(), inputs, Direction::Outgoing);
let topsort_nodes: Vec<_> = topsort.collect();
let mut topsort_ind = UnmanagedDenseMap::with_capacity(graph.node_count());
for (i, &n) in topsort_nodes.iter().enumerate() {
Expand All @@ -51,7 +51,7 @@ where

/// The graph on which convexity queries can be made.
pub fn graph(&self) -> G {
self.graph
self.graph.clone()
}

/// Whether the subgraph induced by the node set is convex.
Expand Down
6 changes: 3 additions & 3 deletions src/view/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ pub type LinkFilter<Ctx> = fn(PortIndex, &Ctx) -> bool;
/// Both nodes and links can be filtered by providing the filter functions
/// `node_filter` and `link_filter`.
///
/// As ports always occopy a contiguous interval of indices, they cannot be
/// As ports always occupy a contiguous interval of indices, they cannot be
/// filtered out directly. Instead, when `link_filter` filters out a port it
/// appears as disconnected, effectively remove the link between ports. A link
/// is removed whenever either of its ports is filtered out.
///
/// For the special case of filtering out nodes only, the type alias
/// [`NodeFiltered`] is provided, along with [`NodeFiltered::new_node_filtered`].
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct FilteredGraph<'a, G, FN, FP, Context = ()> {
graph: &'a G,
node_filter: FN,
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<G, Ctx> FilteredGraph<'_, G, NodeFilter<Ctx>, LinkFilter<Ctx>, Ctx> {
/// Context used internally for the [`FilteredGraph`] iterators.
///
/// This is a named struct to make the iterator signatures more readable.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FilteredGraphCtx<'a, G, Ctx> {
pub(self) graph: &'a G,
pub(self) node_filter: NodeFilter<Ctx>,
Expand Down