// https://github.com/mikolalysenko/union-find UnionFind = (function() { "use strict"; "use restrict"; function UnionFind(count) { this.roots = new Array(count); this.ranks = new Array(count); for(var i=0; i { if (l.source.index > n) n = l.source.index; if (l.target.index > n) n = l.target.index; }) const uf = new UnionFind(n); // 4 trier les arêtes de G par poids croissant graph = graph.map(l => { l.w = l.length || dist(l.source, l.target); return l; }) graph.sort((a,b) => d3.ascending(a.w, b.w)) // 5 pour chaque arête (u, v) de G prise par poids croissant : .forEach(l => { // 6 si find(u) ≠ find(v) : if (uf.find(l.source.index) != uf.find(l.target.index)) { // 7 ajouter l'arête (u, v) à l'ensemble A A.push(l); // 8 union(u, v) uf.link(l.source.index, l.target.index); } }); // 9 retourner A return A; // yield uf; }