stillflow.engine 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +114 -2
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8 -0
- package/dist/stillflow/abstracts/IR.d.ts +7 -0
- package/dist/stillflow/abstracts/IR.js +1 -0
- package/dist/stillflow/abstracts/meta.d.ts +8 -0
- package/dist/stillflow/abstracts/meta.js +1 -0
- package/dist/stillflow/abstracts/operators.d.ts +22 -0
- package/dist/stillflow/abstracts/operators.js +1 -0
- package/dist/stillflow/abstracts/state.d.ts +7 -0
- package/dist/stillflow/abstracts/state.js +1 -0
- package/dist/stillflow/abstracts/view.d.ts +8 -0
- package/dist/stillflow/abstracts/view.js +1 -0
- package/dist/stillflow/compiler/compile.d.ts +11 -0
- package/dist/stillflow/compiler/compile.js +84 -0
- package/dist/stillflow/compiler/instantiate.d.ts +3 -0
- package/dist/stillflow/compiler/instantiate.js +40 -0
- package/dist/stillflow/factories/factories.d.ts +10 -0
- package/dist/stillflow/factories/factories.js +20 -0
- package/dist/stillflow/kernel/buffer.d.ts +9 -0
- package/dist/stillflow/kernel/buffer.js +13 -0
- package/dist/stillflow/kernel/kernel.d.ts +20 -0
- package/dist/stillflow/kernel/kernel.js +44 -0
- package/dist/stillflow/kernel/signal.d.ts +5 -0
- package/dist/stillflow/kernel/signal.js +12 -0
- package/dist/stillflow/operators.d.ts +15 -0
- package/dist/stillflow/operators.js +31 -0
- package/dist/stillflow/state.d.ts +9 -0
- package/dist/stillflow/state.js +12 -0
- package/dist/stillflow/stillflow.d.ts +27 -0
- package/dist/stillflow/stillflow.js +59 -0
- package/dist/stillflow/tools/batcher.d.ts +8 -0
- package/dist/stillflow/tools/batcher.js +17 -0
- package/dist/stillflow/variable.d.ts +12 -0
- package/dist/stillflow/variable.js +24 -0
- package/dist/stillflow-adapters/binding.d.ts +4 -0
- package/dist/stillflow-adapters/binding.js +1 -0
- package/dist/stillflow-adapters/dom/compiler/apply.d.ts +16 -0
- package/dist/stillflow-adapters/dom/compiler/apply.js +212 -0
- package/dist/stillflow-adapters/dom/compiler/compile.d.ts +18 -0
- package/dist/stillflow-adapters/dom/compiler/compile.js +47 -0
- package/dist/stillflow-adapters/dom/compiler/transform.d.ts +2 -0
- package/dist/stillflow-adapters/dom/compiler/transform.js +41 -0
- package/dist/stillflow-adapters/dom/description/describe.d.ts +3 -0
- package/dist/stillflow-adapters/dom/description/describe.js +6 -0
- package/dist/stillflow-adapters/dom/dom.d.ts +4 -0
- package/dist/stillflow-adapters/dom/dom.js +1 -0
- package/dist/stillflow-adapters/dom/index.d.ts +15 -0
- package/dist/stillflow-adapters/dom/index.js +22 -0
- package/dist/stillflow-adapters/dom/jsx.dom.d.ts +32 -0
- package/dist/stillflow-adapters/dom/jsx.dom.js +77 -0
- package/dist/stillflow-adapters/dom/properties/modifiers.d.ts +17 -0
- package/dist/stillflow-adapters/dom/properties/modifiers.js +1 -0
- package/dist/stillflow-adapters/dom/properties/properties.d.ts +15 -0
- package/dist/stillflow-adapters/dom/properties/properties.js +1 -0
- package/dist/stillflow-adapters/dom/tags.d.ts +7 -0
- package/dist/stillflow-adapters/dom/tags.js +5 -0
- package/dist/stillflow-adapters/index.d.ts +3 -0
- package/dist/stillflow-adapters/index.js +3 -0
- package/dist/stillflow-adapters/runtime/jsx.runtime.d.ts +2 -0
- package/dist/stillflow-adapters/runtime/jsx.runtime.js +3 -0
- package/dist/stillflow-collection/abstract/collection.d.ts +15 -0
- package/dist/stillflow-collection/abstract/collection.js +1 -0
- package/dist/stillflow-collection/delta.d.ts +10 -0
- package/dist/stillflow-collection/delta.js +18 -0
- package/dist/stillflow-collection/fenwick.d.ts +24 -0
- package/dist/stillflow-collection/fenwick.js +102 -0
- package/dist/stillflow-collection/flushable.d.ts +21 -0
- package/dist/stillflow-collection/flushable.js +70 -0
- package/dist/stillflow-collection/utilities/disjointed-set.d.ts +10 -0
- package/dist/stillflow-collection/utilities/disjointed-set.js +45 -0
- package/dist/stillflow-collection/utilities/fenwick-tree.d.ts +9 -0
- package/dist/stillflow-collection/utilities/fenwick-tree.js +27 -0
- package/dist/stillflow-collection/utilities/interval-merger.d.ts +7 -0
- package/dist/stillflow-collection/utilities/interval-merger.js +70 -0
- package/dist/stillflow-collection/utilities/range-fenwick-tree.d.ts +11 -0
- package/dist/stillflow-collection/utilities/range-fenwick-tree.js +28 -0
- package/dist/stillflow-examples/app.d.ts +1 -0
- package/dist/stillflow-examples/app.js +140 -0
- package/dist/stillflow-examples/data.d.ts +5 -0
- package/dist/stillflow-examples/data.js +73 -0
- package/dist/stillflow-examples/test.d.ts +1 -0
- package/dist/stillflow-examples/test.js +35 -0
- package/dist/stillflow-scripts/gen-tags.d.ts +1 -0
- package/dist/stillflow-scripts/gen-tags.js +50 -0
- package/dist/stillflow-vm/analyze.d.ts +7 -0
- package/dist/stillflow-vm/analyze.js +22 -0
- package/dist/stillflow-vm/buffer.d.ts +1 -0
- package/dist/stillflow-vm/buffer.js +1 -0
- package/dist/stillflow-vm/instruction.d.ts +1 -0
- package/dist/stillflow-vm/instruction.js +1 -0
- package/dist/stillflow-vm/pool.d.ts +1 -0
- package/dist/stillflow-vm/pool.js +1 -0
- package/dist/stillflow-vm/resources.d.ts +14 -0
- package/dist/stillflow-vm/resources.js +16 -0
- package/package.json +38 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Modifiers } from "./modifiers.js";
|
|
2
|
+
export type Properties<Context, Tag extends keyof HTMLElementTagNameMap> = Partial<{
|
|
3
|
+
name: Tag;
|
|
4
|
+
text: string;
|
|
5
|
+
events: Partial<{
|
|
6
|
+
[L in keyof HTMLElementEventMap]: (event: HTMLElementEventMap[L], context: Context) => void;
|
|
7
|
+
}>;
|
|
8
|
+
properties: Partial<{
|
|
9
|
+
[L in keyof Omit<HTMLElementTagNameMap[Tag], 'style'>]: HTMLElementTagNameMap[Tag][L];
|
|
10
|
+
}>;
|
|
11
|
+
modifiers: Partial<Modifiers<Context, Tag>>;
|
|
12
|
+
styles: Partial<{
|
|
13
|
+
[L in keyof HTMLElementTagNameMap[Tag]['style']]: HTMLElementTagNameMap[Tag]['style'][L];
|
|
14
|
+
}>;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const HTML_TAGS: readonly ["a", "abbr", "address", "area", "article", "aside", "audio", "b", "base", "bdi", "bdo", "blockquote", "body", "br", "button", "canvas", "caption", "cite", "code", "col", "colgroup", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "iframe", "img", "input", "ins", "kbd", "label", "legend", "li", "link", "main", "map", "mark", "menu", "meta", "meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "search", "section", "select", "slot", "small", "source", "span", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "u", "ul", "var", "video", "wbr"];
|
|
2
|
+
export declare const SVG_TAGS: readonly ["a", "animate", "animateMotion", "animateTransform", "circle", "clipPath", "defs", "desc", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "foreignObject", "g", "image", "line", "linearGradient", "marker", "mask", "metadata", "mpath", "path", "pattern", "polygon", "polyline", "radialGradient", "rect", "script", "set", "stop", "style", "svg", "switch", "symbol", "text", "textPath", "title", "tspan", "use", "view"];
|
|
3
|
+
export declare const MATH_TAGS: readonly ["a", "annotation", "annotation-xml", "maction", "math", "merror", "mfrac", "mi", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mprescripts", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msubsup", "msup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "semantics"];
|
|
4
|
+
export type HTMLTag = typeof HTML_TAGS[number];
|
|
5
|
+
export type SVGTag = typeof SVG_TAGS[number];
|
|
6
|
+
export type MathTag = typeof MATH_TAGS[number];
|
|
7
|
+
export type Tag = HTMLTag | SVGTag | MathTag;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/gen-tags.ts. Do not edit.
|
|
2
|
+
// Source: typescript/lib/lib.dom.d.ts
|
|
3
|
+
export const HTML_TAGS = ["a", "abbr", "address", "area", "article", "aside", "audio", "b", "base", "bdi", "bdo", "blockquote", "body", "br", "button", "canvas", "caption", "cite", "code", "col", "colgroup", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "iframe", "img", "input", "ins", "kbd", "label", "legend", "li", "link", "main", "map", "mark", "menu", "meta", "meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "search", "section", "select", "slot", "small", "source", "span", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "u", "ul", "var", "video", "wbr"];
|
|
4
|
+
export const SVG_TAGS = ["a", "animate", "animateMotion", "animateTransform", "circle", "clipPath", "defs", "desc", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "foreignObject", "g", "image", "line", "linearGradient", "marker", "mask", "metadata", "mpath", "path", "pattern", "polygon", "polyline", "radialGradient", "rect", "script", "set", "stop", "style", "svg", "switch", "symbol", "text", "textPath", "title", "tspan", "use", "view"];
|
|
5
|
+
export const MATH_TAGS = ["a", "annotation", "annotation-xml", "maction", "math", "merror", "mfrac", "mi", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mprescripts", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msubsup", "msup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "semantics"];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface AbstractCollection<T> {
|
|
2
|
+
at(index: number): T;
|
|
3
|
+
map(id: number): number;
|
|
4
|
+
add(value: T): void;
|
|
5
|
+
set(index: number, value: T): void;
|
|
6
|
+
swap(i: number, j: number): void;
|
|
7
|
+
attach(value: T[]): void;
|
|
8
|
+
mutate(index: number, mutator: (value: T) => void): void;
|
|
9
|
+
shrink(): void;
|
|
10
|
+
mark_cleared(): void;
|
|
11
|
+
mark_removed(index: number): void;
|
|
12
|
+
mark_removed_range(left: number, right: number): void;
|
|
13
|
+
get size(): number;
|
|
14
|
+
get capacity(): number;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type Delta = {
|
|
2
|
+
addes: number;
|
|
3
|
+
swaps: Map<number, number>;
|
|
4
|
+
updates: Set<number>;
|
|
5
|
+
removes: Set<number>;
|
|
6
|
+
replaces: boolean;
|
|
7
|
+
clears: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function clear_delta(delta: Delta): void;
|
|
10
|
+
export declare function copy_delta(delta: Delta): Delta;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AbstractCollection } from "./abstract/collection.js";
|
|
2
|
+
export declare class FenwickCollection<T> implements AbstractCollection<T> {
|
|
3
|
+
private _size;
|
|
4
|
+
private static GROW;
|
|
5
|
+
private static REMOVE_COUNT;
|
|
6
|
+
private _removes;
|
|
7
|
+
private _tree;
|
|
8
|
+
private _shift;
|
|
9
|
+
private _data;
|
|
10
|
+
constructor(_size?: number);
|
|
11
|
+
at(index: number): T;
|
|
12
|
+
map(id: number): number;
|
|
13
|
+
set(index: number, value: T): void;
|
|
14
|
+
add(value: T): void;
|
|
15
|
+
swap(i: number, j: number): void;
|
|
16
|
+
attach(value: T[]): void;
|
|
17
|
+
mutate(index: number, mutator: (value: T) => void): void;
|
|
18
|
+
shrink(): void;
|
|
19
|
+
mark_cleared(): void;
|
|
20
|
+
mark_removed(index: number): void;
|
|
21
|
+
mark_removed_range(left: number, right: number): void;
|
|
22
|
+
get size(): number;
|
|
23
|
+
get capacity(): number;
|
|
24
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AbstractCollection } from "./abstract/collection.js";
|
|
2
|
+
import { Delta } from "./delta.js";
|
|
3
|
+
export declare class FlushableCollection<T> implements AbstractCollection<T> {
|
|
4
|
+
private _base;
|
|
5
|
+
private _delta;
|
|
6
|
+
constructor(_base: AbstractCollection<T>);
|
|
7
|
+
at(index: number): T;
|
|
8
|
+
map(id: number): number;
|
|
9
|
+
add(value: T): void;
|
|
10
|
+
set(index: number, value: T): void;
|
|
11
|
+
swap(i: number, j: number): void;
|
|
12
|
+
attach(value: T[]): void;
|
|
13
|
+
mutate(index: number, mutator: (value: T) => void): void;
|
|
14
|
+
shrink(): void;
|
|
15
|
+
mark_cleared(): void;
|
|
16
|
+
mark_removed(index: number): void;
|
|
17
|
+
mark_removed_range(left: number, right: number): void;
|
|
18
|
+
flush(): Delta;
|
|
19
|
+
get size(): number;
|
|
20
|
+
get capacity(): number;
|
|
21
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class DSU {
|
|
2
|
+
private _size;
|
|
3
|
+
private _parent;
|
|
4
|
+
constructor(_size: number, old?: Int32Array);
|
|
5
|
+
find(index: number): number;
|
|
6
|
+
mark(left: number, right: number): void;
|
|
7
|
+
is_marked(index: number): boolean;
|
|
8
|
+
grow(length: number): DSU;
|
|
9
|
+
get size(): number;
|
|
10
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Fenwick } from "./fenwick-tree.js";
|
|
2
|
+
export declare class RangeFenwick {
|
|
3
|
+
private _start;
|
|
4
|
+
private _end;
|
|
5
|
+
private _size;
|
|
6
|
+
constructor(size: number, _start?: Fenwick, _end?: Fenwick);
|
|
7
|
+
add(left: number, right: number, delta?: number): void;
|
|
8
|
+
count(index: number): number;
|
|
9
|
+
grow(length: number): RangeFenwick;
|
|
10
|
+
get size(): number;
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|