implemented xml type for new event system
This commit is contained in:
@@ -3,25 +3,26 @@ import ID from '../Util/ID.js'
|
||||
|
||||
class DSNode {
|
||||
constructor (id, len, gc) {
|
||||
this.id = id
|
||||
this._id = id
|
||||
this.len = len
|
||||
this.gc = gc
|
||||
}
|
||||
clone () {
|
||||
return new DSNode(this.id, this.len, this.gc)
|
||||
return new DSNode(this._id, this.len, this.gc)
|
||||
}
|
||||
}
|
||||
|
||||
export default class DeleteStore extends Tree {
|
||||
isDeleted (id) {
|
||||
var n = this.ds.findWithUpperBound(id)
|
||||
return n != null && n.id[0] === id[0] && id[1] < n.id[1] + n.len
|
||||
var n = this.findWithUpperBound(id)
|
||||
return n !== null && n._id.user === id.user && id.clock < n._id.clock + n.len
|
||||
}
|
||||
// TODO: put this in function (and all other methods)
|
||||
applyMissingDeletesOnStruct (struct) {
|
||||
const strID = struct._id
|
||||
// find most right delete
|
||||
let n = this.findWithUpperBound(new ID(strID.user, strID.clock + struct.length - 1))
|
||||
if (n === null || n.id.user !== strID.user || n.id.clock + n.length <= strID.clock) {
|
||||
let n = this.findWithUpperBound(new ID(strID.user, strID.clock + struct._length - 1))
|
||||
if (n === null || n._id.user !== strID.user || n._id.clock + n.len <= strID.clock) {
|
||||
// struct is not deleted
|
||||
return null
|
||||
}
|
||||
@@ -37,22 +38,22 @@ export default class DeleteStore extends Tree {
|
||||
throw new Error('length must be defined')
|
||||
}
|
||||
var n = this.findWithUpperBound(id)
|
||||
if (n != null && n.id.user === id.user) {
|
||||
if (n.id.clock <= id.clock && id.clock <= n.id.clock + n.len) {
|
||||
if (n != null && n._id.user === id.user) {
|
||||
if (n._id.clock <= id.clock && id.clock <= n._id.clock + n.len) {
|
||||
// id is in n's range
|
||||
var diff = id.clock + length - (n.id.clock + n.len) // overlapping right
|
||||
var diff = id.clock + length - (n._id.clock + n.len) // overlapping right
|
||||
if (diff > 0) {
|
||||
// id+length overlaps n
|
||||
if (!n.gc) {
|
||||
n.len += diff
|
||||
} else {
|
||||
diff = n.id.clock + n.len - id.clock // overlapping left (id till n.end)
|
||||
diff = n._id.clock + n.len - id.clock // overlapping left (id till n.end)
|
||||
if (diff < length) {
|
||||
// a partial deletion
|
||||
let nId = id.clone()
|
||||
nId.clock += diff
|
||||
n = new DSNode(nId, length - diff, false)
|
||||
this.ds.put(n)
|
||||
this.put(n)
|
||||
} else {
|
||||
// already gc'd
|
||||
throw new Error(
|
||||
@@ -67,21 +68,21 @@ export default class DeleteStore extends Tree {
|
||||
} else {
|
||||
// cannot extend left (there is no left!)
|
||||
n = new DSNode(id, length, false)
|
||||
this.ds.put(n) // TODO: you double-put !!
|
||||
this.put(n) // TODO: you double-put !!
|
||||
}
|
||||
} else {
|
||||
// cannot extend left
|
||||
n = new DSNode(id, length, false)
|
||||
this.ds.put(n)
|
||||
this.put(n)
|
||||
}
|
||||
// can extend right?
|
||||
var next = this.ds.findNext(n.id)
|
||||
var next = this.findNext(n._id)
|
||||
if (
|
||||
next != null &&
|
||||
n.id.user === next.id.user &&
|
||||
n.id.clock + n.len >= next.id.clock
|
||||
n._id.user === next._id.user &&
|
||||
n._id.clock + n.len >= next._id.clock
|
||||
) {
|
||||
diff = n.id.clock + n.len - next.id.clock // from next.start to n.end
|
||||
diff = n._id.clock + n.len - next._id.clock // from next.start to n.end
|
||||
while (diff >= 0) {
|
||||
// n overlaps with next
|
||||
if (next.gc) {
|
||||
@@ -92,7 +93,7 @@ export default class DeleteStore extends Tree {
|
||||
diff = diff - next.len // missing range after next
|
||||
if (diff > 0) {
|
||||
this.put(n) // unneccessary? TODO!
|
||||
this.markDeleted(new ID(next.id.user, next.id.clock + next.len), diff)
|
||||
this.markDeleted(new ID(next._id.user, next._id.clock + next.len), diff)
|
||||
}
|
||||
}
|
||||
break
|
||||
@@ -101,19 +102,19 @@ export default class DeleteStore extends Tree {
|
||||
if (diff > next.len) {
|
||||
// n is even longer than next
|
||||
// get next.next, and try to extend it
|
||||
var _next = this.findNext(next.id)
|
||||
this.delete(next.id)
|
||||
if (_next == null || n.id.user !== _next.id.user) {
|
||||
var _next = this.findNext(next._id)
|
||||
this.delete(next._id)
|
||||
if (_next == null || n._id.user !== _next._id.user) {
|
||||
break
|
||||
} else {
|
||||
next = _next
|
||||
diff = n.id.clock + n.len - next.id.clock // from next.start to n.end
|
||||
diff = n._id.clock + n.len - next._id.clock // from next.start to n.end
|
||||
// continue!
|
||||
}
|
||||
} else {
|
||||
// n just partially overlaps with next. extend n, delete next, and break this loop
|
||||
n.len += next.len - diff
|
||||
this.delete(next.id)
|
||||
this.delete(next._id)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Tree from '../Util/Tree.js'
|
||||
import RootID from '../Util/ID.js'
|
||||
import RootID from '../Util/RootID.js'
|
||||
import { getStruct } from '../Util/structReferences.js'
|
||||
|
||||
export default class OperationStore extends Tree {
|
||||
@@ -10,10 +10,12 @@ export default class OperationStore extends Tree {
|
||||
get (id) {
|
||||
let struct = this.find(id)
|
||||
if (struct === null && id instanceof RootID) {
|
||||
let Constr = getStruct(id.type)
|
||||
const Constr = getStruct(id.type)
|
||||
const y = this.y
|
||||
struct = new Constr()
|
||||
struct._id = id
|
||||
struct._parent = this.y
|
||||
struct._parent = y
|
||||
struct._integrate(y)
|
||||
this.put(struct)
|
||||
}
|
||||
return struct
|
||||
|
||||
@@ -4,12 +4,12 @@ export default class StateStore {
|
||||
constructor (y) {
|
||||
this.y = y
|
||||
this.state = new Map()
|
||||
this.currentClock = 0
|
||||
}
|
||||
getNextID (len) {
|
||||
let id = new ID(this.y.userID, this.currentClock)
|
||||
this.currentClock += len
|
||||
return id
|
||||
const user = this.y.userID
|
||||
const state = this.getState(user)
|
||||
this.setState(user, state + len)
|
||||
return new ID(user, state)
|
||||
}
|
||||
updateRemoteState (struct) {
|
||||
let user = struct._id.user
|
||||
@@ -27,4 +27,8 @@ export default class StateStore {
|
||||
}
|
||||
return state
|
||||
}
|
||||
setState (user, state) {
|
||||
// TODO: modify missingi structs here
|
||||
this.state.set(user, state)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user