import networkx as nx
G = nx.DiGraph()
G.add_edge("A: test", 'B: test')
nx.write_dot(G,'so.dot')
Run Code Online (Sandbox Code Playgroud)
产生
这是由于结肠.
so.dot
:
strict digraph G {
A;
B;
"A: test" -> "B: test";
}
Run Code Online (Sandbox Code Playgroud)
请注意,它会剥离冒号及其后面的所有内容.
如果我手动将其更改为
strict digraph G {
"A: test";
"B: test";
"A: test" -> "B: test";
}
Run Code Online (Sandbox Code Playgroud)
没关系.事实上,只要存在边缘,是否存在节点并不重要.
如果删除之间的空间:
和t
,仅A和B被生成.
我试过以各种方式逃避冒号,但这似乎不起作用.显然,我每次都可以手动删除节点,但脚本解决方案更可取.(而不是通过.dot文件的第二个脚本)
有人有想法吗?
我正在尝试实现列表拉链.到目前为止,我有:
#[derive(RustcDecodable, RustcEncodable, Debug, Clone)]
pub struct ListZipper {
pub focus: Option<Tile>,
pub left: VecDeque<Tile>,
pub right: VecDeque<Tile>,
}
impl PartialEq for ListZipper {
fn eq(&self, other: &ListZipper) -> bool {
self.left == other.left && self.focus == other.focus && self.right == other.right
}
}
Run Code Online (Sandbox Code Playgroud)
我现在正在尝试实现一个迭代器
impl Iterator for ListZipper {
type Item = Tile;
fn next(&mut self) -> Option<Tile> {
self.left.iter().chain(self.focus.iter()).chain(self.right.iter()).next().map(|w| *w)
}
}
Run Code Online (Sandbox Code Playgroud)
在我看来,这是有道理的.迭代时ListZipper
,我想迭代left
,focus
然后right
.所以我链接那些迭代器,然后返回next()
.
如果所有字段ListZipper
都为空,则此方法正常.只要一个不为空,迭代 …