MCPcopy Index your code
hub / github.com/plotly/plotly.js / connectedComponents_sparse

Function connectedComponents_sparse

stackgl_modules/index.js:36054–36081  ·  view source on GitHub ↗
(cells)

Source from the content-addressed store, hash-verified

36052
36053//Computes connected components for a sparse graph
36054function connectedComponents_sparse(cells) {
36055 var vertices = unique(normalize(skeleton(cells, 0)))
36056 , labels = new UnionFind(vertices.length)
36057 for(var i=0; i<cells.length; ++i) {
36058 var c = cells[i]
36059 for(var j=0; j<c.length; ++j) {
36060 var vj = findCell(vertices, [c[j]])
36061 for(var k=j+1; k<c.length; ++k) {
36062 labels.link(vj, findCell(vertices, [c[k]]))
36063 }
36064 }
36065 }
36066 var components = []
36067 , component_labels = labels.ranks
36068 for(var i=0; i<component_labels.length; ++i) {
36069 component_labels[i] = -1
36070 }
36071 for(var i=0; i<cells.length; ++i) {
36072 var l = labels.find(findCell(vertices, [cells[i][0]]));
36073 if(component_labels[l] < 0) {
36074 component_labels[l] = components.length
36075 components.push([cells[i].slice(0)])
36076 } else {
36077 components[component_labels[l]].push(cells[i].slice(0))
36078 }
36079 }
36080 return components
36081}
36082
36083//Computes connected components for a cell complex
36084function connectedComponents(cells, vertex_count) {

Callers 1

connectedComponentsFunction · 0.85

Calls 4

uniqueFunction · 0.85
normalizeFunction · 0.85
skeletonFunction · 0.85
findCellFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…