tla-ts 0.0.4-dev.5f6a4bf → 0.0.4-dev.66582d4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tla-ts",
3
- "version": "0.0.4-dev.5f6a4bf",
3
+ "version": "0.0.4-dev.66582d4",
4
4
  "description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
5
5
  "keywords": [
6
6
  "formal verification",
package/src/live-check.ts CHANGED
@@ -83,6 +83,7 @@ interface Check {
83
83
  firstNodes: Pool<Int32Array>;
84
84
  lastNodes: Pool<Int32Array>;
85
85
  nextSiblings: number[];
86
+ nodeIds: NodeTable;
86
87
  isDone: boolean[];
87
88
  errorNode: number | undefined;
88
89
  }
@@ -140,6 +141,26 @@ const writeToPool = <Data extends Int32Array | Uint8Array>(
140
141
 
141
142
  const NO_NODE = -1;
142
143
 
144
+ // A Map holds at most 2^24 entries, so each tableau node of a state finds its node in an
145
+ // open-addressing table of (state plus one, tableau node, node) triples.
146
+ interface NodeTable {
147
+ slots: Int32Array;
148
+ size: number;
149
+ shift: number;
150
+ }
151
+
152
+ const getNodeSlot = (table: NodeTable, state: number, tableauNode: number) => {
153
+ const mask = table.slots.length / 3 - 1;
154
+ const hash = Math.imul(Math.imul(state, 0x9e3779b1) ^ tableauNode, 0x85ebca6b) >>> table.shift;
155
+ for (let index = hash; ; index = (index + 1) & mask) {
156
+ const slot = index * 3;
157
+ const stored = table.slots[slot];
158
+ if (stored === 0 || (stored === state + 1 && table.slots[slot + 1] === tableauNode)) {
159
+ return slot;
160
+ }
161
+ }
162
+ };
163
+
143
164
  const createNodes = (length: number) => new Int32Array(length).fill(NO_NODE);
144
165
 
145
166
  const UNWRITTEN = -1;
@@ -227,6 +248,7 @@ export const createLivenessChecker = (
227
248
  firstNodes: createPool(createNodes),
228
249
  lastNodes: createPool(createNodes),
229
250
  nextSiblings: [],
251
+ nodeIds: { slots: new Int32Array(3 << 10), size: 0, shift: 22 },
230
252
  isDone: [],
231
253
  errorNode: undefined,
232
254
  }));
@@ -322,12 +344,29 @@ export const createLivenessChecker = (
322
344
  model.infinitelyOftenActions.length === 0,
323
345
  );
324
346
 
325
- const getNodeId = (check: Check, state: number, tableauNode: number) =>
326
- check.solution.tableau
327
- ? getStateNodes(check, state).find((node) => check.nodeTableaux[node] === tableauNode)
328
- : state;
347
+ const getNodeId = (check: Check, state: number, tableauNode: number) => {
348
+ if (!check.solution.tableau) return state;
349
+ const slots = check.nodeIds.slots;
350
+ const slot = getNodeSlot(check.nodeIds, state, tableauNode);
351
+ return slots[slot] === 0 ? undefined : slots[slot + 2];
352
+ };
329
353
  const recordNode = (check: Check, state: number, tableauNode: number) => {
330
354
  const node = pushNode(check, state, tableauNode);
355
+ const table = check.nodeIds;
356
+ if (++table.size * 2 > table.slots.length / 3) {
357
+ const old = table.slots;
358
+ table.slots = new Int32Array(old.length * 2);
359
+ table.shift--;
360
+ for (let slot = 0; slot < old.length; slot += 3) {
361
+ if (old[slot] !== 0) {
362
+ table.slots.set(
363
+ old.subarray(slot, slot + 3),
364
+ getNodeSlot(table, old[slot] - 1, old[slot + 1]),
365
+ );
366
+ }
367
+ }
368
+ }
369
+ table.slots.set([state + 1, tableauNode, node], getNodeSlot(table, state, tableauNode));
331
370
  const last = check.lastNodes.data[state] ?? NO_NODE;
332
371
  if (last === NO_NODE) writeToPool(check.firstNodes, state, [node]);
333
372
  else check.nextSiblings[last] = node;