MCPcopy
hub / github.com/yjs/yjs / createRandomIdMap

Function createRandomIdMap

tests/testHelper.js:419–439  ·  view source on GitHub ↗
(gen, clients, clockRange, attrChoices)

Source from the content-addressed store, hash-verified

417 * @return {Y.IdMap<T>}
418 */
419export const createRandomIdMap = (gen, clients, clockRange, attrChoices) => {
420 const maxOpLen = 5
421 const numOfOps = math.ceil((clients * clockRange) / maxOpLen)
422 const idMap = createIdMap()
423 for (let i = 0; i < numOfOps; i++) {
424 const client = prng.uint32(gen, 0, clients - 1)
425 const clockStart = prng.uint32(gen, 0, clockRange)
426 const len = prng.uint32(gen, 0, clockRange - clockStart)
427 const attrs = [prng.oneOf(gen, attrChoices)]
428 // maybe add another attr
429 if (prng.bool(gen)) {
430 const a = prng.oneOf(gen, attrChoices)
431 if (attrs.find(attr => attr === a) == null) {
432 attrs.push(a)
433 }
434 }
435 idMap.add(client, clockStart, len, attrs.map(v => Y.createContentAttribute('', v)))
436 }
437 t.info(`Created IdMap with ${numOfOps} ranges and ${attrChoices.length} different attributes. Encoded size: ${encodeIdMap(idMap).byteLength}`)
438 return idMap
439}
440
441/**
442 * 1. reconnect and flush all

Callers 5

testRepeatRandomDiffingFunction · 0.90
testRepeatRandomDiffing2Function · 0.90
testRepeatRandomDeletesFunction · 0.90

Calls 5

createIdMapFunction · 0.90
encodeIdMapFunction · 0.90
pushMethod · 0.80
mapMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…