@vworlds/vecs 1.0.10 → 1.0.12
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/.husky/pre-commit +1 -0
- package/README.md +299 -228
- package/dist/command.d.ts +1 -46
- package/dist/component.d.ts +51 -59
- package/dist/component.js +31 -25
- package/dist/component.js.map +1 -1
- package/dist/dsl.d.ts +34 -26
- package/dist/dsl.js +46 -20
- package/dist/dsl.js.map +1 -1
- package/dist/entity.d.ts +96 -106
- package/dist/entity.js +261 -190
- package/dist/entity.js.map +1 -1
- package/dist/filter.d.ts +31 -23
- package/dist/filter.js +24 -17
- package/dist/filter.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/package.json +3 -1
- package/dist/phase.d.ts +12 -30
- package/dist/phase.js +11 -10
- package/dist/phase.js.map +1 -1
- package/dist/query.d.ts +107 -144
- package/dist/query.js +200 -169
- package/dist/query.js.map +1 -1
- package/dist/system.d.ts +170 -86
- package/dist/system.js +253 -114
- package/dist/system.js.map +1 -1
- package/dist/timer.d.ts +50 -0
- package/dist/timer.js +154 -0
- package/dist/timer.js.map +1 -0
- package/dist/util/array_map.d.ts +4 -55
- package/dist/util/array_map.js +35 -37
- package/dist/util/array_map.js.map +1 -1
- package/dist/util/bitset.d.ts +40 -50
- package/dist/util/bitset.js +76 -62
- package/dist/util/bitset.js.map +1 -1
- package/dist/util/events.d.ts +14 -18
- package/dist/util/events.js +24 -3
- package/dist/util/events.js.map +1 -1
- package/dist/util/ordered_set.d.ts +1 -17
- package/dist/util/ordered_set.js +74 -25
- package/dist/util/ordered_set.js.map +1 -1
- package/dist/world.d.ts +230 -218
- package/dist/world.js +422 -327
- package/dist/world.js.map +1 -1
- package/eslint-rules/internal-underscore.js +60 -0
- package/eslint.config.js +5 -0
- package/package.json +3 -1
package/dist/util/bitset.js
CHANGED
|
@@ -2,53 +2,27 @@
|
|
|
2
2
|
* A compact, growable set of non-negative integers backed by an array of
|
|
3
3
|
* 32-bit words.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* ids attached to an entity) and
|
|
7
|
-
*
|
|
5
|
+
* `Bitset` is the data structure the ECS uses to represent entity archetypes
|
|
6
|
+
* (the set of component type ids attached to an entity) and watchlists
|
|
7
|
+
* (the set of component types a query reacts to).
|
|
8
|
+
*
|
|
9
|
+
* It is exported in the public API so component data can use it for
|
|
10
|
+
* compact bit-flag fields:
|
|
8
11
|
*
|
|
9
12
|
* ```ts
|
|
10
13
|
* class Tags extends Component {
|
|
11
|
-
* tags
|
|
12
|
-
* oldTags = new Bitset();
|
|
14
|
+
* tags = new Bitset();
|
|
13
15
|
* }
|
|
14
16
|
*
|
|
15
|
-
*
|
|
17
|
+
* tags.tags.add(TAG_VISIBLE);
|
|
16
18
|
* if (tags.tags.has(TAG_VISIBLE)) { ... }
|
|
17
19
|
* ```
|
|
18
20
|
*/
|
|
19
21
|
export class Bitset {
|
|
20
22
|
constructor() {
|
|
23
|
+
/** @internal Underlying word storage; exposed for tests. */
|
|
21
24
|
this._bits = [];
|
|
22
25
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Return `true` if this bitset and `other` have exactly the same bits set.
|
|
25
|
-
*/
|
|
26
|
-
equal(other) {
|
|
27
|
-
return (this._bits.length === other._bits.length && this._bits.every((v, i) => other._bits[i] === v));
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* OR the given `bitmask` word into the word at position `arrayIndex`.
|
|
31
|
-
*
|
|
32
|
-
* @internal Low-level bulk operation; prefer {@link add} for single bits.
|
|
33
|
-
*/
|
|
34
|
-
addIndexBitmask(arrayIndex, bitmask) {
|
|
35
|
-
this._bits[arrayIndex] |= bitmask;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Replace the word at position `arrayIndex` with `bitmask`.
|
|
39
|
-
*
|
|
40
|
-
* @internal Used by network deserialization to set a whole word at once.
|
|
41
|
-
*/
|
|
42
|
-
setIndexBitmask(arrayIndex, bitmask) {
|
|
43
|
-
this._bits[arrayIndex] = bitmask;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Set the bit described by `bptr` (fast path using a pre-computed
|
|
47
|
-
* {@link BitPtr}).
|
|
48
|
-
*/
|
|
49
|
-
addBit(bptr) {
|
|
50
|
-
this.addIndexBitmask(bptr.arrayIndex, bptr.bitmask);
|
|
51
|
-
}
|
|
52
26
|
/**
|
|
53
27
|
* Set bit `n`.
|
|
54
28
|
*
|
|
@@ -57,12 +31,20 @@ export class Bitset {
|
|
|
57
31
|
add(n) {
|
|
58
32
|
const arrayIndex = Math.floor(n / 32);
|
|
59
33
|
const bitmask = 1 << (n % 32);
|
|
60
|
-
this.
|
|
34
|
+
this._addIndexBitmask(arrayIndex, bitmask);
|
|
61
35
|
}
|
|
62
36
|
/**
|
|
63
|
-
*
|
|
37
|
+
* Set the bit described by `bptr` (fast path using a pre-computed
|
|
38
|
+
* {@link BitPtr}).
|
|
64
39
|
*
|
|
65
|
-
*
|
|
40
|
+
* @param bptr - Pre-computed pointer to a bit position.
|
|
41
|
+
*/
|
|
42
|
+
addBit(bptr) {
|
|
43
|
+
this._addIndexBitmask(bptr.arrayIndex, bptr.bitmask);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Clear bit `n`. Trailing zero words are trimmed so the internal storage
|
|
47
|
+
* stays compact.
|
|
66
48
|
*
|
|
67
49
|
* @param n - Non-negative integer bit index.
|
|
68
50
|
*/
|
|
@@ -80,13 +62,7 @@ export class Bitset {
|
|
|
80
62
|
}
|
|
81
63
|
}
|
|
82
64
|
/**
|
|
83
|
-
* Return `true`
|
|
84
|
-
*/
|
|
85
|
-
hasBit(bptr) {
|
|
86
|
-
return this.hasIndexBitmask(bptr.arrayIndex, bptr.bitmask);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Return `true` if bit `n` is set.
|
|
65
|
+
* Return `true` when bit `n` is set.
|
|
90
66
|
*
|
|
91
67
|
* @param n - Non-negative integer bit index.
|
|
92
68
|
*/
|
|
@@ -97,22 +73,32 @@ export class Bitset {
|
|
|
97
73
|
}
|
|
98
74
|
const bitIndex = n % 32;
|
|
99
75
|
const bitmask = 1 << bitIndex;
|
|
100
|
-
return this.
|
|
76
|
+
return this._hasIndexBitmask(arrayIndex, bitmask);
|
|
101
77
|
}
|
|
102
78
|
/**
|
|
103
|
-
* Return `true`
|
|
79
|
+
* Return `true` when the bit described by `bptr` is set (fast path).
|
|
104
80
|
*
|
|
105
|
-
* @
|
|
81
|
+
* @param bptr - Pre-computed pointer to a bit position.
|
|
106
82
|
*/
|
|
107
|
-
|
|
108
|
-
return
|
|
83
|
+
hasBit(bptr) {
|
|
84
|
+
return this._hasIndexBitmask(bptr.arrayIndex, bptr.bitmask);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Return `true` when this bitset and `other` have exactly the same bits set.
|
|
88
|
+
*
|
|
89
|
+
* @param other - Bitset to compare against.
|
|
90
|
+
*/
|
|
91
|
+
equal(other) {
|
|
92
|
+
return (this._bits.length === other._bits.length && this._bits.every((v, i) => other._bits[i] === v));
|
|
109
93
|
}
|
|
110
94
|
/**
|
|
111
|
-
* Return `true`
|
|
112
|
-
* `other` is a subset of `this`).
|
|
95
|
+
* Return `true` when every bit set in `other` is also set in this bitset
|
|
96
|
+
* (i.e. `other` is a subset of `this`).
|
|
113
97
|
*
|
|
114
98
|
* Used by the world to test whether an entity's archetype satisfies a
|
|
115
|
-
*
|
|
99
|
+
* `HAS` query.
|
|
100
|
+
*
|
|
101
|
+
* @param other - Bitset whose set bits must all appear in this bitset.
|
|
116
102
|
*/
|
|
117
103
|
hasBitset(other) {
|
|
118
104
|
if (this._bits.length < other._bits.length) {
|
|
@@ -126,9 +112,9 @@ export class Bitset {
|
|
|
126
112
|
return true;
|
|
127
113
|
}
|
|
128
114
|
/**
|
|
129
|
-
*
|
|
115
|
+
* Visit each set bit index in ascending order.
|
|
130
116
|
*
|
|
131
|
-
* @param callback -
|
|
117
|
+
* @param callback - Invoked once per set bit.
|
|
132
118
|
*/
|
|
133
119
|
forEach(callback) {
|
|
134
120
|
this._bits.forEach((b, j) => {
|
|
@@ -141,26 +127,50 @@ export class Bitset {
|
|
|
141
127
|
});
|
|
142
128
|
}
|
|
143
129
|
/**
|
|
144
|
-
* Return an array of
|
|
145
|
-
*
|
|
146
|
-
* @returns `number[]` of set bit positions.
|
|
130
|
+
* Return an array of every set bit index in ascending order.
|
|
147
131
|
*/
|
|
148
132
|
indices() {
|
|
149
133
|
const idx = [];
|
|
150
134
|
this.forEach((i) => idx.push(i));
|
|
151
135
|
return idx;
|
|
152
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* OR `bitmask` into the word at position `arrayIndex`.
|
|
139
|
+
*
|
|
140
|
+
* @internal Low-level bulk operation; prefer {@link add} or {@link addBit}
|
|
141
|
+
* for single bits.
|
|
142
|
+
*/
|
|
143
|
+
_addIndexBitmask(arrayIndex, bitmask) {
|
|
144
|
+
this._bits[arrayIndex] |= bitmask;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Replace the word at position `arrayIndex` with `bitmask`.
|
|
148
|
+
*
|
|
149
|
+
* @internal Used by network deserialization to write a whole word at once.
|
|
150
|
+
*/
|
|
151
|
+
_setIndexBitmask(arrayIndex, bitmask) {
|
|
152
|
+
this._bits[arrayIndex] = bitmask;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Return `true` when every bit in `bitmask` is set in the word at
|
|
156
|
+
* `arrayIndex`.
|
|
157
|
+
*
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
_hasIndexBitmask(arrayIndex, bitmask) {
|
|
161
|
+
return (this._bits[arrayIndex] & bitmask) !== 0;
|
|
162
|
+
}
|
|
153
163
|
}
|
|
154
164
|
/**
|
|
155
165
|
* A pre-computed pointer into a {@link Bitset}'s internal word array.
|
|
156
166
|
*
|
|
157
167
|
* Computing `arrayIndex` and `bitmask` from a raw bit index requires a floor
|
|
158
|
-
* division and a
|
|
168
|
+
* division and a bit shift. `BitPtr` caches both values so that hot-path
|
|
159
169
|
* archetype checks ({@link Bitset.hasBit}, {@link Bitset.addBit}) avoid
|
|
160
170
|
* repeating the arithmetic on every entity update.
|
|
161
171
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
172
|
+
* One `BitPtr` is created per registered component type and stored on
|
|
173
|
+
* `ComponentMeta.bitPtr`.
|
|
164
174
|
*/
|
|
165
175
|
export class BitPtr {
|
|
166
176
|
constructor(
|
|
@@ -170,7 +180,11 @@ export class BitPtr {
|
|
|
170
180
|
this.arrayIndex = Math.floor(value / 32);
|
|
171
181
|
this.bitmask = 1 << (value % 32);
|
|
172
182
|
}
|
|
173
|
-
/**
|
|
183
|
+
/**
|
|
184
|
+
* Return `true` when both pointers refer to the same bit position.
|
|
185
|
+
*
|
|
186
|
+
* @param other - Pointer to compare against.
|
|
187
|
+
*/
|
|
174
188
|
equals(other) {
|
|
175
189
|
return this.arrayIndex == other.arrayIndex && this.bitmask == other.bitmask;
|
|
176
190
|
}
|
package/dist/util/bitset.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitset.js","sourceRoot":"","sources":["../../src/util/bitset.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bitset.js","sourceRoot":"","sources":["../../src/util/bitset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,MAAM;IAAnB;QACE,4DAA4D;QACrD,UAAK,GAAa,EAAE,CAAC;IAuJ9B,CAAC;IArJC;;;;OAIG;IACI,GAAG,CAAC,CAAS;QAClB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QACtC,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QAC9B,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strongly-typed wrapper around `eventemitter3`.
|
|
3
|
+
*
|
|
4
|
+
* The class declared in this file is purely a typings shim — at module load
|
|
5
|
+
* its prototype is swapped out for `EventEmitter` from `eventemitter3` so the
|
|
6
|
+
* concrete behavior is provided by that library, while consumers see typed
|
|
7
|
+
* `on` / `emit` / `off` signatures driven by an `EventMap`.
|
|
8
|
+
*
|
|
9
|
+
* Inspired by the typings in `@yandeu/events`
|
|
10
|
+
* (https://github.com/yandeu/events). The original typings turned out to be
|
|
11
|
+
* usable directly on top of `eventemitter3`.
|
|
12
|
+
*
|
|
13
|
+
* @internal Used only inside the package, to expose typed entity-level events.
|
|
5
14
|
*/
|
|
6
15
|
declare type ValidEventMap<T = any> = T extends {
|
|
7
16
|
[P in keyof T]: (...args: any[]) => void;
|
|
8
17
|
} ? T : never;
|
|
9
18
|
declare type Handler<T extends any | ((...args: any[]) => R), R = any> = T;
|
|
19
|
+
/** Listener signature inferred from an `EventMap` entry. */
|
|
10
20
|
export declare type EventListener<T extends ValidEventMap, K extends EventNames<T>> = T extends string | symbol ? (...args: any[]) => void : K extends keyof T ? Handler<T[K], void> : never;
|
|
11
|
-
|
|
21
|
+
/** Names of the events declared on an `EventMap`. */
|
|
12
22
|
export declare type EventNames<T extends ValidEventMap> = T extends string | symbol ? T : keyof T;
|
|
13
|
-
declare class events<EventMap extends ValidEventMap = any> {
|
|
14
|
-
on<T extends EventNames<EventMap>>(event: T, fn: EventListener<EventMap, T>, context?: any): events<EventMap>;
|
|
15
|
-
emit<T extends EventNames<EventMap>>(event: T, ...args: EventArgs<EventMap, T>): boolean;
|
|
16
|
-
once<T extends EventNames<EventMap>>(event: T, fn: EventListener<EventMap, T>, context?: any): events<EventMap>;
|
|
17
|
-
eventNames(): EventNames<EventMap>[];
|
|
18
|
-
listeners(event: EventNames<EventMap>): any[];
|
|
19
|
-
listenerCount(event: EventNames<EventMap>): any;
|
|
20
|
-
removeListener<T extends EventNames<EventMap>>(event: T, fn?: EventListener<EventMap, T>, context?: any, once?: boolean): this;
|
|
21
|
-
removeAllListeners(event?: EventNames<EventMap>): this;
|
|
22
|
-
off<T extends EventNames<EventMap>>(event: T, fn?: EventListener<EventMap, T> | undefined, context?: any, once?: boolean | undefined): events<EventMap>;
|
|
23
|
-
addListener<T extends EventNames<EventMap>>(event: T, fn: EventListener<EventMap, T>, context?: any): events<EventMap>;
|
|
24
|
-
}
|
|
25
|
-
export declare class Events<EventMap extends ValidEventMap = any> extends events<EventMap> {
|
|
26
|
-
}
|
|
27
23
|
export {};
|
package/dist/util/events.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Strongly-typed wrapper around `eventemitter3`.
|
|
3
|
+
*
|
|
4
|
+
* The class declared in this file is purely a typings shim — at module load
|
|
5
|
+
* its prototype is swapped out for `EventEmitter` from `eventemitter3` so the
|
|
6
|
+
* concrete behavior is provided by that library, while consumers see typed
|
|
7
|
+
* `on` / `emit` / `off` signatures driven by an `EventMap`.
|
|
8
|
+
*
|
|
9
|
+
* Inspired by the typings in `@yandeu/events`
|
|
10
|
+
* (https://github.com/yandeu/events). The original typings turned out to be
|
|
11
|
+
* usable directly on top of `eventemitter3`.
|
|
12
|
+
*
|
|
13
|
+
* @internal Used only inside the package, to expose typed entity-level events.
|
|
5
14
|
*/
|
|
6
15
|
import eventEmitter3 from "eventemitter3";
|
|
7
16
|
const { EventEmitter } = eventEmitter3;
|
|
17
|
+
/**
|
|
18
|
+
* Typed event emitter shape. Replaced at runtime by `EventEmitter` from
|
|
19
|
+
* `eventemitter3` (see the assignment below the class body).
|
|
20
|
+
*/
|
|
8
21
|
class events {
|
|
9
22
|
on(event, fn, context) {
|
|
10
23
|
return 0;
|
|
@@ -38,6 +51,14 @@ class events {
|
|
|
38
51
|
}
|
|
39
52
|
}
|
|
40
53
|
events = EventEmitter;
|
|
54
|
+
/**
|
|
55
|
+
* Typed `EventEmitter` parameterised by an `EventMap` of `eventName -> handler`.
|
|
56
|
+
*
|
|
57
|
+
* Constructed lazily by `Entity.events`. Inherits its concrete behavior from
|
|
58
|
+
* `eventemitter3`'s `EventEmitter`.
|
|
59
|
+
*
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
41
62
|
export class Events extends events {
|
|
42
63
|
}
|
|
43
64
|
//# sourceMappingURL=events.js.map
|
package/dist/util/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/util/events.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/util/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,aAAa,MAAM,eAAe,CAAC;AAC1C,MAAM,EAAE,YAAY,EAAE,GAAG,aAAa,CAAC;AA0BvC;;;GAGG;AACH,MAAM,MAAM;IACH,EAAE,CACP,KAAQ,EACR,EAA8B,EAC9B,OAAa;QAEb,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,IAAI,CAAiC,KAAQ,EAAE,GAAG,IAA4B;QACnF,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,IAAI,CACT,KAAQ,EACR,EAA8B,EAC9B,OAAa;QAEb,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,UAAU;QACf,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,SAAS,CAAC,KAA2B;QAC1C,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,aAAa,CAAC,KAA2B;QAC9C,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,cAAc,CACnB,KAAQ,EACR,EAA+B,EAC/B,OAAa,EACb,IAAc;QAEd,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,kBAAkB,CAAC,KAA4B;QACpD,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,GAAG,CACR,KAAQ,EACR,EAA2C,EAC3C,OAAa,EACb,IAA0B;QAE1B,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,WAAW,CAChB,KAAQ,EACR,EAA8B,EAC9B,OAAa;QAEb,OAAO,CAAQ,CAAC;IAClB,CAAC;CACF;AAEA,MAAc,GAAG,YAAY,CAAC;AAE/B;;;;;;;GAOG;AACH,MAAM,OAAO,MAA6C,SAAQ,MAAgB;CAAG"}
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
private items;
|
|
3
|
-
private readonly compare;
|
|
4
|
-
constructor(compare: (a: T, b: T) => number);
|
|
5
|
-
private bisect;
|
|
6
|
-
add(value: T): this;
|
|
7
|
-
has(value: T): boolean;
|
|
8
|
-
delete(value: T): boolean;
|
|
9
|
-
clear(): void;
|
|
10
|
-
get size(): number;
|
|
11
|
-
forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: unknown): void;
|
|
12
|
-
[Symbol.iterator](): IterableIterator<T>;
|
|
13
|
-
entries(): IterableIterator<[T, T]>;
|
|
14
|
-
keys(): IterableIterator<T>;
|
|
15
|
-
values(): IterableIterator<T>;
|
|
16
|
-
get [Symbol.toStringTag](): string;
|
|
17
|
-
}
|
|
1
|
+
export {};
|
package/dist/util/ordered_set.js
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `Set<T>` whose iteration order is determined by a comparator instead of
|
|
3
|
+
* insertion order.
|
|
4
|
+
*
|
|
5
|
+
* Backed by a sorted array. Insertions and lookups are `O(log n)` (binary
|
|
6
|
+
* search) plus the cost of an array splice on `add` / `delete`.
|
|
7
|
+
*
|
|
8
|
+
* Used by `Query.sort` to keep matched entities in a user-defined order so
|
|
9
|
+
* iteration in `forEach` and `each` walks them sorted.
|
|
10
|
+
*
|
|
11
|
+
* @internal Used only inside the package.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam T - Element type stored in the set.
|
|
14
|
+
*/
|
|
1
15
|
export class OrderedSet {
|
|
2
16
|
constructor(compare) {
|
|
3
|
-
this.
|
|
4
|
-
this.
|
|
17
|
+
this._items = [];
|
|
18
|
+
this._compare = compare;
|
|
5
19
|
}
|
|
6
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Return the index where `value` should be inserted to keep the array
|
|
22
|
+
* sorted (binary search; mirrors Python's `bisect_left`).
|
|
23
|
+
*/
|
|
24
|
+
_bisect(value) {
|
|
7
25
|
let lo = 0;
|
|
8
|
-
let hi = this.
|
|
26
|
+
let hi = this._items.length;
|
|
9
27
|
while (lo < hi) {
|
|
10
28
|
const mid = (lo + hi) >>> 1;
|
|
11
|
-
if (this.
|
|
29
|
+
if (this._compare(this._items[mid], value) < 0) {
|
|
12
30
|
lo = mid + 1;
|
|
13
31
|
}
|
|
14
32
|
else {
|
|
@@ -17,53 +35,84 @@ export class OrderedSet {
|
|
|
17
35
|
}
|
|
18
36
|
return lo;
|
|
19
37
|
}
|
|
38
|
+
/** Number of elements currently stored. */
|
|
39
|
+
get size() {
|
|
40
|
+
return this._items.length;
|
|
41
|
+
}
|
|
42
|
+
/** Tag used by `Object.prototype.toString` for stringification. */
|
|
43
|
+
get [Symbol.toStringTag]() {
|
|
44
|
+
return "OrderedSet";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Insert `value` at the position determined by the comparator. No-op when
|
|
48
|
+
* an element compares equal to `value`.
|
|
49
|
+
*
|
|
50
|
+
* @param value - Element to insert.
|
|
51
|
+
*/
|
|
20
52
|
add(value) {
|
|
21
|
-
const i = this.
|
|
22
|
-
if (i < this.
|
|
53
|
+
const i = this._bisect(value);
|
|
54
|
+
if (i < this._items.length && this._compare(this._items[i], value) === 0) {
|
|
23
55
|
return this;
|
|
24
56
|
}
|
|
25
|
-
this.
|
|
57
|
+
this._items.splice(i, 0, value);
|
|
26
58
|
return this;
|
|
27
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Return `true` when an element comparing equal to `value` is in the set.
|
|
62
|
+
*
|
|
63
|
+
* @param value - Element to look up.
|
|
64
|
+
*/
|
|
28
65
|
has(value) {
|
|
29
|
-
const i = this.
|
|
30
|
-
return i < this.
|
|
66
|
+
const i = this._bisect(value);
|
|
67
|
+
return i < this._items.length && this._compare(this._items[i], value) === 0;
|
|
31
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Remove the element comparing equal to `value`. Returns `true` if an
|
|
71
|
+
* element was removed.
|
|
72
|
+
*
|
|
73
|
+
* @param value - Element to remove.
|
|
74
|
+
*/
|
|
32
75
|
delete(value) {
|
|
33
|
-
const i = this.
|
|
34
|
-
if (i < this.
|
|
35
|
-
this.
|
|
76
|
+
const i = this._bisect(value);
|
|
77
|
+
if (i < this._items.length && this._compare(this._items[i], value) === 0) {
|
|
78
|
+
this._items.splice(i, 1);
|
|
36
79
|
return true;
|
|
37
80
|
}
|
|
38
81
|
return false;
|
|
39
82
|
}
|
|
83
|
+
/** Remove every element. */
|
|
40
84
|
clear() {
|
|
41
|
-
this.
|
|
42
|
-
}
|
|
43
|
-
get size() {
|
|
44
|
-
return this.items.length;
|
|
85
|
+
this._items.length = 0;
|
|
45
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Visit each element in sorted order.
|
|
89
|
+
*
|
|
90
|
+
* @param callbackfn - Invoked with `(value, value, set)` for each element
|
|
91
|
+
* (`Set` interface compatibility — both arguments are the same value).
|
|
92
|
+
* @param thisArg - Optional `this` binding for the callback.
|
|
93
|
+
*/
|
|
46
94
|
forEach(callbackfn, thisArg) {
|
|
47
|
-
for (const item of this.
|
|
95
|
+
for (const item of this._items) {
|
|
48
96
|
callbackfn.call(thisArg, item, item, this);
|
|
49
97
|
}
|
|
50
98
|
}
|
|
99
|
+
/** Iterator over elements in sorted order. */
|
|
51
100
|
[Symbol.iterator]() {
|
|
52
|
-
return this.
|
|
101
|
+
return this._items[Symbol.iterator]();
|
|
53
102
|
}
|
|
103
|
+
/** Iterator yielding `[value, value]` pairs in sorted order. */
|
|
54
104
|
*entries() {
|
|
55
|
-
for (const item of this.
|
|
105
|
+
for (const item of this._items) {
|
|
56
106
|
yield [item, item];
|
|
57
107
|
}
|
|
58
108
|
}
|
|
109
|
+
/** Iterator over elements in sorted order. */
|
|
59
110
|
keys() {
|
|
60
|
-
return this.
|
|
111
|
+
return this._items[Symbol.iterator]();
|
|
61
112
|
}
|
|
113
|
+
/** Iterator over elements in sorted order. */
|
|
62
114
|
values() {
|
|
63
|
-
return this.
|
|
64
|
-
}
|
|
65
|
-
get [Symbol.toStringTag]() {
|
|
66
|
-
return "OrderedSet";
|
|
115
|
+
return this._items[Symbol.iterator]();
|
|
67
116
|
}
|
|
68
117
|
}
|
|
69
118
|
//# sourceMappingURL=ordered_set.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ordered_set.js","sourceRoot":"","sources":["../../src/util/ordered_set.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAU;IAIrB,YAAY,OAA+B;
|
|
1
|
+
{"version":3,"file":"ordered_set.js","sourceRoot":"","sources":["../../src/util/ordered_set.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,UAAU;IAIrB,YAAY,OAA+B;QAHnC,WAAM,GAAQ,EAAE,CAAC;QAIvB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACK,OAAO,CAAC,KAAQ;QACtB,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAC5B,OAAO,EAAE,GAAG,EAAE,EAAE;YACd,MAAM,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;YAC5B,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE;gBAC9C,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;aACd;iBAAM;gBACL,EAAE,GAAG,GAAG,CAAC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