Comparing version 2.0.13 to 2.0.14
@@ -488,3 +488,11 @@ 'use strict' | ||
const index = elementsCache.get(entry.target) | ||
if (index !== void 0) updates.push(index, height) | ||
const position = itemPositioner.get(index) | ||
if ( | ||
position !== void 0 && | ||
index !== void 0 && | ||
height !== position.height | ||
) { | ||
updates.push(index, height) | ||
} | ||
} | ||
@@ -491,0 +499,0 @@ } |
@@ -1,6 +0,2 @@ | ||
declare enum Color { | ||
Red = 0, | ||
Black = 1, | ||
Nil = 2, | ||
} | ||
declare type Color = 0 | 1 | 2 | ||
interface Interval { | ||
@@ -7,0 +3,0 @@ high: number |
@@ -5,18 +5,9 @@ 'use strict' | ||
exports.default = void 0 | ||
var Color | ||
const RED = 0 | ||
const BLACK = 1 | ||
const NIL = 2 | ||
const DELETE = 0 | ||
const KEEP = 1 | ||
const NOT_FOUND = 2 | ||
;(function(Color) { | ||
Color[(Color['Red'] = 0)] = 'Red' | ||
Color[(Color['Black'] = 1)] = 'Black' | ||
Color[(Color['Nil'] = 2)] = 'Nil' | ||
})(Color || (Color = {})) | ||
var ListResult | ||
;(function(ListResult) { | ||
ListResult[(ListResult['Delete'] = 0)] = 'Delete' | ||
ListResult[(ListResult['Keep'] = 1)] = 'Keep' | ||
ListResult[(ListResult['NotFound'] = 2)] = 'NotFound' | ||
})(ListResult || (ListResult = {})) | ||
const addInterval = (treeNode, high, index) => { | ||
@@ -42,3 +33,3 @@ if (treeNode.list.length === 0) { | ||
const removeInterval = (treeNode, index) => { | ||
if (treeNode.list === void 0) return ListResult.NotFound | ||
if (treeNode.list === void 0) return NOT_FOUND | ||
@@ -51,3 +42,3 @@ for (let i = treeNode.list.length - 1; i > -1; i--) | ||
return treeNode.list.length > 0 ? ListResult.Keep : ListResult.Delete | ||
return treeNode.list.length > 0 ? KEEP : DELETE | ||
} | ||
@@ -59,3 +50,3 @@ | ||
high: 0, | ||
color: Color.Nil, | ||
color: NIL, | ||
// @ts-ignore | ||
@@ -85,3 +76,3 @@ parent: undefined, | ||
while (x.parent != NULL_NODE) { | ||
while (x.parent !== NULL_NODE) { | ||
updateMax(x.parent) | ||
@@ -93,3 +84,3 @@ x = x.parent | ||
const rotateLeft = (tree, x) => { | ||
if (x.right == NULL_NODE) return | ||
if (x.right === NULL_NODE) return | ||
const y = x.right | ||
@@ -111,3 +102,3 @@ x.right = y.left | ||
const rotateRight = (tree, x) => { | ||
if (x.left == NULL_NODE) return | ||
if (x.left === NULL_NODE) return | ||
const y = x.left | ||
@@ -143,9 +134,9 @@ x.left = y.right | ||
while (x !== NULL_NODE && x.color === Color.Black) { | ||
while (x !== NULL_NODE && x.color === BLACK) { | ||
if (x === x.parent.left) { | ||
w = x.parent.right | ||
if (w.color === Color.Red) { | ||
w.color = Color.Black | ||
x.parent.color = Color.Red | ||
if (w.color === RED) { | ||
w.color = BLACK | ||
x.parent.color = RED | ||
rotateLeft(tree, x.parent) | ||
@@ -155,9 +146,9 @@ w = x.parent.right | ||
if (w.left.color === Color.Black && w.right.color === Color.Black) { | ||
w.color = Color.Red | ||
if (w.left.color === BLACK && w.right.color === BLACK) { | ||
w.color = RED | ||
x = x.parent | ||
} else { | ||
if (w.right.color === Color.Black) { | ||
w.left.color = Color.Black | ||
w.color = Color.Red | ||
if (w.right.color === BLACK) { | ||
w.left.color = BLACK | ||
w.color = RED | ||
rotateRight(tree, w) | ||
@@ -168,4 +159,4 @@ w = x.parent.right | ||
w.color = x.parent.color | ||
x.parent.color = Color.Black | ||
w.right.color = Color.Black | ||
x.parent.color = BLACK | ||
w.right.color = BLACK | ||
rotateLeft(tree, x.parent) | ||
@@ -177,5 +168,5 @@ x = tree.root | ||
if (w.color === Color.Red) { | ||
w.color = Color.Black | ||
x.parent.color = Color.Red | ||
if (w.color === RED) { | ||
w.color = BLACK | ||
x.parent.color = RED | ||
rotateRight(tree, x.parent) | ||
@@ -185,9 +176,9 @@ w = x.parent.left | ||
if (w.right.color === Color.Black && w.left.color === Color.Black) { | ||
w.color = Color.Red | ||
if (w.right.color === BLACK && w.left.color === BLACK) { | ||
w.color = RED | ||
x = x.parent | ||
} else { | ||
if (w.left.color === Color.Black) { | ||
w.right.color = Color.Black | ||
w.color = Color.Red | ||
if (w.left.color === BLACK) { | ||
w.right.color = BLACK | ||
w.color = RED | ||
rotateLeft(tree, w) | ||
@@ -198,4 +189,4 @@ w = x.parent.left | ||
w.color = x.parent.color | ||
x.parent.color = Color.Black | ||
w.left.color = Color.Black | ||
x.parent.color = BLACK | ||
w.left.color = BLACK | ||
rotateRight(tree, x.parent) | ||
@@ -207,3 +198,3 @@ x = tree.root | ||
x.color = Color.Black | ||
x.color = BLACK | ||
} | ||
@@ -217,51 +208,2 @@ | ||
const removeNode = (tree, low, index) => { | ||
const z = searchNode(tree.root, low) | ||
if (z === void 0) return | ||
const linkedListResult = removeInterval(z, index) | ||
if (linkedListResult === ListResult.NotFound) return | ||
if (linkedListResult === ListResult.Keep) { | ||
z.high = z.list[0].high | ||
updateMax(z) | ||
updateMaxUp(z) | ||
tree.size-- | ||
return | ||
} | ||
let y = z | ||
let originalYColor = y.color | ||
let x | ||
if (z.left === NULL_NODE) { | ||
x = z.right | ||
rbTransplant(tree, z, z.right) | ||
} else if (z.right === NULL_NODE) { | ||
x = z.left | ||
rbTransplant(tree, z, z.left) | ||
} else { | ||
y = minimumTree(z.right) | ||
originalYColor = y.color | ||
x = y.right | ||
if (y.parent === z) { | ||
x.parent = y | ||
} else { | ||
rbTransplant(tree, y, y.right) | ||
y.right = z.right | ||
y.right.parent = y | ||
} | ||
rbTransplant(tree, z, y) | ||
y.left = z.left | ||
y.left.parent = y | ||
y.color = z.color | ||
} | ||
updateMax(x) | ||
updateMaxUp(x) | ||
if (originalYColor === Color.Black) rbDeleteFixup(tree, x) | ||
tree.size-- | ||
} | ||
const searchNode = (x, low) => { | ||
@@ -279,10 +221,10 @@ while (x !== NULL_NODE && low !== x.low) { | ||
while (z.parent.color === Color.Red) { | ||
while (z.parent.color === RED) { | ||
if (z.parent === z.parent.parent.left) { | ||
y = z.parent.parent.right | ||
if (y.color === Color.Red) { | ||
z.parent.color = Color.Black | ||
y.color = Color.Black | ||
z.parent.parent.color = Color.Red | ||
if (y.color === RED) { | ||
z.parent.color = BLACK | ||
y.color = BLACK | ||
z.parent.parent.color = RED | ||
z = z.parent.parent | ||
@@ -295,4 +237,4 @@ } else { | ||
z.parent.color = Color.Black | ||
z.parent.parent.color = Color.Red | ||
z.parent.color = BLACK | ||
z.parent.parent.color = RED | ||
rotateRight(tree, z.parent.parent) | ||
@@ -303,6 +245,6 @@ } | ||
if (y.color === Color.Red) { | ||
z.parent.color = Color.Black | ||
y.color = Color.Black | ||
z.parent.parent.color = Color.Red | ||
if (y.color === RED) { | ||
z.parent.color = BLACK | ||
y.color = BLACK | ||
z.parent.parent.color = RED | ||
z = z.parent.parent | ||
@@ -315,4 +257,4 @@ } else { | ||
z.parent.color = Color.Black | ||
z.parent.parent.color = Color.Red | ||
z.parent.color = BLACK | ||
z.parent.parent.color = RED | ||
rotateLeft(tree, z.parent.parent) | ||
@@ -323,84 +265,125 @@ } | ||
tree.root.color = Color.Black | ||
tree.root.color = BLACK | ||
} | ||
const addNode = (tree, low, high, index) => { | ||
let x = tree.root | ||
let y = NULL_NODE | ||
while (x !== NULL_NODE) { | ||
y = x | ||
if (low === y.low) break | ||
if (low < x.low) x = x.left | ||
else x = x.right | ||
const IntervalTree = () => { | ||
const tree = { | ||
root: NULL_NODE, | ||
size: 0, | ||
} | ||
return { | ||
insert(low, high, index) { | ||
let x = tree.root | ||
let y = NULL_NODE | ||
if (low === y.low && y !== NULL_NODE) { | ||
if (!addInterval(y, high, index)) return | ||
y.high = Math.max(y.high, high) | ||
updateMax(y) | ||
updateMaxUp(y) | ||
tree.size++ | ||
return | ||
} | ||
while (x !== NULL_NODE) { | ||
y = x | ||
if (low === y.low) break | ||
if (low < x.low) x = x.left | ||
else x = x.right | ||
} | ||
const z = { | ||
low, | ||
high, | ||
max: high, | ||
color: Color.Red, | ||
parent: y, | ||
left: NULL_NODE, | ||
right: NULL_NODE, | ||
list: [ | ||
{ | ||
index, | ||
if (low === y.low && y !== NULL_NODE) { | ||
if (!addInterval(y, high, index)) return | ||
y.high = Math.max(y.high, high) | ||
updateMax(y) | ||
updateMaxUp(y) | ||
tree.size++ | ||
return | ||
} | ||
const z = { | ||
low, | ||
high, | ||
}, | ||
], | ||
} | ||
max: high, | ||
color: RED, | ||
parent: y, | ||
left: NULL_NODE, | ||
right: NULL_NODE, | ||
list: [ | ||
{ | ||
index, | ||
high, | ||
}, | ||
], | ||
} | ||
if (y === NULL_NODE) { | ||
tree.root = z | ||
} else { | ||
if (z.low < y.low) y.left = z | ||
else y.right = z | ||
updateMaxUp(z) | ||
} | ||
if (y === NULL_NODE) { | ||
tree.root = z | ||
} else { | ||
if (z.low < y.low) y.left = z | ||
else y.right = z | ||
updateMaxUp(z) | ||
} | ||
rbInsertFixup(tree, z) | ||
tree.size++ | ||
} | ||
rbInsertFixup(tree, z) | ||
tree.size++ | ||
}, | ||
const searchRecursive = (node, low, high, callback) => { | ||
if (node === NULL_NODE || low > node.max) return | ||
if (node.left !== NULL_NODE) searchRecursive(node.left, low, high, callback) | ||
remove(low, high, index) { | ||
const z = searchNode(tree.root, low) | ||
if (z === void 0) return | ||
const intervalResult = removeInterval(z, index) | ||
if (intervalResult === NOT_FOUND) return | ||
if (node.low <= high && node.high >= low) { | ||
for (let i = 0; i < node.list.length; i++) { | ||
const linkedInterval = node.list[i] | ||
if (linkedInterval.high >= low) | ||
callback(linkedInterval.index, node.low, linkedInterval.high) | ||
} | ||
} | ||
if (intervalResult === KEEP) { | ||
z.high = z.list[0].high | ||
updateMax(z) | ||
updateMaxUp(z) | ||
tree.size-- | ||
return | ||
} | ||
if (node.right !== NULL_NODE) searchRecursive(node.right, low, high, callback) | ||
} | ||
let y = z | ||
let originalYColor = y.color | ||
let x | ||
const IntervalTree = () => { | ||
const tree = { | ||
root: NULL_NODE, | ||
size: 0, | ||
} | ||
return { | ||
insert(low, high, index) { | ||
addNode(tree, low, high, index) | ||
}, | ||
if (z.left === NULL_NODE) { | ||
x = z.right | ||
rbTransplant(tree, z, z.right) | ||
} else if (z.right === NULL_NODE) { | ||
x = z.left | ||
rbTransplant(tree, z, z.left) | ||
} else { | ||
y = minimumTree(z.right) | ||
originalYColor = y.color | ||
x = y.right | ||
remove(low, high, index) { | ||
removeNode(tree, low, index) | ||
if (y.parent === z) { | ||
x.parent = y | ||
} else { | ||
rbTransplant(tree, y, y.right) | ||
y.right = z.right | ||
y.right.parent = y | ||
} | ||
rbTransplant(tree, z, y) | ||
y.left = z.left | ||
y.left.parent = y | ||
y.color = z.color | ||
} | ||
updateMax(x) | ||
updateMaxUp(x) | ||
if (originalYColor === BLACK) rbDeleteFixup(tree, x) | ||
tree.size-- | ||
}, | ||
search(low, high, callback) { | ||
searchRecursive(tree.root, low, high, callback) | ||
function searchRecursive(node) { | ||
if (node === NULL_NODE || low > node.max) return | ||
if (node.left !== NULL_NODE) searchRecursive(node.left) | ||
if (node.low <= high && node.high >= low) { | ||
for (let i = 0; i < node.list.length; i++) { | ||
const interval = node.list[i] | ||
if (interval.high >= low) | ||
callback(interval.index, node.low, interval.high) | ||
} | ||
} | ||
if (node.right !== NULL_NODE) searchRecursive(node.right) | ||
} | ||
searchRecursive(tree.root) | ||
}, | ||
@@ -407,0 +390,0 @@ |
@@ -459,3 +459,11 @@ import _pt from 'prop-types' | ||
const index = elementsCache.get(entry.target) | ||
if (index !== void 0) updates.push(index, height) | ||
const position = itemPositioner.get(index) | ||
if ( | ||
position !== void 0 && | ||
index !== void 0 && | ||
height !== position.height | ||
) { | ||
updates.push(index, height) | ||
} | ||
} | ||
@@ -462,0 +470,0 @@ } |
@@ -1,6 +0,2 @@ | ||
declare enum Color { | ||
Red = 0, | ||
Black = 1, | ||
Nil = 2, | ||
} | ||
declare type Color = 0 | 1 | 2 | ||
interface Interval { | ||
@@ -7,0 +3,0 @@ high: number |
@@ -1,17 +0,8 @@ | ||
var Color | ||
const RED = 0 | ||
const BLACK = 1 | ||
const NIL = 2 | ||
const DELETE = 0 | ||
const KEEP = 1 | ||
const NOT_FOUND = 2 | ||
;(function(Color) { | ||
Color[(Color['Red'] = 0)] = 'Red' | ||
Color[(Color['Black'] = 1)] = 'Black' | ||
Color[(Color['Nil'] = 2)] = 'Nil' | ||
})(Color || (Color = {})) | ||
var ListResult | ||
;(function(ListResult) { | ||
ListResult[(ListResult['Delete'] = 0)] = 'Delete' | ||
ListResult[(ListResult['Keep'] = 1)] = 'Keep' | ||
ListResult[(ListResult['NotFound'] = 2)] = 'NotFound' | ||
})(ListResult || (ListResult = {})) | ||
const addInterval = (treeNode, high, index) => { | ||
@@ -37,3 +28,3 @@ if (treeNode.list.length === 0) { | ||
const removeInterval = (treeNode, index) => { | ||
if (treeNode.list === void 0) return ListResult.NotFound | ||
if (treeNode.list === void 0) return NOT_FOUND | ||
@@ -46,3 +37,3 @@ for (let i = treeNode.list.length - 1; i > -1; i--) | ||
return treeNode.list.length > 0 ? ListResult.Keep : ListResult.Delete | ||
return treeNode.list.length > 0 ? KEEP : DELETE | ||
} | ||
@@ -54,3 +45,3 @@ | ||
high: 0, | ||
color: Color.Nil, | ||
color: NIL, | ||
// @ts-ignore | ||
@@ -80,3 +71,3 @@ parent: undefined, | ||
while (x.parent != NULL_NODE) { | ||
while (x.parent !== NULL_NODE) { | ||
updateMax(x.parent) | ||
@@ -88,3 +79,3 @@ x = x.parent | ||
const rotateLeft = (tree, x) => { | ||
if (x.right == NULL_NODE) return | ||
if (x.right === NULL_NODE) return | ||
const y = x.right | ||
@@ -106,3 +97,3 @@ x.right = y.left | ||
const rotateRight = (tree, x) => { | ||
if (x.left == NULL_NODE) return | ||
if (x.left === NULL_NODE) return | ||
const y = x.left | ||
@@ -138,9 +129,9 @@ x.left = y.right | ||
while (x !== NULL_NODE && x.color === Color.Black) { | ||
while (x !== NULL_NODE && x.color === BLACK) { | ||
if (x === x.parent.left) { | ||
w = x.parent.right | ||
if (w.color === Color.Red) { | ||
w.color = Color.Black | ||
x.parent.color = Color.Red | ||
if (w.color === RED) { | ||
w.color = BLACK | ||
x.parent.color = RED | ||
rotateLeft(tree, x.parent) | ||
@@ -150,9 +141,9 @@ w = x.parent.right | ||
if (w.left.color === Color.Black && w.right.color === Color.Black) { | ||
w.color = Color.Red | ||
if (w.left.color === BLACK && w.right.color === BLACK) { | ||
w.color = RED | ||
x = x.parent | ||
} else { | ||
if (w.right.color === Color.Black) { | ||
w.left.color = Color.Black | ||
w.color = Color.Red | ||
if (w.right.color === BLACK) { | ||
w.left.color = BLACK | ||
w.color = RED | ||
rotateRight(tree, w) | ||
@@ -163,4 +154,4 @@ w = x.parent.right | ||
w.color = x.parent.color | ||
x.parent.color = Color.Black | ||
w.right.color = Color.Black | ||
x.parent.color = BLACK | ||
w.right.color = BLACK | ||
rotateLeft(tree, x.parent) | ||
@@ -172,5 +163,5 @@ x = tree.root | ||
if (w.color === Color.Red) { | ||
w.color = Color.Black | ||
x.parent.color = Color.Red | ||
if (w.color === RED) { | ||
w.color = BLACK | ||
x.parent.color = RED | ||
rotateRight(tree, x.parent) | ||
@@ -180,9 +171,9 @@ w = x.parent.left | ||
if (w.right.color === Color.Black && w.left.color === Color.Black) { | ||
w.color = Color.Red | ||
if (w.right.color === BLACK && w.left.color === BLACK) { | ||
w.color = RED | ||
x = x.parent | ||
} else { | ||
if (w.left.color === Color.Black) { | ||
w.right.color = Color.Black | ||
w.color = Color.Red | ||
if (w.left.color === BLACK) { | ||
w.right.color = BLACK | ||
w.color = RED | ||
rotateLeft(tree, w) | ||
@@ -193,4 +184,4 @@ w = x.parent.left | ||
w.color = x.parent.color | ||
x.parent.color = Color.Black | ||
w.left.color = Color.Black | ||
x.parent.color = BLACK | ||
w.left.color = BLACK | ||
rotateRight(tree, x.parent) | ||
@@ -202,3 +193,3 @@ x = tree.root | ||
x.color = Color.Black | ||
x.color = BLACK | ||
} | ||
@@ -212,51 +203,2 @@ | ||
const removeNode = (tree, low, index) => { | ||
const z = searchNode(tree.root, low) | ||
if (z === void 0) return | ||
const linkedListResult = removeInterval(z, index) | ||
if (linkedListResult === ListResult.NotFound) return | ||
if (linkedListResult === ListResult.Keep) { | ||
z.high = z.list[0].high | ||
updateMax(z) | ||
updateMaxUp(z) | ||
tree.size-- | ||
return | ||
} | ||
let y = z | ||
let originalYColor = y.color | ||
let x | ||
if (z.left === NULL_NODE) { | ||
x = z.right | ||
rbTransplant(tree, z, z.right) | ||
} else if (z.right === NULL_NODE) { | ||
x = z.left | ||
rbTransplant(tree, z, z.left) | ||
} else { | ||
y = minimumTree(z.right) | ||
originalYColor = y.color | ||
x = y.right | ||
if (y.parent === z) { | ||
x.parent = y | ||
} else { | ||
rbTransplant(tree, y, y.right) | ||
y.right = z.right | ||
y.right.parent = y | ||
} | ||
rbTransplant(tree, z, y) | ||
y.left = z.left | ||
y.left.parent = y | ||
y.color = z.color | ||
} | ||
updateMax(x) | ||
updateMaxUp(x) | ||
if (originalYColor === Color.Black) rbDeleteFixup(tree, x) | ||
tree.size-- | ||
} | ||
const searchNode = (x, low) => { | ||
@@ -274,10 +216,10 @@ while (x !== NULL_NODE && low !== x.low) { | ||
while (z.parent.color === Color.Red) { | ||
while (z.parent.color === RED) { | ||
if (z.parent === z.parent.parent.left) { | ||
y = z.parent.parent.right | ||
if (y.color === Color.Red) { | ||
z.parent.color = Color.Black | ||
y.color = Color.Black | ||
z.parent.parent.color = Color.Red | ||
if (y.color === RED) { | ||
z.parent.color = BLACK | ||
y.color = BLACK | ||
z.parent.parent.color = RED | ||
z = z.parent.parent | ||
@@ -290,4 +232,4 @@ } else { | ||
z.parent.color = Color.Black | ||
z.parent.parent.color = Color.Red | ||
z.parent.color = BLACK | ||
z.parent.parent.color = RED | ||
rotateRight(tree, z.parent.parent) | ||
@@ -298,6 +240,6 @@ } | ||
if (y.color === Color.Red) { | ||
z.parent.color = Color.Black | ||
y.color = Color.Black | ||
z.parent.parent.color = Color.Red | ||
if (y.color === RED) { | ||
z.parent.color = BLACK | ||
y.color = BLACK | ||
z.parent.parent.color = RED | ||
z = z.parent.parent | ||
@@ -310,4 +252,4 @@ } else { | ||
z.parent.color = Color.Black | ||
z.parent.parent.color = Color.Red | ||
z.parent.color = BLACK | ||
z.parent.parent.color = RED | ||
rotateLeft(tree, z.parent.parent) | ||
@@ -318,84 +260,125 @@ } | ||
tree.root.color = Color.Black | ||
tree.root.color = BLACK | ||
} | ||
const addNode = (tree, low, high, index) => { | ||
let x = tree.root | ||
let y = NULL_NODE | ||
while (x !== NULL_NODE) { | ||
y = x | ||
if (low === y.low) break | ||
if (low < x.low) x = x.left | ||
else x = x.right | ||
const IntervalTree = () => { | ||
const tree = { | ||
root: NULL_NODE, | ||
size: 0, | ||
} | ||
return { | ||
insert(low, high, index) { | ||
let x = tree.root | ||
let y = NULL_NODE | ||
if (low === y.low && y !== NULL_NODE) { | ||
if (!addInterval(y, high, index)) return | ||
y.high = Math.max(y.high, high) | ||
updateMax(y) | ||
updateMaxUp(y) | ||
tree.size++ | ||
return | ||
} | ||
while (x !== NULL_NODE) { | ||
y = x | ||
if (low === y.low) break | ||
if (low < x.low) x = x.left | ||
else x = x.right | ||
} | ||
const z = { | ||
low, | ||
high, | ||
max: high, | ||
color: Color.Red, | ||
parent: y, | ||
left: NULL_NODE, | ||
right: NULL_NODE, | ||
list: [ | ||
{ | ||
index, | ||
if (low === y.low && y !== NULL_NODE) { | ||
if (!addInterval(y, high, index)) return | ||
y.high = Math.max(y.high, high) | ||
updateMax(y) | ||
updateMaxUp(y) | ||
tree.size++ | ||
return | ||
} | ||
const z = { | ||
low, | ||
high, | ||
}, | ||
], | ||
} | ||
max: high, | ||
color: RED, | ||
parent: y, | ||
left: NULL_NODE, | ||
right: NULL_NODE, | ||
list: [ | ||
{ | ||
index, | ||
high, | ||
}, | ||
], | ||
} | ||
if (y === NULL_NODE) { | ||
tree.root = z | ||
} else { | ||
if (z.low < y.low) y.left = z | ||
else y.right = z | ||
updateMaxUp(z) | ||
} | ||
if (y === NULL_NODE) { | ||
tree.root = z | ||
} else { | ||
if (z.low < y.low) y.left = z | ||
else y.right = z | ||
updateMaxUp(z) | ||
} | ||
rbInsertFixup(tree, z) | ||
tree.size++ | ||
} | ||
rbInsertFixup(tree, z) | ||
tree.size++ | ||
}, | ||
const searchRecursive = (node, low, high, callback) => { | ||
if (node === NULL_NODE || low > node.max) return | ||
if (node.left !== NULL_NODE) searchRecursive(node.left, low, high, callback) | ||
remove(low, high, index) { | ||
const z = searchNode(tree.root, low) | ||
if (z === void 0) return | ||
const intervalResult = removeInterval(z, index) | ||
if (intervalResult === NOT_FOUND) return | ||
if (node.low <= high && node.high >= low) { | ||
for (let i = 0; i < node.list.length; i++) { | ||
const linkedInterval = node.list[i] | ||
if (linkedInterval.high >= low) | ||
callback(linkedInterval.index, node.low, linkedInterval.high) | ||
} | ||
} | ||
if (intervalResult === KEEP) { | ||
z.high = z.list[0].high | ||
updateMax(z) | ||
updateMaxUp(z) | ||
tree.size-- | ||
return | ||
} | ||
if (node.right !== NULL_NODE) searchRecursive(node.right, low, high, callback) | ||
} | ||
let y = z | ||
let originalYColor = y.color | ||
let x | ||
const IntervalTree = () => { | ||
const tree = { | ||
root: NULL_NODE, | ||
size: 0, | ||
} | ||
return { | ||
insert(low, high, index) { | ||
addNode(tree, low, high, index) | ||
}, | ||
if (z.left === NULL_NODE) { | ||
x = z.right | ||
rbTransplant(tree, z, z.right) | ||
} else if (z.right === NULL_NODE) { | ||
x = z.left | ||
rbTransplant(tree, z, z.left) | ||
} else { | ||
y = minimumTree(z.right) | ||
originalYColor = y.color | ||
x = y.right | ||
remove(low, high, index) { | ||
removeNode(tree, low, index) | ||
if (y.parent === z) { | ||
x.parent = y | ||
} else { | ||
rbTransplant(tree, y, y.right) | ||
y.right = z.right | ||
y.right.parent = y | ||
} | ||
rbTransplant(tree, z, y) | ||
y.left = z.left | ||
y.left.parent = y | ||
y.color = z.color | ||
} | ||
updateMax(x) | ||
updateMaxUp(x) | ||
if (originalYColor === BLACK) rbDeleteFixup(tree, x) | ||
tree.size-- | ||
}, | ||
search(low, high, callback) { | ||
searchRecursive(tree.root, low, high, callback) | ||
function searchRecursive(node) { | ||
if (node === NULL_NODE || low > node.max) return | ||
if (node.left !== NULL_NODE) searchRecursive(node.left) | ||
if (node.low <= high && node.high >= low) { | ||
for (let i = 0; i < node.list.length; i++) { | ||
const interval = node.list[i] | ||
if (interval.high >= low) | ||
callback(interval.index, node.low, interval.high) | ||
} | ||
} | ||
if (node.right !== NULL_NODE) searchRecursive(node.right) | ||
} | ||
searchRecursive(tree.root) | ||
}, | ||
@@ -402,0 +385,0 @@ |
{ | ||
"name": "masonic", | ||
"version": "2.0.13", | ||
"version": "2.0.14", | ||
"homepage": "https://github.com/jaredLunde/masonic#readme", | ||
@@ -82,3 +82,2 @@ "repository": "github:jaredLunde/masonic", | ||
"prettier": "latest", | ||
"rand-int": "^1.0.0", | ||
"react": "latest", | ||
@@ -97,3 +96,2 @@ "react-dom": "latest", | ||
"@react-hook/window-size": "^1.0.10", | ||
"redblack": "^0.1.2", | ||
"resize-observer-polyfill": "^1.5.1", | ||
@@ -100,0 +98,0 @@ "trie-memoize": "^1.0.19" |
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
10
28
92768
2555
- Removedredblack@^0.1.2
- Removedredblack@0.1.2(transitive)