(transaction, store, clientsStructRefs)
| 187 | * @function |
| 188 | */ |
| 189 | const integrateStructs = (transaction, store, clientsStructRefs) => { |
| 190 | /** |
| 191 | * @type {Array<Item | GC>} |
| 192 | */ |
| 193 | const stack = [] |
| 194 | // sort them so that we take the higher id first, in case of conflicts the lower id will probably not conflict with the id from the higher user. |
| 195 | let clientsStructRefsIds = array.from(clientsStructRefs.clients.keys()).sort((a, b) => a - b) |
| 196 | if (clientsStructRefsIds.length === 0) { |
| 197 | return null |
| 198 | } |
| 199 | const getNextStructTarget = () => { |
| 200 | if (clientsStructRefsIds.length === 0) { |
| 201 | return null |
| 202 | } |
| 203 | let nextStructsTarget = /** @type {{i:number,refs:Array<GC|Item>}} */ (clientsStructRefs.clients.get(clientsStructRefsIds[clientsStructRefsIds.length - 1])) |
| 204 | while (nextStructsTarget.refs.length === nextStructsTarget.i) { |
| 205 | clientsStructRefsIds.pop() |
| 206 | if (clientsStructRefsIds.length > 0) { |
| 207 | nextStructsTarget = /** @type {{i:number,refs:Array<GC|Item>}} */ (clientsStructRefs.clients.get(clientsStructRefsIds[clientsStructRefsIds.length - 1])) |
| 208 | } else { |
| 209 | return null |
| 210 | } |
| 211 | } |
| 212 | return nextStructsTarget |
| 213 | } |
| 214 | let curStructsTarget = getNextStructTarget() |
| 215 | if (curStructsTarget === null) { |
| 216 | return null |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * @type {StructStore} |
| 221 | */ |
| 222 | const restStructs = new StructStore() |
| 223 | const missingSV = new Map() |
| 224 | /** |
| 225 | * @param {number} client |
| 226 | * @param {number} clock |
| 227 | */ |
| 228 | const updateMissingSv = (client, clock) => { |
| 229 | const mclock = missingSV.get(client) |
| 230 | if (mclock == null || mclock > clock) { |
| 231 | missingSV.set(client, clock) |
| 232 | } |
| 233 | } |
| 234 | /** |
| 235 | * @type {GC|Item} |
| 236 | */ |
| 237 | let stackHead = /** @type {any} */ (curStructsTarget).refs[/** @type {any} */ (curStructsTarget).i++] |
| 238 | // caching the state because it is used very often |
| 239 | const state = new Map() |
| 240 | |
| 241 | // // caching the state because it is used very often |
| 242 | // const currentInsertSet = createIdSet() |
| 243 | // clientsStructRefsIds.forEach(clientId => { |
| 244 | // currentInsertSet.clients.set(clientid, new IdRanges(_createInsertSliceFromStructs(store.clients.get(clientId) ?? [], false))) |
| 245 | // }) |
| 246 |
no test coverage detected
searching dependent graphs…