Skip to content

Commit a63d0c5

Browse files
authored
Merge pull request #42 from mitchmindtree/maintenance/prepare-0-8-1
2 parents deb7624 + 0574d37 commit a63d0c5

File tree

10 files changed

+210
-76
lines changed

10 files changed

+210
-76
lines changed

.github/workflows/daggy.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,32 @@ jobs:
1515
- uses: actions/checkout@v4
1616
- uses: dtolnay/rust-toolchain@master
1717
with:
18-
toolchain: stable
18+
toolchain: nightly
1919
components: rustfmt
2020
- name: Run rustfmt
21-
uses: actions-rs/cargo@v1
22-
with:
23-
command: fmt
24-
args: --all -- --check
21+
run: cargo fmt --all -- --check
22+
23+
clippy:
24+
name: Clippy
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 10
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: dtolnay/rust-toolchain@master
30+
with:
31+
toolchain: nightly
32+
components: clippy
33+
34+
- name: 'Run clippy'
35+
run: cargo clippy --all-features -- -D warnings
2536

2637
cargo-test:
2738
runs-on: ubuntu-latest
2839
steps:
2940
- uses: actions/checkout@v4
3041
- uses: dtolnay/rust-toolchain@stable
3142
- name: cargo test
32-
uses: actions-rs/cargo@v1
33-
with:
34-
command: test
35-
args: --verbose
43+
run: cargo test --verbose
3644

3745
cargo-test-all-features:
3846
runs-on: ubuntu-latest

CHANGELOG.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44

55
* Add `Dag::transitive_reduce` ([#36][#36], [#41][#41]).
66
* Add `Dag::{reserve_*, shrink_*}` functions ([#38][#38]).
7-
- `reserve_nodes`
8-
- `reserve_exact_nodes`
9-
- `reserve_edges`
10-
- `reserve_exact_edges`
11-
- `shrink_to_fit`
12-
- `shrink_to_fit_nodes`
13-
- `shrink_to_fit_edges`
7+
* Add `Dag::transitive_reduce` ([#36][#36], [#41][#41]).
8+
* Add `Dag::{reserve_*, shrink_*}` functions ([#38][#38]).
9+
* Update `petgraph` to `0.7` ([#40][#40])
1410

1511
[#36]: https://github.com/mitchmindtree/daggy/pull/36
1612
[#38]: https://github.com/mitchmindtree/daggy/pull/38
13+
[#40]: https://github.com/mitchmindtree/daggy/pull/40
1714
[#41]: https://github.com/mitchmindtree/daggy/pull/41

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "daggy"
3-
version = "0.8.0"
3+
version = "0.8.1"
44
authors = ["mitchmindtree <mitchell.nordine@gmail.com>"]
55
description = "A directed acyclic graph data structure library. It is Implemented on top of petgraph's Graph data structure and attempts to follow similar conventions where suitable."
66
readme = "README.md"

README.md

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,77 @@
33

44
A [directed acyclic graph](https://en.wikipedia.org/wiki/Directed_acyclic_graph) data structure for Rust.
55

6-
It is Implemented on top of [petgraph](https://github.com/petgraph/petgraph)'s [Graph](https://docs.rs/petgraph/latest/petgraph/graph/struct.Graph.html) data structure and attempts to follow similar conventions where suitable.
6+
It is implemented on top of [petgraph](https://github.com/petgraph/petgraph)'s [Graph](https://docs.rs/petgraph/latest/petgraph/graph/struct.Graph.html) data structure and attempts to follow similar conventions where suitable.
77

88

9-
Usage
10-
-----
9+
## Usage
1110

12-
Please see the [tests directory](https://github.com/mitchmindtree/daggy/tree/master/tests) for some basic usage examples.
13-
14-
Use daggy in your project by adding it to your Cargo.toml dependencies like so:
11+
Use daggy in your project by adding it to your `Cargo.toml` dependencies:
1512

1613
```toml
1714
[dependencies]
18-
daggy = "*"
15+
daggy = "0.8.1"
16+
17+
# Enables the `StableDag` type.
18+
daggy = { version = "0.8.1", features = ["stable_dag"] }
19+
20+
# Allows the `Dag` to be serialized and deserialized.
21+
daggy = { version = "0.8.1", features = ["serde-1"] }
1922
```
2023

24+
## Examples
25+
26+
> Please see the [tests directory](https://github.com/mitchmindtree/daggy/tree/master/tests) for some basic usage examples.
27+
28+
Transitive reduction:
29+
30+
```rust
31+
use daggy::Dag;
32+
33+
let mut dag = Dag::<&str, &str>::new();
34+
35+
// Reduce edges:
36+
//
37+
// ```text
38+
// # Before: | # After:
39+
// |
40+
// a -> b ----. | a -> b ----.
41+
// | | | | |
42+
// |-> c ----|----. | '-> c |
43+
// | \ | | | \ |
44+
// | \ v | | \ v
45+
// |------>> d | | '> d
46+
// | \ v | \
47+
// '----------->> e | '> e
48+
// ```
49+
50+
let a = dag.add_node("a");
51+
52+
let (_, b) = dag.add_child(a, "a->b", "b");
53+
let (_, c) = dag.add_child(a, "a->c", "c");
54+
let (_, d) = dag.add_child(a, "a->d", "d");
55+
let (_, e) = dag.add_child(a, "a->e", "e");
2156

22-
License
23-
-------
57+
dag.add_edge(b, d, "b->d").unwrap();
58+
59+
dag.add_edge(c, d, "c->d").unwrap();
60+
dag.add_edge(c, e, "c->e").unwrap();
61+
62+
dag.add_edge(d, e, "d->e").unwrap();
63+
64+
assert_eq!(dag.edge_count(), 8);
65+
66+
dag.transitive_reduce(vec![a]);
67+
68+
let mut edges = dag.graph().edge_weights().copied().collect::<Vec<_>>();
69+
edges.sort();
70+
assert_eq!(dag.edge_count(), 5);
71+
assert_eq!(&edges, &["a->b", "a->c", "b->d", "c->d", "d->e"]);
72+
```
73+
74+
75+
## License
2476

2577
Dual-licensed to be compatible with the petgraph and Rust projects.
2678

2779
Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.
28-

src/lib.rs

Lines changed: 79 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,77 @@
88
//! methods behave similarly to iterator types, however **Walker**s do not require borrowing the
99
//! graph. This means that we can still safely mutably borrow from the graph whilst we traverse it.
1010
//!
11-
//!
1211
//! [1]: Dag
1312
//! [2]: petgraph
1413
//! [3]: petgraph::graph::Graph
14+
//!
15+
//!
16+
//! ## Usage
17+
//!
18+
//! Use daggy in your project by adding it to your `Cargo.toml` dependencies:
19+
//!
20+
//! ```toml
21+
//! [dependencies]
22+
//! daggy = "0.8.1"
23+
//!
24+
//! # Enables the `StableDag` type.
25+
//! daggy = { version = "0.8.1", features = ["stable_dag"] }
26+
//!
27+
//! # Allows the `Dag` to be serialized and deserialized.
28+
//! daggy = { version = "0.8.1", features = ["serde-1"] }
29+
//! ```
30+
//!
31+
//! # Examples
32+
//!
33+
//! > Please see the [tests directory][4] for some basic usage examples.
34+
//!
35+
//! Transitive reduction:
36+
//!
37+
//! ```rust
38+
//! use daggy::Dag;
39+
//!
40+
//! let mut dag = Dag::<&str, &str>::new();
41+
//!
42+
//! // Reduce edges:
43+
//! //
44+
//! // ```text
45+
//! // # Before: | # After:
46+
//! // |
47+
//! // a -> b ----. | a -> b ----.
48+
//! // | | | | |
49+
//! // |-> c ----|----. | '-> c |
50+
//! // | \ | | | \ |
51+
//! // | \ v | | \ v
52+
//! // |------>> d | | '> d
53+
//! // | \ v | \
54+
//! // '----------->> e | '> e
55+
//! // ```
56+
//!
57+
//! let a = dag.add_node("a");
58+
//!
59+
//! let (_, b) = dag.add_child(a, "a->b", "b");
60+
//! let (_, c) = dag.add_child(a, "a->c", "c");
61+
//! let (_, d) = dag.add_child(a, "a->d", "d");
62+
//! let (_, e) = dag.add_child(a, "a->e", "e");
63+
//!
64+
//! dag.add_edge(b, d, "b->d").unwrap();
65+
//!
66+
//! dag.add_edge(c, d, "c->d").unwrap();
67+
//! dag.add_edge(c, e, "c->e").unwrap();
68+
//!
69+
//! dag.add_edge(d, e, "d->e").unwrap();
70+
//!
71+
//! assert_eq!(dag.edge_count(), 8);
72+
//!
73+
//! dag.transitive_reduce(vec![a]);
74+
//!
75+
//! let mut edges = dag.graph().edge_weights().copied().collect::<Vec<_>>();
76+
//! edges.sort();
77+
//! assert_eq!(dag.edge_count(), 5);
78+
//! assert_eq!(&edges, &["a->b", "a->c", "b->d", "c->d", "d->e"]);
79+
//! ```
80+
//!
81+
//! [4]: https://github.com/mitchmindtree/daggy/tree/master/tests
1582
1683
#![forbid(unsafe_code)]
1784
#![warn(missing_docs)]
@@ -211,10 +278,7 @@ where
211278
{
212279
let graph = self.graph.map(node_map, edge_map);
213280
let cycle_state = self.cycle_state.clone();
214-
Dag {
215-
graph: graph,
216-
cycle_state: cycle_state,
217-
}
281+
Dag { graph, cycle_state }
218282
}
219283

220284
/// Create a new `Dag` by mapping node and edge weights. A node or edge may be mapped to `None`
@@ -237,10 +301,7 @@ where
237301
{
238302
let graph = self.graph.filter_map(node_map, edge_map);
239303
let cycle_state = DfsSpace::new(&graph);
240-
Dag {
241-
graph: graph,
242-
cycle_state: cycle_state,
243-
}
304+
Dag { graph, cycle_state }
244305
}
245306

246307
/// Removes all nodes and edges from the **Dag**.
@@ -434,10 +495,8 @@ where
434495

435496
for (a, b, weight) in edges {
436497
// Check whether or not we'll need to check for cycles.
437-
if !should_check_for_cycle {
438-
if must_check_for_cycle(self, a, b) {
439-
should_check_for_cycle = true;
440-
}
498+
if !should_check_for_cycle && must_check_for_cycle(self, a, b) {
499+
should_check_for_cycle = true;
441500
}
442501

443502
self.graph.add_edge(a, b, weight);
@@ -614,6 +673,7 @@ where
614673
/// Both indices can be either `NodeIndex`s, `EdgeIndex`s or a combination of the two.
615674
///
616675
/// **Panics** if the indices are equal or if they are out of bounds.
676+
#[allow(clippy::type_complexity)]
617677
pub fn index_twice_mut<A, B>(
618678
&mut self,
619679
a: A,
@@ -657,7 +717,7 @@ where
657717
pub fn parents(&self, child: NodeIndex<Ix>) -> Parents<N, E, Ix> {
658718
let walk_edges = self.graph.neighbors_directed(child, pg::Incoming).detach();
659719
Parents {
660-
walk_edges: walk_edges,
720+
walk_edges,
661721
_node: PhantomData,
662722
_edge: PhantomData,
663723
}
@@ -675,7 +735,7 @@ where
675735
pub fn children(&self, parent: NodeIndex<Ix>) -> Children<N, E, Ix> {
676736
let walk_edges = self.graph.neighbors_directed(parent, pg::Outgoing).detach();
677737
Children {
678-
walk_edges: walk_edges,
738+
walk_edges,
679739
_node: PhantomData,
680740
_edge: PhantomData,
681741
}
@@ -749,12 +809,12 @@ where
749809

750810
// Dag implementations.
751811

752-
impl<N, E, Ix> Into<DiGraph<N, E, Ix>> for Dag<N, E, Ix>
812+
impl<N, E, Ix> From<Dag<N, E, Ix>> for DiGraph<N, E, Ix>
753813
where
754814
Ix: IndexType,
755815
{
756-
fn into(self) -> DiGraph<N, E, Ix> {
757-
self.into_graph()
816+
fn from(val: Dag<N, E, Ix>) -> Self {
817+
val.into_graph()
758818
}
759819
}
760820

@@ -890,7 +950,7 @@ where
890950
}
891951
}
892952

893-
impl<'a, N, E, Ix> IntoNodeIdentifiers for &'a Dag<N, E, Ix>
953+
impl<N, E, Ix> IntoNodeIdentifiers for &Dag<N, E, Ix>
894954
where
895955
Ix: IndexType,
896956
{

src/serde.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ where
3030
{
3131
let graph = Deserialize::deserialize(deserializer)?;
3232
let cycle_state = DfsSpace::new(&graph);
33-
let dag = Dag {
34-
graph: graph,
35-
cycle_state: cycle_state,
36-
};
33+
let dag = Dag { graph, cycle_state };
3734
Ok(dag)
3835
}
3936
}

0 commit comments

Comments
 (0)