mirror of
https://github.com/yjs/yjs.git
synced 2025-12-16 11:47:46 +01:00
more renames (ds=>idset)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
_diffSet,
|
||||
findIndexInIdRanges,
|
||||
DSDecoderV1, DSDecoderV2, DSEncoderV1, DSEncoderV2, IdSet, ID // eslint-disable-line
|
||||
DSDecoderV1, DSDecoderV2, IdSetEncoderV1, IdSetEncoderV2, IdSet, ID // eslint-disable-line
|
||||
} from '../internals.js'
|
||||
|
||||
import * as array from 'lib0/array'
|
||||
@@ -342,7 +342,7 @@ export class IdMap {
|
||||
* written. Attribute.names are referenced by id. Attributes themselfs are also referenced by id.
|
||||
*
|
||||
* @template Attr
|
||||
* @param {DSEncoderV1 | DSEncoderV2} encoder
|
||||
* @param {IdSetEncoderV1 | IdSetEncoderV2} encoder
|
||||
* @param {IdMap<Attr>} idmap
|
||||
*
|
||||
* @private
|
||||
@@ -364,7 +364,7 @@ export const writeIdMap = (encoder, idmap) => {
|
||||
.sort((a, b) => a[0] - b[0])
|
||||
.forEach(([client, _idRanges]) => {
|
||||
const attrRanges = _idRanges.getIds()
|
||||
encoder.resetDsCurVal()
|
||||
encoder.resetIdSetCurVal()
|
||||
const diff = client - lastWrittenClientId
|
||||
encoding.writeVarUint(encoder.restEncoder, diff)
|
||||
lastWrittenClientId = client
|
||||
@@ -374,8 +374,8 @@ export const writeIdMap = (encoder, idmap) => {
|
||||
const item = attrRanges[i]
|
||||
const attrs = item.attrs
|
||||
const attrLen = attrs.length
|
||||
encoder.writeDsClock(item.clock)
|
||||
encoder.writeDsLen(item.len)
|
||||
encoder.writeIdSetClock(item.clock)
|
||||
encoder.writeIdSetLen(item.len)
|
||||
encoding.writeVarUint(encoder.restEncoder, attrLen)
|
||||
for (let j = 0; j < attrLen; j++) {
|
||||
const attr = attrs[j]
|
||||
@@ -407,7 +407,7 @@ export const writeIdMap = (encoder, idmap) => {
|
||||
* @param {IdMap<any>} idmap
|
||||
*/
|
||||
export const encodeIdMap = idmap => {
|
||||
const encoder = new DSEncoderV2()
|
||||
const encoder = new IdSetEncoderV2()
|
||||
writeIdMap(encoder, idmap)
|
||||
return encoder.toUint8Array()
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
UpdateEncoderV2,
|
||||
IdMap,
|
||||
AttrRanges,
|
||||
AbstractStruct, DSDecoderV1, DSEncoderV1, DSDecoderV2, DSEncoderV2, Item, GC, StructStore, Transaction, ID // eslint-disable-line
|
||||
AbstractStruct, DSDecoderV1, IdSetEncoderV1, DSDecoderV2, IdSetEncoderV2, Item, GC, StructStore, Transaction, ID // eslint-disable-line
|
||||
} from '../internals.js'
|
||||
|
||||
import * as array from 'lib0/array'
|
||||
@@ -358,7 +358,7 @@ export const createDeleteSetFromStructStore = ss => {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {DSEncoderV1 | DSEncoderV2} encoder
|
||||
* @param {IdSetEncoderV1 | IdSetEncoderV2} encoder
|
||||
* @param {IdSet} idSet
|
||||
*
|
||||
* @private
|
||||
@@ -371,14 +371,14 @@ export const writeIdSet = (encoder, idSet) => {
|
||||
.sort((a, b) => b[0] - a[0])
|
||||
.forEach(([client, _idRanges]) => {
|
||||
const idRanges = _idRanges.getIds()
|
||||
encoder.resetDsCurVal()
|
||||
encoder.resetIdSetCurVal()
|
||||
encoding.writeVarUint(encoder.restEncoder, client)
|
||||
const len = idRanges.length
|
||||
encoding.writeVarUint(encoder.restEncoder, len)
|
||||
for (let i = 0; i < len; i++) {
|
||||
const item = idRanges[i]
|
||||
encoder.writeDsClock(item.clock)
|
||||
encoder.writeDsLen(item.len)
|
||||
encoder.writeIdSetClock(item.clock)
|
||||
encoder.writeIdSetLen(item.len)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
writeIdSet,
|
||||
createIdSet,
|
||||
mergeIdSets,
|
||||
DSEncoderV1, DSDecoderV1, ID, IdSet, YArrayEvent, Transaction, Doc // eslint-disable-line
|
||||
IdSetEncoderV1, DSDecoderV1, ID, IdSet, YArrayEvent, Transaction, Doc // eslint-disable-line
|
||||
} from '../internals.js'
|
||||
|
||||
import * as decoding from 'lib0/decoding'
|
||||
@@ -95,7 +95,7 @@ export class PermanentUserData {
|
||||
user.get('ids').push([clientid])
|
||||
}
|
||||
})
|
||||
const encoder = new DSEncoderV1()
|
||||
const encoder = new IdSetEncoderV1()
|
||||
const ds = this.dss.get(userDescription)
|
||||
if (ds) {
|
||||
writeIdSet(encoder, ds)
|
||||
@@ -109,7 +109,7 @@ export class PermanentUserData {
|
||||
const yds = user.get('ds')
|
||||
const ds = transaction.deleteSet
|
||||
if (transaction.local && ds.clients.size > 0 && filter(transaction, ds)) {
|
||||
const encoder = new DSEncoderV1()
|
||||
const encoder = new IdSetEncoderV1()
|
||||
writeIdSet(encoder, ds)
|
||||
yds.push([encoder.toUint8Array()])
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
applyUpdateV2,
|
||||
LazyStructReader,
|
||||
equalIdSets,
|
||||
UpdateDecoderV1, UpdateDecoderV2, DSEncoderV1, DSEncoderV2, DSDecoderV1, DSDecoderV2, Transaction, Doc, IdSet, Item, // eslint-disable-line
|
||||
UpdateDecoderV1, UpdateDecoderV2, IdSetEncoderV1, IdSetEncoderV2, DSDecoderV1, DSDecoderV2, Transaction, Doc, IdSet, Item, // eslint-disable-line
|
||||
mergeIdSets
|
||||
} from '../internals.js'
|
||||
|
||||
@@ -63,10 +63,10 @@ export const equalSnapshots = (snap1, snap2) => {
|
||||
|
||||
/**
|
||||
* @param {Snapshot} snapshot
|
||||
* @param {DSEncoderV1 | DSEncoderV2} [encoder]
|
||||
* @param {IdSetEncoderV1 | IdSetEncoderV2} [encoder]
|
||||
* @return {Uint8Array}
|
||||
*/
|
||||
export const encodeSnapshotV2 = (snapshot, encoder = new DSEncoderV2()) => {
|
||||
export const encodeSnapshotV2 = (snapshot, encoder = new IdSetEncoderV2()) => {
|
||||
writeIdSet(encoder, snapshot.ds)
|
||||
writeStateVector(encoder, snapshot.sv)
|
||||
return encoder.toUint8Array()
|
||||
@@ -76,7 +76,7 @@ export const encodeSnapshotV2 = (snapshot, encoder = new DSEncoderV2()) => {
|
||||
* @param {Snapshot} snapshot
|
||||
* @return {Uint8Array}
|
||||
*/
|
||||
export const encodeSnapshot = snapshot => encodeSnapshotV2(snapshot, new DSEncoderV1())
|
||||
export const encodeSnapshot = snapshot => encodeSnapshotV2(snapshot, new IdSetEncoderV1())
|
||||
|
||||
/**
|
||||
* @param {Uint8Array} buf
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
ID // eslint-disable-line
|
||||
} from '../internals.js'
|
||||
|
||||
export class DSEncoderV1 {
|
||||
export class IdSetEncoderV1 {
|
||||
constructor () {
|
||||
this.restEncoder = encoding.createEncoder()
|
||||
}
|
||||
@@ -14,26 +14,26 @@ export class DSEncoderV1 {
|
||||
return encoding.toUint8Array(this.restEncoder)
|
||||
}
|
||||
|
||||
resetDsCurVal () {
|
||||
resetIdSetCurVal () {
|
||||
// nop
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} clock
|
||||
*/
|
||||
writeDsClock (clock) {
|
||||
writeIdSetClock (clock) {
|
||||
encoding.writeVarUint(this.restEncoder, clock)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} len
|
||||
*/
|
||||
writeDsLen (len) {
|
||||
writeIdSetLen (len) {
|
||||
encoding.writeVarUint(this.restEncoder, len)
|
||||
}
|
||||
}
|
||||
|
||||
export class UpdateEncoderV1 extends DSEncoderV1 {
|
||||
export class UpdateEncoderV1 extends IdSetEncoderV1 {
|
||||
/**
|
||||
* @param {ID} id
|
||||
*/
|
||||
@@ -124,7 +124,7 @@ export class UpdateEncoderV1 extends DSEncoderV1 {
|
||||
}
|
||||
}
|
||||
|
||||
export class DSEncoderV2 {
|
||||
export class IdSetEncoderV2 {
|
||||
constructor () {
|
||||
this.restEncoder = encoding.createEncoder() // encodes all the rest / non-optimized
|
||||
this.dsCurrVal = 0
|
||||
@@ -134,14 +134,14 @@ export class DSEncoderV2 {
|
||||
return encoding.toUint8Array(this.restEncoder)
|
||||
}
|
||||
|
||||
resetDsCurVal () {
|
||||
resetIdSetCurVal () {
|
||||
this.dsCurrVal = 0
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} clock
|
||||
*/
|
||||
writeDsClock (clock) {
|
||||
writeIdSetClock (clock) {
|
||||
const diff = clock - this.dsCurrVal
|
||||
this.dsCurrVal = clock
|
||||
encoding.writeVarUint(this.restEncoder, diff)
|
||||
@@ -150,7 +150,7 @@ export class DSEncoderV2 {
|
||||
/**
|
||||
* @param {number} len
|
||||
*/
|
||||
writeDsLen (len) {
|
||||
writeIdSetLen (len) {
|
||||
if (len === 0) {
|
||||
error.unexpectedCase()
|
||||
}
|
||||
@@ -159,7 +159,7 @@ export class DSEncoderV2 {
|
||||
}
|
||||
}
|
||||
|
||||
export class UpdateEncoderV2 extends DSEncoderV2 {
|
||||
export class UpdateEncoderV2 extends IdSetEncoderV2 {
|
||||
constructor () {
|
||||
super()
|
||||
/**
|
||||
|
||||
@@ -27,9 +27,9 @@ import {
|
||||
UpdateDecoderV2,
|
||||
UpdateEncoderV1,
|
||||
UpdateEncoderV2,
|
||||
DSEncoderV2,
|
||||
IdSetEncoderV2,
|
||||
DSDecoderV1,
|
||||
DSEncoderV1,
|
||||
IdSetEncoderV1,
|
||||
mergeUpdates,
|
||||
mergeUpdatesV2,
|
||||
Skip,
|
||||
@@ -613,7 +613,7 @@ export const readStateVector = decoder => {
|
||||
export const decodeStateVector = decodedState => readStateVector(new DSDecoderV1(decoding.createDecoder(decodedState)))
|
||||
|
||||
/**
|
||||
* @param {DSEncoderV1 | DSEncoderV2} encoder
|
||||
* @param {IdSetEncoderV1 | IdSetEncoderV2} encoder
|
||||
* @param {Map<number,number>} sv
|
||||
* @function
|
||||
*/
|
||||
@@ -627,7 +627,7 @@ export const writeStateVector = (encoder, sv) => {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {DSEncoderV1 | DSEncoderV2} encoder
|
||||
* @param {IdSetEncoderV1 | IdSetEncoderV2} encoder
|
||||
* @param {Doc} doc
|
||||
*
|
||||
* @function
|
||||
@@ -638,12 +638,12 @@ export const writeDocumentStateVector = (encoder, doc) => writeStateVector(encod
|
||||
* Encode State as Uint8Array.
|
||||
*
|
||||
* @param {Doc|Map<number,number>} doc
|
||||
* @param {DSEncoderV1 | DSEncoderV2} [encoder]
|
||||
* @param {IdSetEncoderV1 | IdSetEncoderV2} [encoder]
|
||||
* @return {Uint8Array}
|
||||
*
|
||||
* @function
|
||||
*/
|
||||
export const encodeStateVectorV2 = (doc, encoder = new DSEncoderV2()) => {
|
||||
export const encodeStateVectorV2 = (doc, encoder = new IdSetEncoderV2()) => {
|
||||
if (doc instanceof Map) {
|
||||
writeStateVector(encoder, doc)
|
||||
} else {
|
||||
@@ -660,4 +660,4 @@ export const encodeStateVectorV2 = (doc, encoder = new DSEncoderV2()) => {
|
||||
*
|
||||
* @function
|
||||
*/
|
||||
export const encodeStateVector = doc => encodeStateVectorV2(doc, new DSEncoderV1())
|
||||
export const encodeStateVector = doc => encodeStateVectorV2(doc, new IdSetEncoderV1())
|
||||
|
||||
@@ -20,8 +20,8 @@ import {
|
||||
ContentType,
|
||||
createID,
|
||||
decodeStateVector,
|
||||
DSEncoderV1,
|
||||
DSEncoderV2,
|
||||
IdSetEncoderV1,
|
||||
IdSetEncoderV2,
|
||||
GC,
|
||||
Item,
|
||||
mergeIdSets,
|
||||
@@ -187,11 +187,11 @@ export const mergeUpdates = updates => mergeUpdatesV2(updates, UpdateDecoderV1,
|
||||
|
||||
/**
|
||||
* @param {Uint8Array} update
|
||||
* @param {typeof DSEncoderV1 | typeof DSEncoderV2} YEncoder
|
||||
* @param {typeof IdSetEncoderV1 | typeof IdSetEncoderV2} YEncoder
|
||||
* @param {typeof UpdateDecoderV1 | typeof UpdateDecoderV2} YDecoder
|
||||
* @return {Uint8Array}
|
||||
*/
|
||||
export const encodeStateVectorFromUpdateV2 = (update, YEncoder = DSEncoderV2, YDecoder = UpdateDecoderV2) => {
|
||||
export const encodeStateVectorFromUpdateV2 = (update, YEncoder = IdSetEncoderV2, YDecoder = UpdateDecoderV2) => {
|
||||
const encoder = new YEncoder()
|
||||
const updateDecoder = new LazyStructReader(new YDecoder(decoding.createDecoder(update)), false)
|
||||
let curr = updateDecoder.curr
|
||||
@@ -243,7 +243,7 @@ export const encodeStateVectorFromUpdateV2 = (update, YEncoder = DSEncoderV2, YD
|
||||
* @param {Uint8Array} update
|
||||
* @return {Uint8Array}
|
||||
*/
|
||||
export const encodeStateVectorFromUpdate = update => encodeStateVectorFromUpdateV2(update, DSEncoderV1, UpdateDecoderV1)
|
||||
export const encodeStateVectorFromUpdate = update => encodeStateVectorFromUpdateV2(update, IdSetEncoderV1, UpdateDecoderV1)
|
||||
|
||||
/**
|
||||
* @param {Uint8Array} update
|
||||
|
||||
@@ -110,11 +110,11 @@ export const testRepeatRandomDiffing = tc => {
|
||||
const clients = 4
|
||||
const clockRange = 100
|
||||
const attrs = [1, 2, 3]
|
||||
const ds1 = createRandomIdMap(tc.prng, clients, clockRange, attrs)
|
||||
const ds2 = createRandomIdMap(tc.prng, clients, clockRange, attrs)
|
||||
const merged = idmap.mergeIdMaps([ds1, ds2])
|
||||
const e1 = idmap.diffIdMap(ds1, ds2)
|
||||
const e2 = idmap.diffIdMap(merged, ds2)
|
||||
const idset1 = createRandomIdMap(tc.prng, clients, clockRange, attrs)
|
||||
const idset2 = createRandomIdMap(tc.prng, clients, clockRange, attrs)
|
||||
const merged = idmap.mergeIdMaps([idset1, idset2])
|
||||
const e1 = idmap.diffIdMap(idset1, idset2)
|
||||
const e2 = idmap.diffIdMap(merged, idset2)
|
||||
compareIdmaps(e1, e2)
|
||||
const copy = YY.decodeIdMap(YY.encodeIdMap(e1))
|
||||
compareIdmaps(e1, copy)
|
||||
|
||||
@@ -6,11 +6,11 @@ import { compareIdSets, createRandomIdSet, ID } from './testHelper.js'
|
||||
* @param {Array<[number, number, number]>} ops
|
||||
*/
|
||||
const simpleConstructIdSet = ops => {
|
||||
const ds = d.createIdSet()
|
||||
const idset = d.createIdSet()
|
||||
ops.forEach(op => {
|
||||
d.addToIdSet(ds, op[0], op[1], op[2])
|
||||
d.addToIdSet(idset, op[0], op[1], op[2])
|
||||
})
|
||||
return ds
|
||||
return idset
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -399,17 +399,17 @@ export const compareIdmaps = (idmap1, idmap2) => {
|
||||
export const createRandomIdSet = (gen, clients, clockRange) => {
|
||||
const maxOpLen = 5
|
||||
const numOfOps = math.ceil((clients * clockRange) / maxOpLen)
|
||||
const ds = createIdSet()
|
||||
const idset = createIdSet()
|
||||
for (let i = 0; i < numOfOps; i++) {
|
||||
const client = prng.uint32(gen, 0, clients - 1)
|
||||
const clockStart = prng.uint32(gen, 0, clockRange)
|
||||
const len = prng.uint32(gen, 0, clockRange - clockStart)
|
||||
addToIdSet(ds, client, clockStart, len)
|
||||
addToIdSet(idset, client, clockStart, len)
|
||||
}
|
||||
if (ds.clients.size === clients && clients > 1 && prng.bool(gen)) {
|
||||
ds.clients.delete(prng.uint32(gen, 0, clients))
|
||||
if (idset.clients.size === clients && clients > 1 && prng.bool(gen)) {
|
||||
idset.clients.delete(prng.uint32(gen, 0, clients))
|
||||
}
|
||||
return ds
|
||||
return idset
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user