我试图在D语言中实现图形数据结构,它支持节点和边集的并行迭代.
alias ulong index;
alias index node;
alias ulong count;
class Graph {
index z; // max node index
count n; // number of nodes
count m; // number of edges
node[][] adja; // adjacency list
count[] deg; // node degree
this(count n = 0) {
this.z = n;
this.n = n;
this.m = 0;
this.adja = new node[][](this.z, 0);
this.deg = new count[](this.z);
}
Run Code Online (Sandbox Code Playgroud)
这是一个顺序节点迭代器方法:
/**
* Iterate over all nodes of the graph and call handler (lambda closure). …Run Code Online (Sandbox Code Playgroud)