MCPcopy
hub / github.com/josdejong/mathjs / csLeaf

Function csLeaf

src/function/algebra/sparse/csLeaf.js:19–51  ·  view source on GitHub ↗
(i, j, w, first, maxfirst, prevleaf, ancestor)

Source from the content-addressed store, hash-verified

17 * @return {Object}
18 */
19export function csLeaf (i, j, w, first, maxfirst, prevleaf, ancestor) {
20 let s, sparent
21
22 // our result
23 let jleaf = 0
24 let q
25
26 // check j is a leaf
27 if (i <= j || w[first + j] <= w[maxfirst + i]) { return (-1) }
28 // update max first[j] seen so far
29 w[maxfirst + i] = w[first + j]
30 // jprev = previous leaf of ith subtree
31 const jprev = w[prevleaf + i]
32 w[prevleaf + i] = j
33
34 // check j is first or subsequent leaf
35 if (jprev === -1) {
36 // 1st leaf, q = root of ith subtree
37 jleaf = 1
38 q = i
39 } else {
40 // update jleaf
41 jleaf = 2
42 // q = least common ancester (jprev,j)
43 for (q = jprev; q !== w[ancestor + q]; q = w[ancestor + q]);
44 for (s = jprev; s !== q; s = sparent) {
45 // path compression
46 sparent = w[ancestor + s]
47 w[ancestor + s] = q
48 }
49 }
50 return { jleaf, q }
51}

Callers 1

csCounts.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…