added some fixes and started DeleteStore implementation
This commit is contained in:
parent
dd5e2adc87
commit
d1fda080d9
@ -8,6 +8,27 @@ function copyObject (o) {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DeletionStore { // eslint-disable-line
|
||||||
|
constructor () {
|
||||||
|
this.ds = {}
|
||||||
|
}
|
||||||
|
deleteId (id) {
|
||||||
|
var dv = this.db[id[0]]
|
||||||
|
if (dv === void 0) {
|
||||||
|
dv = []
|
||||||
|
this.db[id[0]] = dv
|
||||||
|
}
|
||||||
|
for (var i in dv) {
|
||||||
|
if (dv[i].pos <= id[1] && id[1] < dv[i].pos + length) {
|
||||||
|
// within the bound, already deleted
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Y.Memory = (function () { // eslint-disable-line no-unused-vars
|
Y.Memory = (function () { // eslint-disable-line no-unused-vars
|
||||||
class Transaction extends AbstractTransaction { // eslint-disable-line
|
class Transaction extends AbstractTransaction { // eslint-disable-line
|
||||||
|
|
||||||
|
@ -80,6 +80,22 @@ class N {
|
|||||||
return p.parent
|
return p.parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
prev () {
|
||||||
|
if (this.left !== null) {
|
||||||
|
// search the most right node in the left tree
|
||||||
|
var o = this.left
|
||||||
|
while (o.right !== null) {
|
||||||
|
o = o.right
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
} else {
|
||||||
|
var p = this
|
||||||
|
while (p.parent !== null && p !== p.parent.right) {
|
||||||
|
p = p.parent
|
||||||
|
}
|
||||||
|
return p.parent
|
||||||
|
}
|
||||||
|
}
|
||||||
rotateRight (tree) {
|
rotateRight (tree) {
|
||||||
var parent = this.parent
|
var parent = this.parent
|
||||||
var newParent = this.left
|
var newParent = this.left
|
||||||
@ -118,7 +134,7 @@ class RBTree { // eslint-disable-line no-unused-vars
|
|||||||
}
|
}
|
||||||
var o = this.root
|
var o = this.root
|
||||||
if (o === null) {
|
if (o === null) {
|
||||||
return false
|
return null
|
||||||
} else {
|
} else {
|
||||||
while (true) {
|
while (true) {
|
||||||
if ((from === null || smaller(from, o.val.id)) && o.left !== null) {
|
if ((from === null || smaller(from, o.val.id)) && o.left !== null) {
|
||||||
@ -140,6 +156,34 @@ class RBTree { // eslint-disable-line no-unused-vars
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
findNodeWithUpperBound (to) {
|
||||||
|
if (to === void 0) {
|
||||||
|
throw new Error('You must define from!')
|
||||||
|
}
|
||||||
|
var o = this.root
|
||||||
|
if (o === null) {
|
||||||
|
return null
|
||||||
|
} else {
|
||||||
|
while (true) {
|
||||||
|
if ((to === null || smaller(o.val.id, to)) && o.right !== null) {
|
||||||
|
// o is included in the bound
|
||||||
|
// try to find an element that is closer to the bound
|
||||||
|
o = o.right
|
||||||
|
} else if (to !== null && smaller(to, o.val.id)) {
|
||||||
|
// o is not within the bound, maybe one of the left elements is..
|
||||||
|
if (o.left !== null) {
|
||||||
|
o = o.left
|
||||||
|
} else {
|
||||||
|
// there is no left element. Search for the prev smaller element,
|
||||||
|
// this should be within the bounds
|
||||||
|
return o.prev()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
iterate (from, to, f) {
|
iterate (from, to, f) {
|
||||||
var o = this.findNodeWithLowerBound(from)
|
var o = this.findNodeWithLowerBound(from)
|
||||||
while (o !== null && (to === null || smaller(o.val.id, to) || compareIds(o.val.id, to))) {
|
while (o !== null && (to === null || smaller(o.val.id, to) || compareIds(o.val.id, to))) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user