#[macro_export]
macro_rules! ungraph_node {
( $key:expr ) => {{
use gdsl::ungraph::*;
Node::new($key, ())
}};
( $key:expr, $param:expr ) => {{
use gdsl::ungraph::*;
Node::new($key, $param)
}};
}
#[macro_export]
macro_rules! ungraph_connect {
( $s:expr => $t:expr ) => {{
use gdsl::ungraph::*;
Node::connect($s, $t, ())
}};
( $s:expr => $t:expr, $params:expr ) => {{
use gdsl::ungraph::*;
Node::connect($s, $t, $params)
}};
}
#[macro_export]
macro_rules! ungraph {
()
=> {
{
use gdsl::ungraph::Graph;
Graph::<usize, (), ()>::new()
}
};
( ($K:ty) $(($NODE:expr) => $( [ $( $EDGE:expr),*] )? )* )
=> {
{
use gdsl::ungraph::*;
use gdsl::*;
let mut edges = Vec::<($K, $K)>::new();
edges.clear();
let mut g = Graph::<$K, (), ()>::new();
$(
$(
$(
edges.push(($NODE, $EDGE));
)*
)?
let n = ungraph_node!($NODE);
g.insert(n);
)*
for (s, t) in edges {
if !g.contains(&s) || !g.contains(&t) {
if !g.contains(&s) {
panic!("Check your macro invocation: \"{}\" is not in the graph", s);
} else {
panic!("Check your macro invocation: \"{}\" is not in the graph", t);
}
}
let s = g.get(&s).unwrap();
let t = g.get(&t).unwrap();
ungraph_connect!(&s => &t);
}
g
}
};
( ($K:ty, $N:ty) $(($NODE:expr, $NPARAM:expr) => $( [$( $EDGE:expr) ,*] )? )* )
=> {
{
use gdsl::ungraph::*;
use gdsl::*;
let mut edges = Vec::<($K, $K)>::new();
edges.clear();
let mut g = Graph::<$K, $N, ()>::new();
$(
$(
$(
edges.push(($NODE, $EDGE));
)*
)?
let n = ungraph_node!($NODE, $NPARAM);
g.insert(n);
)*
for (s, t) in edges {
if !g.contains(&s) || !g.contains(&t) {
if !g.contains(&s) {
panic!("Check your macro invocation: \"{}\" is not in the graph", s);
} else {
panic!("Check your macro invocation: \"{}\" is not in the graph", t);
}
}
let s = g.get(&s).unwrap();
let t = g.get(&t).unwrap();
ungraph_connect!(&s => &t);
}
g
}
};
( ($K:ty) => [$E:ty] $(($NODE:expr) => $( [$( ( $EDGE:expr, $EPARAM:expr) ),*] )? )* )
=> {
{
use gdsl::ungraph::*;
use gdsl::*;
let mut edges = Vec::<($K, $K, $E)>::new();
edges.clear();
let mut g = Graph::<$K, (), $E>::new();
$(
$(
$(
edges.push(($NODE, $EDGE, $EPARAM));
)*
)?
let n = ungraph_node!($NODE);
g.insert(n);
)*
for (s, t, param) in edges {
if !g.contains(&s) || !g.contains(&t) {
if !g.contains(&s) {
panic!("Check your macro invocation: \"{}\" is not in the graph", s);
} else {
panic!("Check your macro invocation: \"{}\" is not in the graph", t);
}
}
let s = g.get(&s).unwrap();
let t = g.get(&t).unwrap();
ungraph_connect!(&s => &t, param);
}
g
}
};
( ($K:ty, $N:ty) => [$E:ty] $(($NODE:expr, $NPARAM:expr) => $( [$( ( $EDGE:expr, $EPARAM:expr) ),*] )? )* )
=> {
{
use gdsl::ungraph::*;
use gdsl::*;
let mut edges = Vec::<($K, $K, $E)>::new();
edges.clear();
let mut g = Graph::<$K, $N, $E>::new();
$(
$(
$(
edges.push(($NODE, $EDGE, $EPARAM));
)*
)?
let n = ungraph_node!($NODE, $NPARAM);
g.insert(n);
)*
for (s, t, param) in edges {
if !g.contains(&s) || !g.contains(&t) {
if !g.contains(&s) {
panic!("Check your macro invocation: \"{}\" is not in the graph", s);
} else {
panic!("Check your macro invocation: \"{}\" is not in the graph", t);
}
}
let s = g.get(&s).unwrap();
let t = g.get(&t).unwrap();
ungraph_connect!(&s => &t, param);
}
g
}
};
}