Skip to content

Commit 9cd3358

Browse files
committed
Use cargo feature "unstable" for StableGraph; ironically enough.
1 parent 6541dda commit 9cd3358

File tree

8 files changed

+30
-7
lines changed

8 files changed

+30
-7
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ rand = "0.3"
3333
[features]
3434

3535
test = []
36+
# For unstable features
37+
unstable = []

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ DOCCRATES = petgraph fixedbitset
33
# deps to delete the generated docs
44
RMDOCS =
55

6-
FEATURES =
6+
FEATURES = unstable
77

88
VERSIONS = $(patsubst %,target/VERS/%,$(DOCCRATES))
99

src/generate.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Graph generation. ***Unstable.***
2+
//!
3+
//! `feature = "unstable"`
4+
//!
15
26
use {Graph, Directed, EdgeType};
37
use graph::NodeIndex;
@@ -13,6 +17,8 @@ use graph::NodeIndex;
1317
// For a graph of n=3 nodes we have (n - 1) * n / 2 = 3 possible edges.
1418

1519
/// A graph generator of “all” graphs of a particular size.
20+
///
21+
/// ***Unstable: API may change at any time.*** Depends on `feature = "unstable"`.
1622
pub struct Generator<Ty> {
1723
acyclic: bool,
1824
selfloops: bool,

src/graph.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<Ix: IndexType = DefIndex> NodeIndex<Ix>
9090
NodeIndex(IndexType::max())
9191
}
9292

93-
fn into_edge(self) -> EdgeIndex<Ix> {
93+
fn _into_edge(self) -> EdgeIndex<Ix> {
9494
EdgeIndex(self.0)
9595
}
9696
}
@@ -129,7 +129,7 @@ impl<Ix: IndexType = DefIndex> EdgeIndex<Ix>
129129
EdgeIndex(IndexType::max())
130130
}
131131

132-
fn into_node(self) -> NodeIndex<Ix> {
132+
fn _into_node(self) -> NodeIndex<Ix> {
133133
NodeIndex(self.0)
134134
}
135135
}
@@ -1610,6 +1610,7 @@ impl<Ix: IndexType> DoubleEndedIterator for EdgeIndices<Ix> {
16101610
}
16111611
}
16121612

1613+
#[cfg(feature = "unstable")]
16131614
#[path = "stable.rs"]
16141615
pub mod stable;
16151616

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub use EdgeDirection::{Outgoing, Incoming};
2424

2525
mod scored;
2626
pub mod algo;
27-
#[doc(hidden)] // Not for public consumption -- only for testing
27+
#[cfg(feature = "unstable")]
2828
pub mod generate;
2929
pub mod graphmap;
3030
pub mod graph;

src/stable.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//! `StableGraph` keeps indices stable across removals.
1+
//! `StableGraph` keeps indices stable across removals. ***Unstable.***
2+
//!
3+
//! `feature = "unstable"`
24
35
use std::fmt;
46
use std::mem::replace;
@@ -25,6 +27,8 @@ use super::{
2527
/// `StableGraph<N, E, Ty, Ix>` is a graph datastructure using an adjacency
2628
/// list representation.
2729
///
30+
/// ***Unstable: API may change at any time.*** Depends on `feature = "unstable"`.
31+
///
2832
/// The graph **does not invalidate** any unrelated node or edge indices when
2933
/// items are removed.
3034
///
@@ -133,7 +137,7 @@ impl<N, E, Ty=Directed, Ix=DefIndex> StableGraph<N, E, Ty, Ix>
133137
let node_slot = &mut self.g.nodes[node_idx.index()];
134138
let _old = replace(&mut node_slot.weight, Some(weight));
135139
debug_assert!(_old.is_none());
136-
self.free_node = node_slot.next[0].into_node();
140+
self.free_node = node_slot.next[0]._into_node();
137141
node_slot.next[0] = EdgeIndex::end();
138142
node_idx
139143
} else {
@@ -180,7 +184,7 @@ impl<N, E, Ty=Directed, Ix=DefIndex> StableGraph<N, E, Ty, Ix>
180184
let node_slot = &mut self.g.nodes[a.index()];
181185
//let node_weight = replace(&mut self.g.nodes[a.index()].weight, Entry::Empty(self.free_node));
182186
//self.g.nodes[a.index()].next = [EdgeIndex::end(), EdgeIndex::end()];
183-
node_slot.next = [self.free_node.into_edge(), EdgeIndex::end()];
187+
node_slot.next = [self.free_node._into_edge(), EdgeIndex::end()];
184188
self.free_node = a;
185189
self.node_count -= 1;
186190

src/visit.rs

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use super::{
2222
use graph::{
2323
IndexType,
2424
};
25+
#[cfg(feature = "unstable")]
2526
use graph::stable::StableGraph;
2627

2728
/// Base trait for graphs that defines the node identifier.
@@ -48,6 +49,7 @@ impl<'a, N, E: 'a, Ty, Ix> NeighborIter<'a> for Graph<N, E, Ty, Ix> where
4849
}
4950
}
5051

52+
#[cfg(feature = "unstable")]
5153
impl<'a, N, E: 'a, Ty, Ix> NeighborIter<'a> for StableGraph<N, E, Ty, Ix> where
5254
Ty: EdgeType,
5355
Ix: IndexType,
@@ -121,6 +123,7 @@ impl<'a, N, E: 'a, Ty, Ix> NeighborsDirected<'a> for Graph<N, E, Ty, Ix>
121123
}
122124
}
123125

126+
#[cfg(feature = "unstable")]
124127
impl<'a, N, E: 'a, Ty, Ix> NeighborsDirected<'a> for StableGraph<N, E, Ty, Ix>
125128
where Ty: EdgeType,
126129
Ix: IndexType,
@@ -249,12 +252,14 @@ impl<N, E, Ty, Ix> Revisitable for Graph<N, E, Ty, Ix>
249252
}
250253
}
251254

255+
#[cfg(feature = "unstable")]
252256
impl<N, E, Ty, Ix> Graphlike for StableGraph<N, E, Ty, Ix> where
253257
Ix: IndexType,
254258
{
255259
type NodeId = graph::NodeIndex<Ix>;
256260
}
257261

262+
#[cfg(feature = "unstable")]
258263
impl<N, E, Ty, Ix> Visitable for StableGraph<N, E, Ty, Ix> where
259264
Ty: EdgeType,
260265
Ix: IndexType,
@@ -263,6 +268,7 @@ impl<N, E, Ty, Ix> Visitable for StableGraph<N, E, Ty, Ix> where
263268
fn visit_map(&self) -> FixedBitSet { FixedBitSet::with_capacity(self.node_count()) }
264269
}
265270

271+
#[cfg(feature = "unstable")]
266272
impl<N, E, Ty, Ix> Revisitable for StableGraph<N, E, Ty, Ix>
267273
where Ty: EdgeType,
268274
Ix: IndexType,

tests/ograph.rs

+4
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ fn dijk() {
339339
assert_eq!(scores[&c], 9);
340340
}
341341

342+
#[cfg(feature = "unstable")]
342343
#[test]
343344
fn test_generate_undirected() {
344345
for size in 0..4 {
@@ -354,6 +355,7 @@ fn test_generate_undirected() {
354355
}
355356
}
356357

358+
#[cfg(feature = "unstable")]
357359
#[test]
358360
fn test_generate_directed() {
359361
// Number of DAG out of all graphs (all permutations) per node size
@@ -381,6 +383,8 @@ fn test_generate_directed() {
381383
assert_eq!(n, 1 << nedges);
382384
}
383385
}
386+
387+
#[cfg(feature = "unstable")]
384388
#[test]
385389
fn test_generate_dag() {
386390
for size in 1..5 {

0 commit comments

Comments
 (0)