stillflow.engine 0.4.9 → 0.5.0

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.
Files changed (138) hide show
  1. package/README.md +12 -30
  2. package/dist/index.cjs.js +566 -0
  3. package/dist/index.d.ts +4 -5
  4. package/dist/index.es.js +557 -0
  5. package/dist/rolldown-runtime-BW-eSwOZ.cjs +42 -0
  6. package/dist/stillflow/abstracts/meta.d.ts +1 -1
  7. package/dist/stillflow/abstracts/view.d.ts +2 -2
  8. package/dist/stillflow/compiler/compile.d.ts +5 -5
  9. package/dist/stillflow/compiler/instantiate.d.ts +2 -2
  10. package/dist/stillflow/index.d.ts +2 -2
  11. package/dist/stillflow/kernel/buffer.d.ts +1 -1
  12. package/dist/stillflow/kernel/kernel.d.ts +2 -2
  13. package/dist/stillflow/operators.d.ts +1 -1
  14. package/dist/stillflow/state.d.ts +1 -1
  15. package/dist/stillflow/stillflow.d.ts +6 -6
  16. package/dist/stillflow/variable.d.ts +2 -2
  17. package/dist/stillflow-collection/fenwick.d.ts +1 -1
  18. package/dist/stillflow-collection/flushable.d.ts +2 -2
  19. package/dist/stillflow-collection/index.d.ts +3 -3
  20. package/dist/stillflow-collection/utilities/range-fenwick-tree.d.ts +1 -1
  21. package/dist/stillflow-vite/babel-vm/abstract/binding.d.ts +4 -0
  22. package/dist/stillflow-vite/babel-vm/abstract/configurator.d.ts +7 -0
  23. package/dist/stillflow-vite/babel-vm/abstract/generator.d.ts +2 -0
  24. package/dist/stillflow-vite/babel-vm/classes/payload.d.ts +23 -0
  25. package/dist/stillflow-vite/babel-vm/index.d.ts +7 -0
  26. package/dist/stillflow-vite/babel-vm/utilities/build.d.ts +6 -0
  27. package/dist/stillflow-vite/babel-vm/utilities/create.d.ts +11 -0
  28. package/dist/stillflow-vite/dom/build-vm/build.d.ts +4 -0
  29. package/dist/stillflow-vite/dom/build-vm/build.dom.d.ts +6 -0
  30. package/dist/stillflow-vite/dom/build-vm/compile.d.ts +8 -0
  31. package/dist/stillflow-vite/dom/build-vm/markup.d.ts +7 -0
  32. package/dist/stillflow-vite/dom/build-vm/run.d.ts +12 -0
  33. package/dist/stillflow-vite/dom/build-vm/template.d.ts +14 -0
  34. package/dist/stillflow-vite/dom/build-vm/transform.d.ts +10 -0
  35. package/dist/{stillflow-adapters/dom/vm/dom.codes.d.ts → stillflow-vite/dom/directives/codes.d.ts} +1 -2
  36. package/dist/stillflow-vite/dom/directives/generators.d.ts +3 -0
  37. package/dist/stillflow-vite/dom/environment.d.ts +21 -0
  38. package/dist/stillflow-vite/dom/helpers/collectors.d.ts +9 -0
  39. package/dist/stillflow-vite/dom/helpers/extractors.d.ts +11 -0
  40. package/dist/stillflow-vite/dom/helpers/getters.d.ts +7 -0
  41. package/dist/stillflow-vite/dom/helpers/replacers.d.ts +2 -0
  42. package/dist/stillflow-vite/dom/properties/directives.d.ts +16 -0
  43. package/dist/{stillflow-adapters → stillflow-vite}/dom/properties/properties.d.ts +4 -3
  44. package/dist/{stillflow-adapters/dom/vm/dom.types.d.ts → stillflow-vite/dom/properties/types.d.ts} +2 -2
  45. package/dist/{stillflow-adapters/dom/vm/utilities/dom.delegator.d.ts → stillflow-vite/dom/utilities/delegator.d.ts} +1 -0
  46. package/dist/stillflow-vite/dom.plugin.d.ts +2 -0
  47. package/dist/{stillflow-adapters/dom → stillflow-vite/runtime}/jsx.dom.d.ts +20 -14
  48. package/dist/vite.cjs.js +18348 -0
  49. package/dist/vite.es.js +18345 -0
  50. package/dist/vite.plugin.d.ts +2 -0
  51. package/package.json +41 -29
  52. package/dist/index.js +0 -6
  53. package/dist/jsx-runtime.d.ts +0 -3
  54. package/dist/jsx-runtime.js +0 -7
  55. package/dist/stillflow/abstracts/IR.js +0 -1
  56. package/dist/stillflow/abstracts/meta.js +0 -1
  57. package/dist/stillflow/abstracts/operators.js +0 -1
  58. package/dist/stillflow/abstracts/state.js +0 -1
  59. package/dist/stillflow/abstracts/view.js +0 -1
  60. package/dist/stillflow/compiler/compile.js +0 -84
  61. package/dist/stillflow/compiler/instantiate.js +0 -40
  62. package/dist/stillflow/factories/factories.js +0 -20
  63. package/dist/stillflow/index.js +0 -3
  64. package/dist/stillflow/kernel/buffer.js +0 -16
  65. package/dist/stillflow/kernel/kernel.js +0 -44
  66. package/dist/stillflow/kernel/signal.js +0 -12
  67. package/dist/stillflow/operators.js +0 -31
  68. package/dist/stillflow/state.js +0 -12
  69. package/dist/stillflow/stillflow.js +0 -59
  70. package/dist/stillflow/tools/batcher.js +0 -21
  71. package/dist/stillflow/variable.js +0 -24
  72. package/dist/stillflow-adapters/dom/base.dom.d.ts +0 -17
  73. package/dist/stillflow-adapters/dom/base.dom.js +0 -31
  74. package/dist/stillflow-adapters/dom/description/describe.d.ts +0 -3
  75. package/dist/stillflow-adapters/dom/description/describe.js +0 -6
  76. package/dist/stillflow-adapters/dom/jsx.dom.js +0 -98
  77. package/dist/stillflow-adapters/dom/properties/properties.js +0 -1
  78. package/dist/stillflow-adapters/dom/tags.d.ts +0 -7
  79. package/dist/stillflow-adapters/dom/tags.js +0 -5
  80. package/dist/stillflow-adapters/dom/vm/compile/dom.apply.d.ts +0 -3
  81. package/dist/stillflow-adapters/dom/vm/compile/dom.apply.js +0 -10
  82. package/dist/stillflow-adapters/dom/vm/compile/dom.apply.keyed.d.ts +0 -3
  83. package/dist/stillflow-adapters/dom/vm/compile/dom.apply.keyed.js +0 -10
  84. package/dist/stillflow-adapters/dom/vm/compile/dom.compile-vm.d.ts +0 -2
  85. package/dist/stillflow-adapters/dom/vm/compile/dom.compile-vm.js +0 -204
  86. package/dist/stillflow-adapters/dom/vm/compile/dom.compile-vm.keyed.d.ts +0 -2
  87. package/dist/stillflow-adapters/dom/vm/compile/dom.compile-vm.keyed.js +0 -168
  88. package/dist/stillflow-adapters/dom/vm/compile/dom.compile.d.ts +0 -3
  89. package/dist/stillflow-adapters/dom/vm/compile/dom.compile.js +0 -77
  90. package/dist/stillflow-adapters/dom/vm/compile/dom.context.d.ts +0 -13
  91. package/dist/stillflow-adapters/dom/vm/compile/dom.context.js +0 -1
  92. package/dist/stillflow-adapters/dom/vm/compile/dom.markup.d.ts +0 -3
  93. package/dist/stillflow-adapters/dom/vm/compile/dom.markup.js +0 -32
  94. package/dist/stillflow-adapters/dom/vm/dom.codes.js +0 -1
  95. package/dist/stillflow-adapters/dom/vm/dom.directives.d.ts +0 -18
  96. package/dist/stillflow-adapters/dom/vm/dom.directives.js +0 -1
  97. package/dist/stillflow-adapters/dom/vm/dom.symbols.js +0 -18
  98. package/dist/stillflow-adapters/dom/vm/dom.template.d.ts +0 -10
  99. package/dist/stillflow-adapters/dom/vm/dom.template.js +0 -1
  100. package/dist/stillflow-adapters/dom/vm/dom.types.js +0 -1
  101. package/dist/stillflow-adapters/dom/vm/transform/dom.transform.d.ts +0 -3
  102. package/dist/stillflow-adapters/dom/vm/transform/dom.transform.js +0 -54
  103. package/dist/stillflow-adapters/dom/vm/utilities/dom.delegator.js +0 -39
  104. package/dist/stillflow-adapters/dom/vm/utilities/dom.pool.js +0 -46
  105. package/dist/stillflow-adapters/index.d.ts +0 -2
  106. package/dist/stillflow-adapters/index.js +0 -2
  107. package/dist/stillflow-collection/abstract/collection.js +0 -1
  108. package/dist/stillflow-collection/delta.js +0 -18
  109. package/dist/stillflow-collection/fenwick.js +0 -102
  110. package/dist/stillflow-collection/flushable.js +0 -70
  111. package/dist/stillflow-collection/index.js +0 -2
  112. package/dist/stillflow-collection/utilities/disjointed-set.js +0 -45
  113. package/dist/stillflow-collection/utilities/fenwick-tree.js +0 -27
  114. package/dist/stillflow-collection/utilities/interval-merger.js +0 -70
  115. package/dist/stillflow-collection/utilities/range-fenwick-tree.js +0 -28
  116. package/dist/stillflow-examples/app.js +0 -120
  117. package/dist/stillflow-examples/data.js +0 -73
  118. package/dist/stillflow-examples/test.js +0 -32
  119. package/dist/stillflow-scripts/gen-tags.d.ts +0 -1
  120. package/dist/stillflow-scripts/gen-tags.js +0 -50
  121. package/dist/stillflow-vm/abstract/config.d.ts +0 -6
  122. package/dist/stillflow-vm/abstract/config.js +0 -1
  123. package/dist/stillflow-vm/abstract/generator.d.ts +0 -1
  124. package/dist/stillflow-vm/abstract/generator.js +0 -1
  125. package/dist/stillflow-vm/abstract/target.d.ts +0 -7
  126. package/dist/stillflow-vm/abstract/target.js +0 -1
  127. package/dist/stillflow-vm/binding.d.ts +0 -4
  128. package/dist/stillflow-vm/binding.js +0 -1
  129. package/dist/stillflow-vm/create.d.ts +0 -5
  130. package/dist/stillflow-vm/create.js +0 -17
  131. package/dist/stillflow-vm/emitter.js +0 -9
  132. package/dist/stillflow-vm/index.d.ts +0 -6
  133. package/dist/stillflow-vm/index.js +0 -3
  134. package/dist/stillflow-vm/payload.d.ts +0 -9
  135. package/dist/stillflow-vm/payload.js +0 -24
  136. /package/dist/{stillflow-vm → stillflow-vite/babel-vm/classes}/emitter.d.ts +0 -0
  137. /package/dist/{stillflow-adapters/dom/vm/utilities/dom.pool.d.ts → stillflow-vite/dom/utilities/pool.d.ts} +0 -0
  138. /package/dist/{stillflow-adapters/dom/vm/dom.symbols.d.ts → stillflow-vite/dom/utilities/symbols.d.ts} +0 -0
@@ -1,32 +0,0 @@
1
- import { SF_CACHE, SF_CACHE_TEXT } from "../dom.symbols.js";
2
- function markup_template_code(node, path) {
3
- let { modifiers } = node.properties;
4
- let code = String();
5
- const has_modifiers = modifiers?.text !== undefined ||
6
- modifiers?.properties !== undefined ||
7
- modifiers?.events !== undefined ||
8
- modifiers?.iterate !== undefined ||
9
- modifiers?.conditional !== undefined;
10
- if (has_modifiers) {
11
- code += `sf_markup_path.push(root${path.map(x => `.children[${x}]`).join(String())});`;
12
- }
13
- for (let index = 0; index < node.children.length; index++) {
14
- code += markup_template_code(node.children[index], [...path, index]);
15
- }
16
- return code;
17
- }
18
- function markup_template(node) {
19
- let code = String();
20
- code += `return function(root) {`;
21
- code += `if (root.${SF_CACHE}) {`;
22
- code += `return;`;
23
- code += `}`;
24
- code += `let sf_markup_path = [];`;
25
- code += markup_template_code(node, []);
26
- code += `root.${SF_CACHE} = sf_markup_path;`;
27
- code += `root.${SF_CACHE_TEXT} = sf_markup_path.map(node => node.firstChild);`;
28
- code += `}`;
29
- const generator = new Function(code);
30
- return generator();
31
- }
32
- export { markup_template };
@@ -1 +0,0 @@
1
- export {};
@@ -1,18 +0,0 @@
1
- import * as collection from "../../../stillflow-collection/index.js";
2
- import * as vm from '../../../stillflow-vm/index.js';
3
- import { AnyDOM } from "./dom.types.js";
4
- export type Directives<V, K extends keyof HTMLElementTagNameMap = any> = Partial<{
5
- vm: (context: V) => vm.Target<unknown, V>;
6
- text: (context: V) => string;
7
- events: Partial<{
8
- [L in keyof HTMLElementEventMap]: (event: HTMLElementEventMap[L], context: V) => void;
9
- }>;
10
- conditional: (context: V) => boolean;
11
- properties: Partial<{
12
- [L in keyof HTMLElementTagNameMap[K]]: (context: V) => string;
13
- }>;
14
- iterate: {
15
- select: <W>(context: V) => collection.Flushable<W>;
16
- each: () => AnyDOM<any>;
17
- };
18
- }>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,18 +0,0 @@
1
- const EMPTY = () => String();
2
- export const SF_LISTENED = '__stillflow_listened__';
3
- export const SF_CONTEXT = '__stillflow_context__';
4
- export const SF_CACHE_TEXT = '__stillflow_cache_text__';
5
- export const SF_CACHE = '__stillflow_cache__';
6
- export const SF_HANDLERS = `__stillflow_handlers__`;
7
- export const SF_ANY = new Proxy({}, {
8
- get: (_, property) => {
9
- if (property === Symbol.toPrimitive || property === 'valueOf') {
10
- return EMPTY;
11
- }
12
- if (property === Symbol.iterator) {
13
- return [][Symbol.iterator];
14
- }
15
- return SF_ANY;
16
- },
17
- apply: () => SF_ANY
18
- });
@@ -1,10 +0,0 @@
1
- import { AnyDOM } from "./dom.types.js";
2
- export interface Template {
3
- node: AnyDOM<any>;
4
- root: HTMLElement;
5
- nodes: AnyDOM<any>[];
6
- bytecode: ArrayLike<number>;
7
- strings: string[];
8
- functions: Function[];
9
- templates: Template[];
10
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { DOM } from "../dom.types.js";
2
- declare function transform<V, K extends keyof HTMLElementTagNameMap>(description: DOM<V, K>): HTMLElementTagNameMap[K];
3
- export { transform };
@@ -1,54 +0,0 @@
1
- function transform_code(description, payloads, depth = 1) {
2
- let { name, text, properties, styles, events, modifiers } = description.properties;
3
- let code = String();
4
- styles = styles || Object.create(null);
5
- events = events || Object.create(null);
6
- properties = properties || Object.create(null);
7
- const nameIndex = payloads.length;
8
- payloads.push(name);
9
- code += `let sf_child_node_${depth} = document.createElement(p${nameIndex});`;
10
- if (text !== undefined || modifiers?.text !== undefined) {
11
- const textIndex = payloads.length;
12
- payloads.push(text);
13
- code += `let sf_text_node_${depth} = document.createTextNode(p${textIndex});`;
14
- code += `sf_child_node_${depth}.appendChild(sf_text_node_${depth});`;
15
- }
16
- code += `sf_child_node_${depth - 1}.appendChild(sf_child_node_${depth});`;
17
- for (const key in styles) {
18
- const keyIndex = payloads.length;
19
- payloads.push(key);
20
- const styleIndex = payloads.length;
21
- payloads.push(styles[key]);
22
- code += `sf_child_node_${depth}.style[p${keyIndex}] = p${styleIndex};`;
23
- }
24
- for (const key in events) {
25
- const pIndex = payloads.length;
26
- const event = events[key];
27
- payloads.push(event);
28
- code += `sf_child_node_${depth}.addEventListener("${key}", p${pIndex});`;
29
- }
30
- for (const key in properties) {
31
- const keyIndex = payloads.length;
32
- payloads.push(key);
33
- const propertyIndex = payloads.length;
34
- const property = properties[key];
35
- payloads.push(property);
36
- code += `sf_child_node_${depth}[p${keyIndex}] = p${propertyIndex};`;
37
- }
38
- for (const child of description.children) {
39
- code += `{${transform_code(child, payloads, depth + 1)}}`;
40
- }
41
- return code;
42
- }
43
- function transform(description) {
44
- const payloads = [];
45
- const fragment = document.createDocumentFragment();
46
- let code = String();
47
- code += `let sf_child_node_0 = root;`;
48
- code += transform_code(description, payloads);
49
- code += `return sf_child_node_1; `;
50
- const transformer = new Function(...payloads.map((_, id) => `p${id} `), 'root', code);
51
- const root = transformer(...payloads, fragment);
52
- return root;
53
- }
54
- export { transform };
@@ -1,39 +0,0 @@
1
- import { SF_CONTEXT, SF_HANDLERS } from "../dom.symbols.js";
2
- export class EventDelegator {
3
- _actives = new Set();
4
- ensure(type) {
5
- if (this._actives.has(type)) {
6
- return;
7
- }
8
- this._actives.add(type);
9
- document.body.addEventListener(type, event => {
10
- let target = event.target;
11
- while (target && target !== document.body) {
12
- const listeners = target[SF_HANDLERS];
13
- if (listeners !== undefined) {
14
- const callback = listeners[type];
15
- callback?.(event, target[SF_CONTEXT]);
16
- if (event.cancelBubble) {
17
- break;
18
- }
19
- }
20
- target = target.parentElement;
21
- }
22
- });
23
- }
24
- remove(root) {
25
- const element = root;
26
- element[SF_CONTEXT] = null;
27
- element[SF_HANDLERS] = undefined;
28
- }
29
- add(root, type, listener) {
30
- const element = root;
31
- if (element[SF_HANDLERS] !== undefined) {
32
- return;
33
- }
34
- const listeners = Object.create(null);
35
- listeners[type] = listener;
36
- element[SF_HANDLERS] = listeners;
37
- this.ensure(type);
38
- }
39
- }
@@ -1,46 +0,0 @@
1
- import { SF_CONTEXT, SF_LISTENED } from "../dom.symbols.js";
2
- export class Pool {
3
- static TIME_TO_EVICT = 2;
4
- _hots = [];
5
- _colds = [];
6
- _frame = 0;
7
- evict() {
8
- for (let id = this._hots.length - 1; id >= 0; id--) {
9
- const hot = this._hots[id];
10
- if (this._frame - hot.frame >= Pool.TIME_TO_EVICT) {
11
- const element = hot.root;
12
- element[SF_CONTEXT] = null;
13
- element[SF_LISTENED] = false;
14
- this._colds.push(new WeakRef(hot.root));
15
- }
16
- }
17
- this._hots = this._hots.filter(hot => this._frame - hot.frame < Pool.TIME_TO_EVICT);
18
- }
19
- retrieve() {
20
- if (this._hots.length <= 0) {
21
- while (this._colds.length > 0) {
22
- const cold = this._colds.pop();
23
- const element = cold.deref();
24
- if (element !== undefined) {
25
- this._hots.push({ root: element, frame: this._frame });
26
- }
27
- }
28
- }
29
- }
30
- get() {
31
- this.retrieve();
32
- const element = this._hots.pop();
33
- if (element === undefined) {
34
- return undefined;
35
- }
36
- element.frame = this._frame;
37
- return element.root;
38
- }
39
- add(root) {
40
- this._hots.push({ root, frame: this._frame });
41
- }
42
- tick() {
43
- this.evict();
44
- this._frame++;
45
- }
46
- }
@@ -1,2 +0,0 @@
1
- export { JSXDOM_REGISTRY as jsxdom } from './dom/jsx.dom.js';
2
- export { DOM_REGISTRY as dom } from './dom/base.dom.js';
@@ -1,2 +0,0 @@
1
- export { JSXDOM_REGISTRY as jsxdom } from './dom/jsx.dom.js';
2
- export { DOM_REGISTRY as dom } from './dom/base.dom.js';
@@ -1 +0,0 @@
1
- export {};
@@ -1,18 +0,0 @@
1
- export function clear_delta(delta) {
2
- delta.addes = 0;
3
- delta.swaps.clear();
4
- delta.updates.clear();
5
- delta.removes.clear();
6
- delta.replaces = false;
7
- delta.clears = false;
8
- }
9
- export function copy_delta(delta) {
10
- return {
11
- addes: delta.addes,
12
- swaps: new Map(delta.swaps),
13
- updates: new Set(delta.updates),
14
- removes: new Set(delta.removes),
15
- replaces: delta.replaces,
16
- clears: delta.clears
17
- };
18
- }
@@ -1,102 +0,0 @@
1
- import { Fenwick } from "./utilities/fenwick-tree.js";
2
- export class FenwickCollection {
3
- _size;
4
- static GROW = 2;
5
- static REMOVE_COUNT = 1;
6
- _removes = new Set();
7
- _tree;
8
- _shift = 0;
9
- _data;
10
- constructor(_size = 1) {
11
- this._size = _size;
12
- this._data = new Array();
13
- this._tree = new Fenwick(this._size);
14
- }
15
- at(index) {
16
- return this._data[index + this._shift];
17
- }
18
- map(id) {
19
- let physical_index = 0;
20
- let step = 1;
21
- // Находим наибольшую степень двойки <= size
22
- while (step * 2 <= this._size) {
23
- step *= 2;
24
- }
25
- for (let index = step; index > 0; index >>= 1) {
26
- const next = physical_index + index;
27
- // Не выходим за границы данных
28
- if (next <= this._data.length) {
29
- // count(next) теперь корректен благодаря двойному Фенвику
30
- const removed = this._tree.count(next);
31
- const logical = next - removed;
32
- if (logical <= id) {
33
- physical_index = next;
34
- }
35
- }
36
- }
37
- return physical_index + this._shift;
38
- }
39
- set(index, value) {
40
- this._data[index + this._shift] = value;
41
- }
42
- add(value) {
43
- const index = this._data.push(value);
44
- if (index >= this._size) {
45
- this._tree = this._tree.grow(this._size);
46
- this._size *= FenwickCollection.GROW;
47
- }
48
- }
49
- swap(i, j) {
50
- const temporary = this.at(i);
51
- this.set(i, this.at(j));
52
- this.set(j, temporary);
53
- }
54
- attach(value) {
55
- this._data = this._data.concat(value);
56
- const index = this._data.length;
57
- while (index >= this._size) {
58
- this._tree = this._tree.grow(this._size);
59
- this._size *= FenwickCollection.GROW;
60
- }
61
- }
62
- mutate(index, mutator) {
63
- mutator(this.at(index));
64
- }
65
- shrink() {
66
- this._data.splice(0, this._shift);
67
- this._shift = 0;
68
- const removes = Array.from(this._removes).sort((i, j) => j - i);
69
- for (const id of removes) {
70
- this._data.splice(id, 1);
71
- }
72
- this._removes.clear();
73
- this._size = this._data.length + 1;
74
- this._tree = new Fenwick(this._size);
75
- }
76
- mark_cleared() {
77
- this._shift = this._data.length;
78
- this._size = this._data.length + 1;
79
- this._removes.clear();
80
- this._tree = new Fenwick(this._size);
81
- }
82
- mark_removed(index) {
83
- this.mark_removed_range(index, index);
84
- }
85
- mark_removed_range(left, right) {
86
- if (left > right) {
87
- return;
88
- }
89
- for (let index = left; index <= right; index++) {
90
- if (this._removes.has(index) === false) {
91
- this._tree.add(index, FenwickCollection.REMOVE_COUNT);
92
- this._removes.add(index);
93
- }
94
- }
95
- }
96
- get size() {
97
- return this._data.length - this._shift - this._tree.count(this._data.length - this._shift);
98
- }
99
- get capacity() {
100
- return this._size;
101
- }
102
- }
@@ -1,70 +0,0 @@
1
- import { clear_delta, copy_delta } from "./delta.js";
2
- export class FlushableCollection {
3
- _base;
4
- _delta = {
5
- addes: 0,
6
- swaps: new Map(),
7
- updates: new Set(),
8
- removes: new Set(),
9
- replaces: false,
10
- clears: false
11
- };
12
- constructor(_base) {
13
- this._base = _base;
14
- }
15
- at(index) {
16
- return this._base.at(index);
17
- }
18
- map(id) {
19
- return this._base.map(id);
20
- }
21
- add(value) {
22
- this._delta.addes++;
23
- this._base.add(value);
24
- }
25
- set(index, value) {
26
- this._delta.updates.add(index);
27
- this._base.set(index, value);
28
- }
29
- swap(i, j) {
30
- this._delta.swaps.set(i, j);
31
- this._base.swap(i, j);
32
- }
33
- attach(value) {
34
- this._delta.addes += value.length;
35
- this._base.attach(value);
36
- }
37
- mutate(index, mutator) {
38
- this._delta.updates.add(index);
39
- this._base.mutate(index, mutator);
40
- }
41
- shrink() {
42
- this._base.shrink();
43
- }
44
- mark_cleared() {
45
- this._delta.clears = true;
46
- this._base.mark_cleared();
47
- }
48
- mark_removed(index) {
49
- this._delta.removes.add(index);
50
- this._base.mark_removed(index);
51
- }
52
- mark_removed_range(left, right) {
53
- for (let index = left; index <= right; index++) {
54
- this._delta.removes.add(index);
55
- }
56
- this._base.mark_removed_range(left, right);
57
- }
58
- flush() {
59
- this._delta.replaces = (this._delta.addes > 0) && (this._delta.clears);
60
- const delta = copy_delta(this._delta);
61
- clear_delta(this._delta);
62
- return delta;
63
- }
64
- get size() {
65
- return this._base.size;
66
- }
67
- get capacity() {
68
- return this._base.capacity;
69
- }
70
- }
@@ -1,2 +0,0 @@
1
- export { FlushableCollection as Flushable } from "./flushable.js";
2
- export { FenwickCollection as Fenwick } from "./fenwick.js";
@@ -1,45 +0,0 @@
1
- export class DSU {
2
- _size;
3
- _parent;
4
- constructor(_size, old = new Int32Array(0)) {
5
- this._size = _size;
6
- this._parent = new Int32Array(this._size + 1);
7
- this._parent.set(old);
8
- for (let index = old.length; index <= this._size; index++) {
9
- this._parent[index] = index;
10
- }
11
- }
12
- find(index) {
13
- if (index > this._size) {
14
- throw new Error(`Index ${index} out of bounds (size: ${this._size})`);
15
- }
16
- let root = index;
17
- while (this._parent[root] !== root) {
18
- root = this._parent[root];
19
- }
20
- let current = index;
21
- while (this._parent[current] !== root) {
22
- const next = this._parent[current];
23
- this._parent[current] = root;
24
- current = next;
25
- }
26
- return root;
27
- }
28
- mark(left, right) {
29
- let current = this.find(left);
30
- while (current <= right) {
31
- const next = this.find(current + 1);
32
- this._parent[current] = next;
33
- current = next;
34
- }
35
- }
36
- is_marked(index) {
37
- return this.find(index) !== index;
38
- }
39
- grow(length) {
40
- return new DSU(this._size + length, this._parent);
41
- }
42
- get size() {
43
- return this._size;
44
- }
45
- }
@@ -1,27 +0,0 @@
1
- export class Fenwick {
2
- _size;
3
- _tree;
4
- constructor(_size, old = new Int32Array(0)) {
5
- this._size = _size;
6
- this._tree = new Int32Array(this._size + 1);
7
- this._tree.set(old);
8
- }
9
- add(start, delta) {
10
- for (let index = start + 1; index <= this._size; index += index & -index) {
11
- this._tree[index] += delta;
12
- }
13
- }
14
- count(end) {
15
- let amount = 0;
16
- for (let index = end + 1; index > 0; index -= index & -index) {
17
- amount += this._tree[index];
18
- }
19
- return amount;
20
- }
21
- grow(length) {
22
- return new Fenwick(this._size + length, this._tree);
23
- }
24
- get size() {
25
- return this._size;
26
- }
27
- }
@@ -1,70 +0,0 @@
1
- export class IntervalMerger {
2
- _ranges = [];
3
- add(left, right) {
4
- if (left > right) {
5
- return;
6
- }
7
- if (this._ranges.length <= 0) {
8
- this._ranges.push([left, right]);
9
- return;
10
- }
11
- const intervals = [];
12
- let new_interval = [left, right];
13
- let inserted = false;
14
- for (const range of this._ranges) {
15
- if (range[1] < new_interval[0] - 1) {
16
- intervals.push(range);
17
- }
18
- else if (range[0] > new_interval[1] + 1) {
19
- if (inserted === false) {
20
- intervals.push(new_interval);
21
- inserted = true;
22
- }
23
- intervals.push(range);
24
- }
25
- else {
26
- new_interval[0] = Math.min(new_interval[0], range[0]);
27
- new_interval[1] = Math.max(new_interval[1], range[1]);
28
- }
29
- }
30
- if (inserted === false) {
31
- intervals.push(new_interval);
32
- }
33
- this._ranges = intervals;
34
- }
35
- find_overlaps(left, right) {
36
- const overlaps = [];
37
- if (this._ranges.length <= 0) {
38
- return overlaps;
39
- }
40
- let low = 0;
41
- let high = this._ranges.length - 1;
42
- let start_index = this._ranges.length;
43
- while (low <= high) {
44
- const middle = (low + high) >> 1;
45
- if (this._ranges[middle][1] >= left) {
46
- start_index = middle;
47
- high = middle - 1;
48
- }
49
- else {
50
- low = middle + 1;
51
- }
52
- }
53
- for (let index = start_index; index < this._ranges.length; index++) {
54
- const [ol, or] = this._ranges[index];
55
- if (ol > right) {
56
- break;
57
- }
58
- if (or >= left && ol <= right) {
59
- overlaps.push([ol, or]);
60
- }
61
- }
62
- return overlaps;
63
- }
64
- clear() {
65
- this._ranges.length = 0;
66
- }
67
- get ranges() {
68
- return this._ranges;
69
- }
70
- }
@@ -1,28 +0,0 @@
1
- import { Fenwick } from "./fenwick-tree.js";
2
- export class RangeFenwick {
3
- _start;
4
- _end;
5
- _size = 0;
6
- constructor(size, _start = new Fenwick(size), _end = new Fenwick(size)) {
7
- this._start = _start;
8
- this._end = _end;
9
- this._size = size;
10
- }
11
- add(left, right, delta = 1) {
12
- this._start.add(left, delta);
13
- this._start.add(right + 1, -delta);
14
- this._end.add(left, delta * (left - 1));
15
- this._end.add(right + 1, -delta * right);
16
- }
17
- count(index) {
18
- const amount_0 = this._start.count(index);
19
- const amount_1 = this._end.count(index);
20
- return amount_0 * index - amount_1;
21
- }
22
- grow(length) {
23
- return new RangeFenwick(this._size + length, this._start.grow(length), this._end.grow(length));
24
- }
25
- get size() {
26
- return this._size;
27
- }
28
- }