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

NO_STD #370

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 13 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@ jobs:
- rust: 1.37.0
env:
- ALL=' '
- FEATURES='default'
- rust: stable
env:
- FEATURES='unstable quickcheck'
- FEATURES='unstable quickcheck default'
- CHECKFMT=1
- rust: beta
env:
- FEATURES='default'
- rust: nightly
env:
- FEATURES='default'
- rust: nightly
env:
- ALL='--package petgraph'
- FEATURES='no_std'
- rust: nightly
env:
- FEATURES='unstable quickcheck'
- FEATURES='unstable quickcheck default'
- BENCH=1
branches:
only:
Expand All @@ -24,11 +33,8 @@ before_script:
fi
script:
- |
cargo build --verbose --no-default-features &&
cargo test --verbose --no-default-features &&
cargo build --verbose --features "$FEATURES" &&
cargo test ${ALL:---all} --verbose --features "$FEATURES" &&
cargo build --verbose --no-default-features --features "$FEATURES" &&
cargo test ${ALL:---all} --verbose --no-default-features --features "$FEATURES" &&
if [ "${CHECKFMT}" == "1"]; then
cargo +stable fmt -- --check
fi

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ debug = true
[dependencies]
fixedbitset = { version = "0.3.0", default-features = false }
quickcheck = { optional = true, version = "0.8", default-features = false }
indexmap = { version = "1.0.2" }
indexmap = { version = "1.5.1" }
serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }
hashbrown = { version = "0.8.2", features = ["ahash"]}

[dev-dependencies]
rand = "0.5.5"
rand = { version = "0.5.5"}
odds = { version = "0.2.19" }
defmac = "0.1"
itertools = { version = "0.8", default-features = false }

[features]
default = ["graphmap", "stable_graph", "matrix_graph"]
default = [ "std", "graphmap", "stable_graph", "matrix_graph" ]
std = []
graphmap = []
serde-1 = ["serde", "serde_derive"]
stable_graph = []
Expand Down
5 changes: 4 additions & 1 deletion src/algo/dominators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
//! dominates **C** and **C** dominates **B**.

use std::cmp::Ordering;
use std::collections::{HashMap, HashSet, hash_map::Iter};
use std::hash::Hash;

use crate::lib::{HashMap, HashSet, Iter, Vec};
#[cfg(not(feature = "std"))]
use crate::lib::vec;

use crate::visit::{DfsPostOrder, GraphBase, IntoNeighbors, Visitable, Walker};

/// The dominance relation for some graph and root.
Expand Down
7 changes: 5 additions & 2 deletions src/algo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
pub mod dominators;

use std::cmp::min;
use std::collections::{BinaryHeap, HashMap};

use crate::prelude::*;

use crate::lib::{VecDeque, BinaryHeap, HashMap, Vec};
#[cfg(not(feature = "std"))]
use crate::lib::vec;

use super::graph::IndexType;
use super::unionfind::UnionFind;
use super::visit::{
Expand Down Expand Up @@ -846,7 +849,7 @@ where
red.visit(start);
let mut blue = g.visit_map();

let mut stack = ::std::collections::VecDeque::new();
let mut stack = VecDeque::new();
stack.push_front(start);

while let Some(node) = stack.pop_front() {
Expand Down
6 changes: 4 additions & 2 deletions src/astar.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::{BinaryHeap, HashMap};

use std::hash::Hash;

use crate::lib::{Occupied, Vacant, BinaryHeap, HashMap, Vec};
#[cfg(not(feature = "std"))]
use crate::lib::vec;

use super::visit::{EdgeRef, GraphBase, IntoEdges, VisitMap, Visitable};
use crate::scored::MinScored;

Expand Down
35 changes: 28 additions & 7 deletions src/csr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ use std::marker::PhantomData;
use std::ops::{Index, IndexMut, Range};
use std::slice::Windows;


use crate::lib::{Vec};
#[cfg(not(feature = "std"))]
use crate::lib::vec;

use crate::visit::{Data, GraphProp, IntoEdgeReferences, NodeCount};
use crate::visit::{EdgeRef, GraphBase, IntoEdges, IntoNeighbors, NodeIndexable};
use crate::visit::{IntoNodeIdentifiers, NodeCompactIndexable, Visitable};
Expand Down Expand Up @@ -741,10 +746,12 @@ Row : [0, 2, 5] <- value index of row start
mod tests {
use super::Csr;
use crate::algo::bellman_ford;
#[cfg(feature = "std")]
use crate::algo::tarjan_scc;
use crate::visit::Dfs;
use crate::visit::VisitMap;
use crate::Undirected;
use crate::lib::{Vec};

#[test]
fn csr1() {
Expand All @@ -755,6 +762,7 @@ mod tests {
m.add_edge(0, 2, ());
m.add_edge(1, 0, ());
m.add_edge(1, 1, ());
#[cfg(feature = "std")]
println!("{:?}", m);
assert_eq!(&m.column, &[0, 2, 0, 1, 2, 2]);
assert_eq!(&m.row, &[0, 2, 5, 6]);
Expand Down Expand Up @@ -782,6 +790,7 @@ mod tests {
m.add_edge(0, 2, ());
m.add_edge(1, 2, ());
m.add_edge(2, 2, ());
#[cfg(feature = "std")]
println!("{:?}", m);
assert_eq!(&m.column, &[0, 2, 2, 0, 1, 2]);
assert_eq!(&m.row, &[0, 2, 3, 6]);
Expand All @@ -793,22 +802,25 @@ mod tests {
#[test]
fn csr_from_error_1() {
// not sorted in source
let m: Csr = Csr::from_sorted_edges(&[(0, 1), (1, 0), (0, 2)]).unwrap();
println!("{:?}", m);
let _m: Csr = Csr::from_sorted_edges(&[(0, 1), (1, 0), (0, 2)]).unwrap();
#[cfg(feature = "std")]
println!("{:?}", _m);
}

#[should_panic]
#[test]
fn csr_from_error_2() {
// not sorted in target
let m: Csr = Csr::from_sorted_edges(&[(0, 1), (1, 0), (1, 2), (1, 1)]).unwrap();
println!("{:?}", m);
let _m: Csr = Csr::from_sorted_edges(&[(0, 1), (1, 0), (1, 2), (1, 1)]).unwrap();
#[cfg(feature = "std")]
println!("{:?}", _m);
}

#[test]
fn csr_from() {
let m: Csr =
Csr::from_sorted_edges(&[(0, 1), (0, 2), (1, 0), (1, 1), (2, 2), (2, 4)]).unwrap();
#[cfg(feature = "std")]
println!("{:?}", m);
assert_eq!(m.neighbors_slice(0), &[1, 2]);
assert_eq!(m.neighbors_slice(1), &[0, 1]);
Expand All @@ -831,6 +843,7 @@ mod tests {
(4, 5),
])
.unwrap();
#[cfg(feature = "std")]
println!("{:?}", m);
let mut dfs = Dfs::new(&m, 0);
while let Some(_) = dfs.next(&m) {}
Expand All @@ -841,6 +854,7 @@ mod tests {
assert!(!dfs.discovered[5]);

m.add_edge(1, 4, ());
#[cfg(feature = "std")]
println!("{:?}", m);

dfs.reset(&m);
Expand All @@ -854,7 +868,7 @@ mod tests {

#[test]
fn csr_tarjan() {
let m: Csr = Csr::from_sorted_edges(&[
let _m: Csr = Csr::from_sorted_edges(&[
(0, 1),
(0, 2),
(1, 0),
Expand All @@ -867,8 +881,10 @@ mod tests {
(5, 2),
])
.unwrap();
println!("{:?}", m);
println!("{:?}", tarjan_scc(&m));
#[cfg(feature = "std")]
println!("{:?}", _m);
#[cfg(feature = "std")]
println!("{:?}", tarjan_scc(&_m));
}

#[test]
Expand All @@ -887,8 +903,10 @@ mod tests {
(7, 8, 3.),
])
.unwrap();
#[cfg(feature = "std")]
println!("{:?}", m);
let result = bellman_ford(&m, 0).unwrap();
#[cfg(feature = "std")]
println!("{:?}", result);
let answer = [0., 0.5, 1.5, 1.5];
assert_eq!(&answer, &result.0[..4]);
Expand Down Expand Up @@ -932,6 +950,7 @@ mod tests {
let mut copy = Vec::new();
for e in m.edge_references() {
copy.push((e.source(), e.target(), *e.weight()));
#[cfg(feature = "std")]
println!("{:?}", e);
}
let m2: Csr<(), _> = Csr::from_sorted_edges(&copy).unwrap();
Expand All @@ -951,6 +970,7 @@ mod tests {
assert!(g.add_edge(b, c, ()));
assert!(g.add_edge(c, a, ()));

#[cfg(feature = "std")]
println!("{:?}", g);

assert_eq!(g.node_count(), 3);
Expand All @@ -972,6 +992,7 @@ mod tests {

let c = g.add_node(());

#[cfg(feature = "std")]
println!("{:?}", g);

assert_eq!(g.node_count(), 3);
Expand Down
4 changes: 4 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use crate::visit::{Data, NodeCount, NodeIndexable, Reversed};
use crate::EdgeType;
use crate::Graph;


use crate::lib::{Vec};


trait_template! {
/// Access node and edge weights (associated data).
pub trait DataMap : Data {
Expand Down
7 changes: 3 additions & 4 deletions src/dijkstra.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::{BinaryHeap, HashMap};

use std::hash::Hash;

use crate::lib::{Occupied, Vacant, BinaryHeap, HashMap};

use super::visit::{EdgeRef, IntoEdges, VisitMap, Visitable};
use crate::algo::Measure;
use crate::scored::MinScored;
Expand All @@ -25,7 +24,7 @@ use crate::scored::MinScored;
/// use petgraph::Graph;
/// use petgraph::algo::dijkstra;
/// use petgraph::prelude::*;
/// use std::collections::HashMap;
/// use petgraph::lib::HashMap;
///
/// let mut graph : Graph<(),(),Directed>= Graph::new();
/// let a = graph.add_node(()); // node with no weight
Expand Down
6 changes: 6 additions & 0 deletions src/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::visit::{
NodeIndexable, NodeRef,
};

use crate::lib::{String, ToString};

/// `Dot` implements output to graphviz .dot format for a graph.
///
/// Formatting and options are rather simple, this is mostly intended
Expand Down Expand Up @@ -264,6 +266,10 @@ mod test {
use crate::visit::NodeRef;
use std::fmt::Write;

use crate::lib::{String};
#[cfg(not(feature = "std"))]
use crate::lib::format;

#[test]
fn test_escape() {
let mut buff = String::new();
Expand Down
4 changes: 4 additions & 0 deletions src/graph_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use std::mem::size_of;
use std::ops::{Index, IndexMut, Range};
use std::slice;

use crate::lib::{Vec};
#[cfg(not(feature = "std"))]
use crate::lib::vec;

use crate::{Directed, Direction, EdgeType, Incoming, IntoWeightedEdge, Outgoing, Undirected};

use crate::iter_format::{DebugMap, IterFormatExt, NoPretty};
Expand Down
1 change: 1 addition & 0 deletions src/graph_impl/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::de::Error;
use std::marker::PhantomData;

use crate::prelude::*;
use crate::lib::{Vec};

use crate::graph::Node;
use crate::graph::{Edge, IndexType};
Expand Down
14 changes: 14 additions & 0 deletions src/graph_impl/stable_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use std::mem::size_of;
use std::ops::{Index, IndexMut};
use std::slice;

#[cfg(not(feature = "std"))]
use crate::lib::vec;

use crate::{Directed, Direction, EdgeType, Graph, Incoming, Outgoing, Undirected};

use crate::iter_format::{DebugMap, IterFormatExt, NoPretty};
Expand Down Expand Up @@ -1741,23 +1744,30 @@ fn stable_graph() {
let b = gr.add_node(1);
let c = gr.add_node(2);
let _ed = gr.add_edge(a, b, 1);
#[cfg(feature = "std")]
println!("{:?}", gr);
gr.remove_node(b);
#[cfg(feature = "std")]
println!("{:?}", gr);
let d = gr.add_node(3);
#[cfg(feature = "std")]
println!("{:?}", gr);
gr.check_free_lists();
gr.remove_node(a);
gr.check_free_lists();
gr.remove_node(c);
gr.check_free_lists();
#[cfg(feature = "std")]
println!("{:?}", gr);
gr.add_edge(d, d, 2);
#[cfg(feature = "std")]
println!("{:?}", gr);

let e = gr.add_node(4);
gr.add_edge(d, e, 3);
#[cfg(feature = "std")]
println!("{:?}", gr);
#[cfg(feature = "std")]
for neigh in gr.neighbors(d) {
println!("edge {:?} -> {:?}", d, neigh);
}
Expand All @@ -1766,6 +1776,7 @@ fn stable_graph() {

#[test]
fn dfs() {
#[cfg(feature = "std")]
use crate::visit::Dfs;

let mut gr = StableGraph::<_, _>::with_capacity(0, 0);
Expand All @@ -1780,9 +1791,12 @@ fn dfs() {
gr.add_edge(c, d, 5);
gr.add_edge(d, b, 6);
gr.add_edge(c, b, 7);
#[cfg(feature = "std")]
println!("{:?}", gr);

#[cfg(feature = "std")]
let mut dfs = Dfs::new(&gr, a);
#[cfg(feature = "std")]
while let Some(next) = dfs.next(&gr) {
println!("dfs visit => {:?}, weight={:?}", next, &gr[next]);
}
Expand Down
Loading