Comparing version 1.11.0 to 1.12.0
39
index.js
@@ -51,2 +51,41 @@ exports.fullRoots = function (index, result) { | ||
exports.patch = function (from, to) { | ||
if (from === 0 || from >= to) return [] | ||
const roots = exports.fullRoots(from) | ||
const target = exports.fullRoots(to) | ||
// first find the first root that is different | ||
let i = 0 | ||
for (; i < target.length; i++) { | ||
if (i >= roots.length || roots[i] !== target[i]) break | ||
} | ||
// now we need to grow the newest root until it hits the diff one | ||
let prev = roots.length - 1 | ||
const ite = exports.iterator(roots[prev--]) | ||
const patch = [] | ||
while (ite.index !== target[i]) { | ||
ite.sibling() | ||
if (prev >= 0 && ite.index === roots[prev]) { | ||
prev-- | ||
} else { | ||
patch.push(ite.index) | ||
} | ||
patch.push(ite.parent()) | ||
} | ||
// include the rest | ||
for (i++; i < target.length; i++) patch.push(target[i]) | ||
return patch | ||
} | ||
exports.depth = function (index) { | ||
@@ -53,0 +92,0 @@ let depth = 0 |
{ | ||
"name": "flat-tree", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "A series of functions to map a binary tree to a list", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13432
266