@blackglory/structures 0.15.1 → 0.15.2
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/lib/bit-set/bit-set.d.ts +1 -1
- package/lib/bit-set/bit-set.js +6 -6
- package/lib/bit-set/bit-set.js.map +1 -1
- package/lib/bit-set/dynamic-typed-bit-set.d.ts +1 -1
- package/lib/bit-set/dynamic-typed-bit-set.js +5 -5
- package/lib/bit-set/dynamic-typed-bit-set.js.map +1 -1
- package/lib/bit-set/resizable-typed-bit-set.d.ts +1 -1
- package/lib/bit-set/resizable-typed-bit-set.js +5 -5
- package/lib/bit-set/resizable-typed-bit-set.js.map +1 -1
- package/lib/bit-set/typed-bit-set.d.ts +1 -1
- package/lib/bit-set/typed-bit-set.js +5 -5
- package/lib/bit-set/typed-bit-set.js.map +1 -1
- package/lib/dynamic-typed-array.d.ts +1 -1
- package/lib/dynamic-typed-array.js +14 -14
- package/lib/dynamic-typed-array.js.map +1 -1
- package/lib/resizable-typed-array.d.ts +1 -1
- package/lib/resizable-typed-array.js +14 -14
- package/lib/resizable-typed-array.js.map +1 -1
- package/lib/sparse-map/typed-clean-sparse-map-lite.d.ts +1 -1
- package/lib/sparse-map/typed-clean-sparse-map-lite.js +8 -8
- package/lib/sparse-map/typed-clean-sparse-map-lite.js.map +1 -1
- package/lib/sparse-map/typed-clean-sparse-map.d.ts +1 -1
- package/lib/sparse-map/typed-clean-sparse-map.js +8 -8
- package/lib/sparse-map/typed-clean-sparse-map.js.map +1 -1
- package/lib/sparse-map/typed-sparse-map-lite.d.ts +1 -1
- package/lib/sparse-map/typed-sparse-map-lite.js +13 -13
- package/lib/sparse-map/typed-sparse-map-lite.js.map +1 -1
- package/lib/sparse-map/typed-sparse-map.d.ts +1 -1
- package/lib/sparse-map/typed-sparse-map.js +13 -13
- package/lib/sparse-map/typed-sparse-map.js.map +1 -1
- package/lib/sparse-set/typed-clean-sparse-set-lite.d.ts +1 -1
- package/lib/sparse-set/typed-clean-sparse-set-lite.js +6 -6
- package/lib/sparse-set/typed-clean-sparse-set-lite.js.map +1 -1
- package/lib/sparse-set/typed-clean-sparse-set.d.ts +1 -1
- package/lib/sparse-set/typed-clean-sparse-set.js +6 -6
- package/lib/sparse-set/typed-clean-sparse-set.js.map +1 -1
- package/lib/sparse-set/typed-sparse-set-lite.d.ts +1 -1
- package/lib/sparse-set/typed-sparse-set-lite.js +8 -8
- package/lib/sparse-set/typed-sparse-set-lite.js.map +1 -1
- package/lib/sparse-set/typed-sparse-set.d.ts +1 -1
- package/lib/sparse-set/typed-sparse-set.js +8 -8
- package/lib/sparse-set/typed-sparse-set.js.map +1 -1
- package/package.json +1 -1
- package/src/bit-set/bit-set.ts +6 -6
- package/src/bit-set/dynamic-typed-bit-set.ts +5 -5
- package/src/bit-set/resizable-typed-bit-set.ts +5 -5
- package/src/bit-set/typed-bit-set.ts +5 -5
- package/src/dynamic-typed-array.ts +14 -14
- package/src/resizable-typed-array.ts +14 -14
- package/src/sparse-map/typed-clean-sparse-map-lite.ts +8 -8
- package/src/sparse-map/typed-clean-sparse-map.ts +8 -8
- package/src/sparse-map/typed-sparse-map-lite.ts +13 -13
- package/src/sparse-map/typed-sparse-map.ts +13 -13
- package/src/sparse-set/typed-clean-sparse-set-lite.ts +6 -6
- package/src/sparse-set/typed-clean-sparse-set.ts +6 -6
- package/src/sparse-set/typed-sparse-set-lite.ts +8 -8
- package/src/sparse-set/typed-sparse-set.ts +8 -8
|
@@ -10,7 +10,7 @@ export class TypedSparseMap<
|
|
|
10
10
|
private denseKeys: TypedArrayOfConstructor<K>
|
|
11
11
|
private denseValues: TypedArrayOfConstructor<V>
|
|
12
12
|
private sparse: UnsignedTypedArray
|
|
13
|
-
|
|
13
|
+
private _length = 0
|
|
14
14
|
|
|
15
15
|
readonly internalKeyArray: TypedArrayOfConstructor<K, ArrayBuffer>
|
|
16
16
|
readonly internalValueArray: TypedArrayOfConstructor<V, ArrayBuffer>
|
|
@@ -20,7 +20,7 @@ export class TypedSparseMap<
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
get size(): number {
|
|
23
|
-
return this
|
|
23
|
+
return this._length
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
constructor(
|
|
@@ -68,7 +68,7 @@ export class TypedSparseMap<
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
* entries(): IterableIterator<[key: number, value: number]> {
|
|
71
|
-
for (let i = 0; i < this
|
|
71
|
+
for (let i = 0; i < this._length; i++) {
|
|
72
72
|
yield [
|
|
73
73
|
this.denseKeys[i]
|
|
74
74
|
, this.denseValues[i]
|
|
@@ -77,13 +77,13 @@ export class TypedSparseMap<
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
* keys(): IterableIterator<number> {
|
|
80
|
-
for (let i = 0; i < this
|
|
80
|
+
for (let i = 0; i < this._length; i++) {
|
|
81
81
|
yield this.denseKeys[i]
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
* values(): IterableIterator<number> {
|
|
86
|
-
for (let i = 0; i < this
|
|
86
|
+
for (let i = 0; i < this._length; i++) {
|
|
87
87
|
yield this.denseValues[i]
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -92,7 +92,7 @@ export class TypedSparseMap<
|
|
|
92
92
|
const index = this.sparse[key]
|
|
93
93
|
if (
|
|
94
94
|
index !== undefined &&
|
|
95
|
-
index < this
|
|
95
|
+
index < this._length &&
|
|
96
96
|
index < this.denseKeys.length && // 用于改善JIT优化.
|
|
97
97
|
this.denseKeys[index] === key
|
|
98
98
|
) {
|
|
@@ -103,7 +103,7 @@ export class TypedSparseMap<
|
|
|
103
103
|
has(key: number): boolean {
|
|
104
104
|
const index = this.sparse[key]
|
|
105
105
|
return index !== undefined
|
|
106
|
-
&& index < this
|
|
106
|
+
&& index < this._length
|
|
107
107
|
&& index < this.denseKeys.length // 用于改善JIT优化.
|
|
108
108
|
&& this.denseKeys[index] === key
|
|
109
109
|
}
|
|
@@ -112,7 +112,7 @@ export class TypedSparseMap<
|
|
|
112
112
|
const index = this.sparse[key]
|
|
113
113
|
if (
|
|
114
114
|
index !== undefined &&
|
|
115
|
-
index < this
|
|
115
|
+
index < this._length &&
|
|
116
116
|
index < this.denseKeys.length && // 用于改善JIT优化.
|
|
117
117
|
this.denseKeys[index] === key
|
|
118
118
|
) {
|
|
@@ -126,13 +126,13 @@ export class TypedSparseMap<
|
|
|
126
126
|
const index = this.sparse[key]
|
|
127
127
|
if (
|
|
128
128
|
index !== undefined &&
|
|
129
|
-
index < this
|
|
129
|
+
index < this._length &&
|
|
130
130
|
index < this.denseKeys.length && // 用于改善JIT优化.
|
|
131
131
|
this.denseKeys[index] === key
|
|
132
132
|
) {
|
|
133
133
|
this.denseValues[index] = value
|
|
134
134
|
} else {
|
|
135
|
-
const index = this
|
|
135
|
+
const index = this._length++
|
|
136
136
|
this.denseKeys[index] = key
|
|
137
137
|
this.denseValues[index] = value
|
|
138
138
|
this.sparse[key] = index
|
|
@@ -143,11 +143,11 @@ export class TypedSparseMap<
|
|
|
143
143
|
const index = this.sparse[key]
|
|
144
144
|
if (
|
|
145
145
|
index !== undefined &&
|
|
146
|
-
index < this
|
|
146
|
+
index < this._length &&
|
|
147
147
|
index < this.denseKeys.length && // 用于改善JIT优化.
|
|
148
148
|
this.denseKeys[index] === key
|
|
149
149
|
) {
|
|
150
|
-
const lastIndex = --this
|
|
150
|
+
const lastIndex = --this._length
|
|
151
151
|
const lastKey = this.denseKeys[lastIndex]
|
|
152
152
|
const lastValue = this.denseValues[lastIndex]
|
|
153
153
|
if (key !== lastKey) {
|
|
@@ -163,7 +163,7 @@ export class TypedSparseMap<
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
clear(): void {
|
|
166
|
-
this
|
|
166
|
+
this._length = 0
|
|
167
167
|
// 无需清空dense和sparse数组.
|
|
168
168
|
}
|
|
169
169
|
}
|
|
@@ -4,14 +4,14 @@ import { UnsignedTypedArray } from 'justypes'
|
|
|
4
4
|
export class TypedCleanSparseSetLite implements Iterable<number> {
|
|
5
5
|
private dense: UnsignedTypedArray
|
|
6
6
|
private sparse: Array<number | undefined> = []
|
|
7
|
-
|
|
7
|
+
private _length = 0
|
|
8
8
|
|
|
9
9
|
get [Symbol.toStringTag](): string {
|
|
10
10
|
return this.constructor.name
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
get size(): number {
|
|
14
|
-
return this
|
|
14
|
+
return this._length
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
constructor(array: UnsignedTypedArray<ArrayBuffer>) {
|
|
@@ -25,7 +25,7 @@ export class TypedCleanSparseSetLite implements Iterable<number> {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
* values(): IterableIterator<number> {
|
|
28
|
-
for (let i = 0; i < this
|
|
28
|
+
for (let i = 0; i < this._length; i++) {
|
|
29
29
|
yield this.dense[i]
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -36,7 +36,7 @@ export class TypedCleanSparseSetLite implements Iterable<number> {
|
|
|
36
36
|
|
|
37
37
|
add(value: number): void {
|
|
38
38
|
if (!this.has(value)) {
|
|
39
|
-
const index = this
|
|
39
|
+
const index = this._length++
|
|
40
40
|
this.dense[index] = value
|
|
41
41
|
this.sparse[value] = index
|
|
42
42
|
}
|
|
@@ -47,7 +47,7 @@ export class TypedCleanSparseSetLite implements Iterable<number> {
|
|
|
47
47
|
if (index !== undefined) {
|
|
48
48
|
this.sparse[value] = undefined
|
|
49
49
|
|
|
50
|
-
const lastIndex = --this
|
|
50
|
+
const lastIndex = --this._length
|
|
51
51
|
const lastValue = this.dense[lastIndex]
|
|
52
52
|
if (value !== lastValue) {
|
|
53
53
|
this.dense[index] = lastValue
|
|
@@ -61,7 +61,7 @@ export class TypedCleanSparseSetLite implements Iterable<number> {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
clear(): void {
|
|
64
|
-
this
|
|
64
|
+
this._length = 0
|
|
65
65
|
this.sparse.length = 0
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -7,14 +7,14 @@ export class TypedCleanSparseSet implements Iterable<number> {
|
|
|
7
7
|
private dense: UnsignedTypedArray
|
|
8
8
|
private sparse: UnsignedTypedArray
|
|
9
9
|
private readonly NULL: number
|
|
10
|
-
|
|
10
|
+
private _length = 0
|
|
11
11
|
|
|
12
12
|
get [Symbol.toStringTag](): string {
|
|
13
13
|
return this.constructor.name
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
get size(): number {
|
|
17
|
-
return this
|
|
17
|
+
return this._length
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
constructor(array: UnsignedTypedArray<ArrayBuffer>) {
|
|
@@ -58,7 +58,7 @@ export class TypedCleanSparseSet implements Iterable<number> {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
* values(): IterableIterator<number> {
|
|
61
|
-
for (let i = 0; i < this
|
|
61
|
+
for (let i = 0; i < this._length; i++) {
|
|
62
62
|
yield this.dense[i]
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -69,7 +69,7 @@ export class TypedCleanSparseSet implements Iterable<number> {
|
|
|
69
69
|
|
|
70
70
|
add(value: number): void {
|
|
71
71
|
if (!this.has(value)) {
|
|
72
|
-
const index = this
|
|
72
|
+
const index = this._length++
|
|
73
73
|
this.dense[index] = value
|
|
74
74
|
this.sparse[value] = index
|
|
75
75
|
}
|
|
@@ -80,7 +80,7 @@ export class TypedCleanSparseSet implements Iterable<number> {
|
|
|
80
80
|
if (index !== this.NULL) {
|
|
81
81
|
this.sparse[value] = this.NULL
|
|
82
82
|
|
|
83
|
-
const lastIndex = --this
|
|
83
|
+
const lastIndex = --this._length
|
|
84
84
|
const lastValue = this.dense[lastIndex]
|
|
85
85
|
if (value !== lastValue) {
|
|
86
86
|
this.dense[index] = lastValue
|
|
@@ -94,7 +94,7 @@ export class TypedCleanSparseSet implements Iterable<number> {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
clear(): void {
|
|
97
|
-
this
|
|
97
|
+
this._length = 0
|
|
98
98
|
this.sparse.fill(this.NULL)
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -4,14 +4,14 @@ import { UnsignedTypedArray } from 'justypes'
|
|
|
4
4
|
export class TypedSparseSetLite implements Iterable<number> {
|
|
5
5
|
private dense: UnsignedTypedArray
|
|
6
6
|
private sparse: Array<number | undefined> = []
|
|
7
|
-
|
|
7
|
+
private _length = 0
|
|
8
8
|
|
|
9
9
|
get [Symbol.toStringTag](): string {
|
|
10
10
|
return this.constructor.name
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
get size(): number {
|
|
14
|
-
return this
|
|
14
|
+
return this._length
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
constructor(array: UnsignedTypedArray<ArrayBuffer>) {
|
|
@@ -25,7 +25,7 @@ export class TypedSparseSetLite implements Iterable<number> {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
* values(): IterableIterator<number> {
|
|
28
|
-
for (let i = 0; i < this
|
|
28
|
+
for (let i = 0; i < this._length; i++) {
|
|
29
29
|
yield this.dense[i]
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -33,14 +33,14 @@ export class TypedSparseSetLite implements Iterable<number> {
|
|
|
33
33
|
has(value: number): boolean {
|
|
34
34
|
const index = this.sparse[value]
|
|
35
35
|
return index !== undefined
|
|
36
|
-
&& index < this
|
|
36
|
+
&& index < this._length
|
|
37
37
|
&& index < this.dense.length // 用于改善JIT优化.
|
|
38
38
|
&& this.dense[index] === value
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
add(value: number): void {
|
|
42
42
|
if (!this.has(value)) {
|
|
43
|
-
const index = this
|
|
43
|
+
const index = this._length++
|
|
44
44
|
this.dense[index] = value
|
|
45
45
|
this.sparse[value] = index
|
|
46
46
|
}
|
|
@@ -50,11 +50,11 @@ export class TypedSparseSetLite implements Iterable<number> {
|
|
|
50
50
|
const index = this.sparse[value]
|
|
51
51
|
if (
|
|
52
52
|
index !== undefined &&
|
|
53
|
-
index < this
|
|
53
|
+
index < this._length &&
|
|
54
54
|
index < this.dense.length && // 用于改善JIT优化.
|
|
55
55
|
this.dense[index] === value
|
|
56
56
|
) {
|
|
57
|
-
const lastIndex = --this
|
|
57
|
+
const lastIndex = --this._length
|
|
58
58
|
const lastValue = this.dense[lastIndex]
|
|
59
59
|
if (value !== lastValue) {
|
|
60
60
|
this.dense[index] = lastValue
|
|
@@ -68,7 +68,7 @@ export class TypedSparseSetLite implements Iterable<number> {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
clear(): void {
|
|
71
|
-
this
|
|
71
|
+
this._length = 0
|
|
72
72
|
// 无需清空dense和sparse数组.
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -6,14 +6,14 @@ import { UnsignedTypedArray } from 'justypes'
|
|
|
6
6
|
export class TypedSparseSet implements Iterable<number> {
|
|
7
7
|
private dense: UnsignedTypedArray
|
|
8
8
|
private sparse: UnsignedTypedArray
|
|
9
|
-
|
|
9
|
+
private _length = 0
|
|
10
10
|
|
|
11
11
|
get [Symbol.toStringTag](): string {
|
|
12
12
|
return this.constructor.name
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
get size(): number {
|
|
16
|
-
return this
|
|
16
|
+
return this._length
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
constructor(array: UnsignedTypedArray<ArrayBuffer>) {
|
|
@@ -53,7 +53,7 @@ export class TypedSparseSet implements Iterable<number> {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
* values(): IterableIterator<number> {
|
|
56
|
-
for (let i = 0; i < this
|
|
56
|
+
for (let i = 0; i < this._length; i++) {
|
|
57
57
|
yield this.dense[i]
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -61,14 +61,14 @@ export class TypedSparseSet implements Iterable<number> {
|
|
|
61
61
|
has(value: number): boolean {
|
|
62
62
|
const index = this.sparse[value]
|
|
63
63
|
return index !== undefined
|
|
64
|
-
&& index < this
|
|
64
|
+
&& index < this._length
|
|
65
65
|
&& index < this.dense.length // 用于改善JIT优化.
|
|
66
66
|
&& this.dense[index] === value
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
add(value: number): void {
|
|
70
70
|
if (!this.has(value)) {
|
|
71
|
-
const index = this
|
|
71
|
+
const index = this._length++
|
|
72
72
|
this.dense[index] = value
|
|
73
73
|
this.sparse[value] = index
|
|
74
74
|
}
|
|
@@ -78,11 +78,11 @@ export class TypedSparseSet implements Iterable<number> {
|
|
|
78
78
|
const index = this.sparse[value]
|
|
79
79
|
if (
|
|
80
80
|
index !== undefined &&
|
|
81
|
-
index < this
|
|
81
|
+
index < this._length &&
|
|
82
82
|
index < this.dense.length && // 用于改善JIT优化.
|
|
83
83
|
this.dense[index] === value
|
|
84
84
|
) {
|
|
85
|
-
const lastIndex = --this
|
|
85
|
+
const lastIndex = --this._length
|
|
86
86
|
const lastValue = this.dense[lastIndex]
|
|
87
87
|
if (value !== lastValue) {
|
|
88
88
|
this.dense[index] = lastValue
|
|
@@ -96,7 +96,7 @@ export class TypedSparseSet implements Iterable<number> {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
clear(): void {
|
|
99
|
-
this
|
|
99
|
+
this._length = 0
|
|
100
100
|
// 无需清空dense和sparse数组.
|
|
101
101
|
}
|
|
102
102
|
}
|