Skip to content

Commit 955d989

Browse files
kevinhartmanmtreinishmergify[bot]
authored
Add graph module, port contract_nodes and has_parallel_edges to core. (#1143)
* Port contract_nodes to core. * Explicit implementations for just StableGraph and GraphMap. * Simplify to just graph_ext. * Rename integration tests to graph_ext. * Add module docs for graph_ext. * Avoid 'static requirement for GraphMap extensions. * Improve docs. * Remove dead code. * Add release note. * Update releasenotes/notes/graph-ext-3f008015c31c592e.yaml --------- Co-authored-by: Matthew Treinish <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent c039731 commit 955d989

File tree

11 files changed

+1428
-183
lines changed

11 files changed

+1428
-183
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
features:
3+
- |
4+
Node contraction is now supported for ``petgraph`` types ``StableGraph``
5+
and ``GraphMap`` in rustworkx-core. To use it, import one of the ``ContractNodes*`` traits
6+
from ``graph_ext`` and call the ``contract_nodes`` method on your graph.
7+
- |
8+
All current ``petgraph`` data structures now support testing for parallel
9+
edges in ``rustworkx-core``. To use this, import ``HasParallelEdgesDirected``
10+
or ``HasParallelEdgesUndirected`` depending on your graph type, and call
11+
the ``has_parallel_edges`` method on your graph.
12+
- |
13+
A new trait ``NodeRemovable`` has been added to ``graph_ext`` module in
14+
``rustworkx-core`` which provides a consistent interface for performing
15+
node removal operations on ``petgraph`` types ``Graph``, ``StableGraph``,
16+
``GraphMap``, and ``MatrixGraph``. To use it, import ``NodeRemovable`` from
17+
``graph_ext``.

rustworkx-core/src/err.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
// not use this file except in compliance with the License. You may obtain
3+
// a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
// License for the specific language governing permissions and limitations
11+
// under the License.
12+
13+
//! This module contains common error types and trait impls.
14+
15+
use std::error::Error;
16+
use std::fmt::{Debug, Display, Formatter};
17+
18+
#[derive(Debug)]
19+
pub enum ContractError {
20+
DAGWouldCycle,
21+
}
22+
23+
impl Display for ContractError {
24+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
25+
match self {
26+
ContractError::DAGWouldCycle => fmt_dag_would_cycle(f),
27+
}
28+
}
29+
}
30+
31+
impl Error for ContractError {}
32+
33+
#[derive(Debug)]
34+
pub enum ContractSimpleError<E: Error> {
35+
DAGWouldCycle,
36+
MergeError(E),
37+
}
38+
39+
impl<E: Error> Display for ContractSimpleError<E> {
40+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
41+
match self {
42+
ContractSimpleError::DAGWouldCycle => fmt_dag_would_cycle(f),
43+
ContractSimpleError::MergeError(ref e) => fmt_merge_error(f, e),
44+
}
45+
}
46+
}
47+
48+
impl<E: Error> Error for ContractSimpleError<E> {}
49+
50+
fn fmt_dag_would_cycle(f: &mut Formatter<'_>) -> std::fmt::Result {
51+
write!(f, "The operation would introduce a cycle.")
52+
}
53+
54+
fn fmt_merge_error<E: Error>(f: &mut Formatter<'_>, inner: &E) -> std::fmt::Result {
55+
write!(f, "The prov failed with: {:?}", inner)
56+
}

0 commit comments

Comments
 (0)