@blackglory/structures 0.8.0 → 0.10.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/README.md +59 -21
- package/dist/es2015/index.min.mjs +2 -2
- package/dist/es2015/index.min.mjs.map +1 -1
- package/dist/es2015/index.mjs +415 -96
- package/dist/es2015/index.mjs.map +1 -1
- package/dist/es2015/index.umd.js +417 -95
- package/dist/es2015/index.umd.js.map +1 -1
- package/dist/es2015/index.umd.min.js +2 -2
- package/dist/es2015/index.umd.min.js.map +1 -1
- package/dist/es2018/index.min.mjs +2 -2
- package/dist/es2018/index.min.mjs.map +1 -1
- package/dist/es2018/index.mjs +415 -96
- package/dist/es2018/index.mjs.map +1 -1
- package/dist/es2018/index.umd.js +417 -95
- package/dist/es2018/index.umd.js.map +1 -1
- package/dist/es2018/index.umd.min.js +2 -2
- package/dist/es2018/index.umd.min.js.map +1 -1
- package/lib/es2015/dynamic-typed-array.d.ts +1 -1
- package/lib/es2015/dynamic-typed-array.js +25 -20
- package/lib/es2015/dynamic-typed-array.js.map +1 -1
- package/lib/es2015/index.d.ts +3 -0
- package/lib/es2015/index.js +3 -0
- package/lib/es2015/index.js.map +1 -1
- package/lib/es2015/sorted-set.d.ts +10 -0
- package/lib/es2015/sorted-set.js +32 -0
- package/lib/es2015/sorted-set.js.map +1 -0
- package/lib/es2015/sparse-map.d.ts +5 -12
- package/lib/es2015/sparse-map.js +25 -26
- package/lib/es2015/sparse-map.js.map +1 -1
- package/lib/es2015/sparse-set.d.ts +4 -8
- package/lib/es2015/sparse-set.js +24 -13
- package/lib/es2015/sparse-set.js.map +1 -1
- package/lib/es2015/typed-sparse-map.d.ts +16 -0
- package/lib/es2015/typed-sparse-map.js +70 -0
- package/lib/es2015/typed-sparse-map.js.map +1 -0
- package/lib/es2015/typed-sparse-set.d.ts +13 -0
- package/lib/es2015/typed-sparse-set.js +49 -0
- package/lib/es2015/typed-sparse-set.js.map +1 -0
- package/lib/es2015/utils/skip-list.d.ts +24 -0
- package/lib/es2015/utils/skip-list.js +155 -0
- package/lib/es2015/utils/skip-list.js.map +1 -0
- package/lib/es2018/dynamic-typed-array.d.ts +1 -1
- package/lib/es2018/dynamic-typed-array.js +25 -20
- package/lib/es2018/dynamic-typed-array.js.map +1 -1
- package/lib/es2018/index.d.ts +3 -0
- package/lib/es2018/index.js +3 -0
- package/lib/es2018/index.js.map +1 -1
- package/lib/es2018/sorted-set.d.ts +10 -0
- package/lib/es2018/sorted-set.js +32 -0
- package/lib/es2018/sorted-set.js.map +1 -0
- package/lib/es2018/sparse-map.d.ts +5 -12
- package/lib/es2018/sparse-map.js +25 -26
- package/lib/es2018/sparse-map.js.map +1 -1
- package/lib/es2018/sparse-set.d.ts +4 -8
- package/lib/es2018/sparse-set.js +24 -13
- package/lib/es2018/sparse-set.js.map +1 -1
- package/lib/es2018/typed-sparse-map.d.ts +16 -0
- package/lib/es2018/typed-sparse-map.js +70 -0
- package/lib/es2018/typed-sparse-map.js.map +1 -0
- package/lib/es2018/typed-sparse-set.d.ts +13 -0
- package/lib/es2018/typed-sparse-set.js +49 -0
- package/lib/es2018/typed-sparse-set.js.map +1 -0
- package/lib/es2018/utils/skip-list.d.ts +24 -0
- package/lib/es2018/utils/skip-list.js +155 -0
- package/lib/es2018/utils/skip-list.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SkipList = exports.SkipListNode = void 0;
|
|
4
|
+
const types_1 = require("@blackglory/types");
|
|
5
|
+
class SkipListNode {
|
|
6
|
+
constructor(value) {
|
|
7
|
+
this.value = value;
|
|
8
|
+
this.previous = null;
|
|
9
|
+
this.next = null;
|
|
10
|
+
this.up = null;
|
|
11
|
+
this.down = null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.SkipListNode = SkipListNode;
|
|
15
|
+
class SkipList {
|
|
16
|
+
constructor(compare) {
|
|
17
|
+
this.compare = compare;
|
|
18
|
+
this.head = new SkipListNode(null);
|
|
19
|
+
this.tail = new SkipListNode(null);
|
|
20
|
+
this.height = 0;
|
|
21
|
+
this._size = 0;
|
|
22
|
+
this.head.next = this.tail;
|
|
23
|
+
this.tail.previous = this.head;
|
|
24
|
+
}
|
|
25
|
+
get size() {
|
|
26
|
+
return this._size;
|
|
27
|
+
}
|
|
28
|
+
*elements() {
|
|
29
|
+
let currentNode = this.head;
|
|
30
|
+
while (currentNode.down) {
|
|
31
|
+
currentNode = currentNode.down;
|
|
32
|
+
}
|
|
33
|
+
while (currentNode.next && (0, types_1.isntNull)(currentNode.next.value)) {
|
|
34
|
+
currentNode = currentNode.next;
|
|
35
|
+
yield currentNode;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
dumpList() {
|
|
39
|
+
const result = [];
|
|
40
|
+
let head = this.head;
|
|
41
|
+
do {
|
|
42
|
+
result.push([]);
|
|
43
|
+
let currentNode = head;
|
|
44
|
+
do {
|
|
45
|
+
result[result.length - 1].push(currentNode.value);
|
|
46
|
+
currentNode = currentNode.next;
|
|
47
|
+
} while (currentNode);
|
|
48
|
+
} while (head = head.down);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
delete(value) {
|
|
52
|
+
let currentNode = this.findNode(value);
|
|
53
|
+
while (currentNode) {
|
|
54
|
+
currentNode.previous.next = currentNode.next;
|
|
55
|
+
currentNode.next.previous = currentNode.previous;
|
|
56
|
+
currentNode = currentNode.down;
|
|
57
|
+
}
|
|
58
|
+
this._size--;
|
|
59
|
+
}
|
|
60
|
+
has(value) {
|
|
61
|
+
return (0, types_1.isntNull)(this.findNode(value));
|
|
62
|
+
}
|
|
63
|
+
findNode(value) {
|
|
64
|
+
let currentNode = this.head;
|
|
65
|
+
while (true) {
|
|
66
|
+
while (currentNode.next && (0, types_1.isntNull)(currentNode.next.value)) {
|
|
67
|
+
const result = this.compare(currentNode.next.value, value);
|
|
68
|
+
if (result === 0) {
|
|
69
|
+
return currentNode.next;
|
|
70
|
+
}
|
|
71
|
+
else if (result < 0) {
|
|
72
|
+
currentNode = currentNode.next;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (currentNode.down) {
|
|
79
|
+
currentNode = currentNode.down;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
add(value) {
|
|
87
|
+
let previousNode = this.findPreviousNode(value);
|
|
88
|
+
if (previousNode.next &&
|
|
89
|
+
(0, types_1.isntNull)(previousNode.next.value) &&
|
|
90
|
+
this.compare(previousNode.next.value, value) === 0) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
let newNode = new SkipListNode(value);
|
|
94
|
+
if (previousNode.next) {
|
|
95
|
+
newNode.next = previousNode.next;
|
|
96
|
+
previousNode.next.previous = newNode;
|
|
97
|
+
}
|
|
98
|
+
previousNode.next = newNode;
|
|
99
|
+
newNode.previous = previousNode;
|
|
100
|
+
let level = 0;
|
|
101
|
+
while (Math.random() < 0.5) {
|
|
102
|
+
if (level === this.height) {
|
|
103
|
+
const newHead = new SkipListNode(null);
|
|
104
|
+
const newTail = new SkipListNode(null);
|
|
105
|
+
newHead.next = newTail;
|
|
106
|
+
newHead.down = this.head;
|
|
107
|
+
newTail.previous = newHead;
|
|
108
|
+
newTail.down = this.tail;
|
|
109
|
+
this.head.up = newHead;
|
|
110
|
+
this.tail.up = newTail;
|
|
111
|
+
this.head = newHead;
|
|
112
|
+
this.tail = newTail;
|
|
113
|
+
this.height++;
|
|
114
|
+
}
|
|
115
|
+
while (!previousNode.up) {
|
|
116
|
+
previousNode = previousNode.previous;
|
|
117
|
+
}
|
|
118
|
+
previousNode = previousNode.up;
|
|
119
|
+
const upperNewNode = new SkipListNode(value);
|
|
120
|
+
if (previousNode.next) {
|
|
121
|
+
upperNewNode.next = previousNode.next;
|
|
122
|
+
previousNode.next.previous = upperNewNode;
|
|
123
|
+
}
|
|
124
|
+
previousNode.next = upperNewNode;
|
|
125
|
+
upperNewNode.previous = previousNode;
|
|
126
|
+
upperNewNode.down = newNode;
|
|
127
|
+
newNode.up = upperNewNode;
|
|
128
|
+
newNode = upperNewNode;
|
|
129
|
+
level++;
|
|
130
|
+
}
|
|
131
|
+
this._size++;
|
|
132
|
+
}
|
|
133
|
+
findPreviousNode(value) {
|
|
134
|
+
let currentNode = this.head;
|
|
135
|
+
while (true) {
|
|
136
|
+
while (currentNode.next && (0, types_1.isntNull)(currentNode.next.value)) {
|
|
137
|
+
const result = this.compare(currentNode.next.value, value);
|
|
138
|
+
if (result >= 0) {
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
currentNode = currentNode.next;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (currentNode.down) {
|
|
146
|
+
currentNode = currentNode.down;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return currentNode;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.SkipList = SkipList;
|
|
155
|
+
//# sourceMappingURL=skip-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-list.js","sourceRoot":"","sources":["../../../src/utils/skip-list.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,MAAa,YAAY;IAMvB,YAAmB,KAAe;QAAf,UAAK,GAAL,KAAK,CAAU;QALlC,aAAQ,GAA2B,IAAI,CAAA;QACvC,SAAI,GAA2B,IAAI,CAAA;QACnC,OAAE,GAA2B,IAAI,CAAA;QACjC,SAAI,GAA2B,IAAI,CAAA;IAEE,CAAC;CACvC;AAPD,oCAOC;AAED,MAAa,QAAQ;IAcnB,YAAoB,OAA+B;QAA/B,YAAO,GAAP,OAAO,CAAwB;Q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
|
private _length;
|
|
10
|
-
|
|
10
|
+
readonly growthFactor: number;
|
|
11
11
|
get internalTypedArray(): TypedArrayOfConstructor<T>;
|
|
12
12
|
get [Symbol.toStringTag](): string;
|
|
13
13
|
get capacity(): number;
|
|
@@ -8,7 +8,7 @@ class DynamicTypedArray {
|
|
|
8
8
|
this._length = 0;
|
|
9
9
|
(0, errors_1.assert)(Number.isInteger(capacity), 'capacity must be an integer');
|
|
10
10
|
(0, errors_1.assert)(capacity >= 0, 'capacity must be greater than or equal to 0');
|
|
11
|
-
(0, errors_1.assert)(growthFactor
|
|
11
|
+
(0, errors_1.assert)(growthFactor >= 1, 'growthFactory must be greater than or equal to 1');
|
|
12
12
|
this.array = new typedArrayConstructor(capacity);
|
|
13
13
|
this.growthFactor = growthFactor;
|
|
14
14
|
}
|
|
@@ -81,32 +81,37 @@ class DynamicTypedArray {
|
|
|
81
81
|
}
|
|
82
82
|
exports.DynamicTypedArray = DynamicTypedArray;
|
|
83
83
|
function computeNewCapacity(oldCapacity, targetLength, growthFactor) {
|
|
84
|
-
if (
|
|
84
|
+
if (growthFactor === 1) {
|
|
85
85
|
return targetLength;
|
|
86
86
|
}
|
|
87
|
-
else if (oldCapacity < targetLength) {
|
|
88
|
-
let newCapacity = Math.max(oldCapacity, 1);
|
|
89
|
-
while (newCapacity < targetLength) {
|
|
90
|
-
newCapacity *= growthFactor;
|
|
91
|
-
}
|
|
92
|
-
return Math.floor(newCapacity);
|
|
93
|
-
}
|
|
94
87
|
else {
|
|
95
|
-
if (
|
|
96
|
-
return
|
|
88
|
+
if (oldCapacity === targetLength) {
|
|
89
|
+
return targetLength;
|
|
90
|
+
}
|
|
91
|
+
else if (oldCapacity < targetLength) {
|
|
92
|
+
let newCapacity = Math.max(oldCapacity, 1);
|
|
93
|
+
while (newCapacity < targetLength) {
|
|
94
|
+
newCapacity *= growthFactor;
|
|
95
|
+
}
|
|
96
|
+
return Math.floor(newCapacity);
|
|
97
97
|
}
|
|
98
98
|
else {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
if (targetLength === 0) {
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
let newCapacity = oldCapacity;
|
|
104
|
+
while (true) {
|
|
105
|
+
const temp = newCapacity / growthFactor;
|
|
106
|
+
if (temp < targetLength) {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
newCapacity = temp;
|
|
111
|
+
}
|
|
107
112
|
}
|
|
113
|
+
return Math.floor(newCapacity);
|
|
108
114
|
}
|
|
109
|
-
return Math.floor(newCapacity);
|
|
110
115
|
}
|
|
111
116
|
}
|
|
112
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-typed-array.js","sourceRoot":"","sources":["../../src/dynamic-typed-array.ts"],"names":[],"mappings":";;;AACA,+CAA2C;AAQ3C,MAAa,iBAAiB;IA2B5B,YACU,qBAAwB,EAChC,EACE,QAAQ,GAAG,CAAC,EACZ,YAAY,GAAG,GAAG,KACW,EAAE;QAJzB,0BAAqB,GAArB,qBAAqB,CAAG;QA1B1B,YAAO,GAAW,CAAC,CAAA;QAgCzB,IAAA,eAAM,EAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,6BAA6B,CAAC,CAAA;QACjE,IAAA,eAAM,EAAC,QAAQ,IAAI,CAAC,EAAE,6CAA6C,CAAC,CAAA;QACpE,IAAA,eAAM,EAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"dynamic-typed-array.js","sourceRoot":"","sources":["../../src/dynamic-typed-array.ts"],"names":[],"mappings":";;;AACA,+CAA2C;AAQ3C,MAAa,iBAAiB;IA2B5B,YACU,qBAAwB,EAChC,EACE,QAAQ,GAAG,CAAC,EACZ,YAAY,GAAG,GAAG,KACW,EAAE;QAJzB,0BAAqB,GAArB,qBAAqB,CA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C/B;SACF;KACF;AACH,CAAC;AAtCD,gDAsCC"}
|
package/lib/es2018/index.d.ts
CHANGED
|
@@ -12,4 +12,7 @@ export * from './finite-state-machine';
|
|
|
12
12
|
export * from './observable-finite-state-machine';
|
|
13
13
|
export * from './sparse-set';
|
|
14
14
|
export * from './sparse-map';
|
|
15
|
+
export * from './typed-sparse-map';
|
|
16
|
+
export * from './typed-sparse-set';
|
|
15
17
|
export { DynamicTypedArray } from './dynamic-typed-array';
|
|
18
|
+
export * from './sorted-set';
|
package/lib/es2018/index.js
CHANGED
|
@@ -29,6 +29,9 @@ __exportStar(require("./finite-state-machine"), exports);
|
|
|
29
29
|
__exportStar(require("./observable-finite-state-machine"), exports);
|
|
30
30
|
__exportStar(require("./sparse-set"), exports);
|
|
31
31
|
__exportStar(require("./sparse-map"), exports);
|
|
32
|
+
__exportStar(require("./typed-sparse-map"), exports);
|
|
33
|
+
__exportStar(require("./typed-sparse-set"), exports);
|
|
32
34
|
var dynamic_typed_array_1 = require("./dynamic-typed-array");
|
|
33
35
|
Object.defineProperty(exports, "DynamicTypedArray", { enumerable: true, get: function () { return dynamic_typed_array_1.DynamicTypedArray; } });
|
|
36
|
+
__exportStar(require("./sorted-set"), exports);
|
|
34
37
|
//# sourceMappingURL=index.js.map
|
package/lib/es2018/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wCAAqB;AACrB,yCAAsB;AACtB,4CAAyB;AACzB,6CAA0B;AAC1B,6CAA0B;AAC1B,0CAAuB;AACvB,4CAAyB;AACzB,kDAA+B;AAC/B,6CAA0B;AAC1B,6CAA0B;AAC1B,yDAAsC;AACtC,oEAAiD;AACjD,+CAA4B;AAC5B,+CAA4B;AAC5B,6DAAyD;AAAhD,wHAAA,iBAAiB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wCAAqB;AACrB,yCAAsB;AACtB,4CAAyB;AACzB,6CAA0B;AAC1B,6CAA0B;AAC1B,0CAAuB;AACvB,4CAAyB;AACzB,kDAA+B;AAC/B,6CAA0B;AAC1B,6CAA0B;AAC1B,yDAAsC;AACtC,oEAAiD;AACjD,+CAA4B;AAC5B,+CAA4B;AAC5B,qDAAkC;AAClC,qDAAkC;AAClC,6DAAyD;AAAhD,wHAAA,iBAAiB,OAAA;AAC1B,+CAA4B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class SortedSet<T> implements Iterable<T> {
|
|
2
|
+
private skipList;
|
|
3
|
+
get [Symbol.toStringTag](): string;
|
|
4
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
5
|
+
constructor(compare: (a: T, b: T) => number);
|
|
6
|
+
values(): Iterable<T>;
|
|
7
|
+
has(value: T): boolean;
|
|
8
|
+
add(value: T): void;
|
|
9
|
+
delete(value: T): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SortedSet = void 0;
|
|
4
|
+
const skip_list_1 = require("./utils/skip-list");
|
|
5
|
+
const iterable_operator_1 = require("iterable-operator");
|
|
6
|
+
class SortedSet {
|
|
7
|
+
constructor(compare) {
|
|
8
|
+
this.skipList = new skip_list_1.SkipList(compare);
|
|
9
|
+
}
|
|
10
|
+
get [Symbol.toStringTag]() {
|
|
11
|
+
return this.constructor.name;
|
|
12
|
+
}
|
|
13
|
+
*[Symbol.iterator]() {
|
|
14
|
+
for (const value of this.values()) {
|
|
15
|
+
yield value;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
values() {
|
|
19
|
+
return (0, iterable_operator_1.map)(this.skipList.elements(), node => node.value);
|
|
20
|
+
}
|
|
21
|
+
has(value) {
|
|
22
|
+
return this.skipList.has(value);
|
|
23
|
+
}
|
|
24
|
+
add(value) {
|
|
25
|
+
this.skipList.add(value);
|
|
26
|
+
}
|
|
27
|
+
delete(value) {
|
|
28
|
+
this.skipList.delete(value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.SortedSet = SortedSet;
|
|
32
|
+
//# sourceMappingURL=sorted-set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sorted-set.js","sourceRoot":"","sources":["../../src/sorted-set.ts"],"names":[],"mappings":";;;AAAA,gDAA2C;AAC3C,yDAAuC;AAEvC,MAAa,SAAS;IAapB,YAAY,OAA+B;QACzC,IAAI,CAAC,QAAQ,GAAG,IAAI,oBAAQ,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;IAZD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAED,CAAE,CAAC,MAAM,CAAC,QAAQ,CAAC;QACjB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE;YACjC,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;IAMD,MAAM;QACJ,OAAO,IAAA,uBAAG,EAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAM,CAAC,CAAA;IAC3D,CAAC;IAED,GAAG,CAAC,KAAQ;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC;IAED,GAAG,CAAC,KAAQ;QACV,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;IAED,MAAM,CAAC,KAAQ;QACb,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;CACF;AAhCD,8BAgCC"}
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
interface ISparseMapOptions {
|
|
3
|
-
capacity?: number;
|
|
4
|
-
growthFactor?: number;
|
|
5
|
-
}
|
|
6
|
-
export declare class SparseMap<T extends TypedArrayConstructor> {
|
|
1
|
+
export declare class SparseMap<T> {
|
|
7
2
|
private keyToIndex;
|
|
8
3
|
private indexToKey;
|
|
9
4
|
private indexToValue;
|
|
10
5
|
get [Symbol.toStringTag](): string;
|
|
11
|
-
|
|
12
|
-
entries(): Iterable<[key: number, value: number]>;
|
|
6
|
+
entries(): Iterable<[key: number, value: T]>;
|
|
13
7
|
keys(): Iterable<number>;
|
|
14
|
-
values(): Iterable<
|
|
8
|
+
values(): Iterable<T>;
|
|
15
9
|
has(key: number): boolean;
|
|
16
|
-
get(key: number):
|
|
17
|
-
set(key: number, value:
|
|
10
|
+
get(key: number): T | undefined;
|
|
11
|
+
set(key: number, value: T): void;
|
|
18
12
|
delete(key: number): void;
|
|
19
13
|
}
|
|
20
|
-
export {};
|
package/lib/es2018/sparse-map.js
CHANGED
|
@@ -1,64 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SparseMap = void 0;
|
|
4
|
-
const dynamic_typed_array_1 = require("./dynamic-typed-array");
|
|
5
4
|
class SparseMap {
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
5
|
+
constructor() {
|
|
6
|
+
this.keyToIndex = [];
|
|
7
|
+
this.indexToKey = [];
|
|
8
|
+
this.indexToValue = [];
|
|
10
9
|
}
|
|
11
10
|
get [Symbol.toStringTag]() {
|
|
12
11
|
return this.constructor.name;
|
|
13
12
|
}
|
|
14
13
|
*entries() {
|
|
15
14
|
for (let i = 0; i < this.indexToKey.length; i++) {
|
|
16
|
-
yield [
|
|
17
|
-
this.indexToKey.internalTypedArray[i],
|
|
18
|
-
this.indexToValue.internalTypedArray[i]
|
|
19
|
-
];
|
|
15
|
+
yield [this.indexToKey[i], this.indexToValue[i]];
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
18
|
keys() {
|
|
23
|
-
return this.indexToKey.
|
|
19
|
+
return this.indexToKey.values();
|
|
24
20
|
}
|
|
25
21
|
values() {
|
|
26
|
-
return this.indexToValue.
|
|
22
|
+
return this.indexToValue.values();
|
|
27
23
|
}
|
|
28
24
|
has(key) {
|
|
29
|
-
|
|
30
|
-
return this.indexToKey.internalTypedArray[index] === key;
|
|
25
|
+
return key in this.keyToIndex;
|
|
31
26
|
}
|
|
32
27
|
get(key) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return this.indexToValue
|
|
28
|
+
if (this.has(key)) {
|
|
29
|
+
const index = this.keyToIndex[key];
|
|
30
|
+
return this.indexToValue[index];
|
|
36
31
|
}
|
|
37
32
|
else {
|
|
38
33
|
return undefined;
|
|
39
34
|
}
|
|
40
35
|
}
|
|
41
36
|
set(key, value) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this.indexToValue
|
|
37
|
+
if (this.has(key)) {
|
|
38
|
+
const index = this.keyToIndex[key];
|
|
39
|
+
this.indexToValue[index] = value;
|
|
45
40
|
}
|
|
46
41
|
else {
|
|
47
42
|
const index = this.indexToKey.length;
|
|
48
43
|
this.indexToKey.push(key);
|
|
49
44
|
this.indexToValue.push(value);
|
|
50
|
-
this.keyToIndex
|
|
45
|
+
this.keyToIndex[key] = index;
|
|
51
46
|
}
|
|
52
47
|
}
|
|
53
48
|
delete(key) {
|
|
54
|
-
|
|
55
|
-
if (this.indexToKey.internalTypedArray[index] === key) {
|
|
49
|
+
if (this.has(key)) {
|
|
56
50
|
const lastKey = this.indexToKey.pop();
|
|
57
51
|
const lastValue = this.indexToValue.pop();
|
|
58
|
-
if (key
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
if (key === lastKey) {
|
|
53
|
+
delete this.keyToIndex[key];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const index = this.keyToIndex[key];
|
|
57
|
+
this.indexToKey[index] = lastKey;
|
|
58
|
+
this.indexToValue[index] = lastValue;
|
|
59
|
+
this.keyToIndex[key] = index;
|
|
60
|
+
delete this.keyToIndex[key];
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sparse-map.js","sourceRoot":"","sources":["../../src/sparse-map.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"sparse-map.js","sourceRoot":"","sources":["../../src/sparse-map.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAS;IAAtB;QACU,eAAU,GAA8B,EAAE,CAAA;QAC1C,eAAU,GAAa,EAAE,CAAA;QACzB,iBAAY,GAAQ,EAAE,CAAA;IA6DhC,CAAC;IA3DC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAED,CAAE,OAAO;QACP,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC/C,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;SACjD;IACH,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAA;IACjC,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAA;IACnC,CAAC;IAED,GAAG,CAAC,GAAW;QAEb,OAAO,GAAG,IAAI,IAAI,CAAC,UAAU,CAAA;IAC/B,CAAC;IAED,GAAG,CAAC,GAAW;QACb,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACjB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,C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B;SACF;IACH,CAAC;CACF;AAhED,8BAgEC"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
export interface ISparseSetOptions {
|
|
3
|
-
capacity?: number;
|
|
4
|
-
growthFactor?: number;
|
|
5
|
-
}
|
|
6
|
-
export declare class SparseSet<T extends UnsignedTypedArrayConstructor> implements Iterable<number> {
|
|
7
|
-
private valueToIndex;
|
|
1
|
+
export declare class SparseSet implements Iterable<number> {
|
|
8
2
|
private indexToValue;
|
|
9
|
-
|
|
3
|
+
private valueToIndex;
|
|
10
4
|
get [Symbol.toStringTag](): string;
|
|
11
5
|
[Symbol.iterator](): IterableIterator<number>;
|
|
6
|
+
constructor(array?: number[]);
|
|
7
|
+
values(): Iterable<number>;
|
|
12
8
|
has(value: number): boolean;
|
|
13
9
|
add(value: number): void;
|
|
14
10
|
delete(value: number): void;
|
package/lib/es2018/sparse-set.js
CHANGED
|
@@ -1,36 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SparseSet = void 0;
|
|
4
|
-
const dynamic_typed_array_1 = require("./dynamic-typed-array");
|
|
5
4
|
class SparseSet {
|
|
6
|
-
constructor(
|
|
7
|
-
this.indexToValue =
|
|
8
|
-
|
|
5
|
+
constructor(array = []) {
|
|
6
|
+
this.indexToValue = [];
|
|
7
|
+
const valueToIndex = [];
|
|
8
|
+
if (array.length > 0) {
|
|
9
|
+
for (const [index, value] of array.entries()) {
|
|
10
|
+
valueToIndex[value] = index;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
this.valueToIndex = valueToIndex;
|
|
9
14
|
}
|
|
10
15
|
get [Symbol.toStringTag]() {
|
|
11
16
|
return this.constructor.name;
|
|
12
17
|
}
|
|
13
18
|
[Symbol.iterator]() {
|
|
14
|
-
return this.indexToValue
|
|
19
|
+
return this.indexToValue[Symbol.iterator]();
|
|
20
|
+
}
|
|
21
|
+
values() {
|
|
22
|
+
return this.indexToValue[Symbol.iterator]();
|
|
15
23
|
}
|
|
16
24
|
has(value) {
|
|
17
|
-
|
|
18
|
-
return this.indexToValue.internalTypedArray[index] === value;
|
|
25
|
+
return value in this.valueToIndex;
|
|
19
26
|
}
|
|
20
27
|
add(value) {
|
|
21
28
|
if (!this.has(value)) {
|
|
22
29
|
const index = this.indexToValue.length;
|
|
23
30
|
this.indexToValue.push(value);
|
|
24
|
-
this.valueToIndex
|
|
31
|
+
this.valueToIndex[value] = index;
|
|
25
32
|
}
|
|
26
33
|
}
|
|
27
34
|
delete(value) {
|
|
28
|
-
|
|
29
|
-
if (this.indexToValue.internalTypedArray[index] === value) {
|
|
35
|
+
if (this.has(value)) {
|
|
30
36
|
const lastValue = this.indexToValue.pop();
|
|
31
|
-
if (value
|
|
32
|
-
this.
|
|
33
|
-
|
|
37
|
+
if (value === lastValue) {
|
|
38
|
+
delete this.valueToIndex[value];
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const index = this.valueToIndex[value];
|
|
42
|
+
this.indexToValue[index] = lastValue;
|
|
43
|
+
this.valueToIndex[lastValue] = index;
|
|
44
|
+
delete this.valueToIndex[value];
|
|
34
45
|
}
|
|
35
46
|
}
|
|
36
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sparse-set.js","sourceRoot":"","sources":["../../src/sparse-set.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"sparse-set.js","sourceRoot":"","sources":["../../src/sparse-set.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAS;IAYpB,YAAY,QAAkB,EAAE;QAXxB,iBAAY,GAAa,EAAE,CAAA;QAYjC,MAAM,YAAY,GAA8B,EAAE,CAAA;QAClD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YACpB,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE;gBAC5C,YAAY,CAAC,KAAK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AAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;aAChC;SACF;IACH,CAAC;CACF;AAtDD,8BAsDC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TypedArrayConstructor } from 'justypes';
|
|
2
|
+
import { DynamicTypedArray } from './dynamic-typed-array';
|
|
3
|
+
export declare class TypedSparseMap<T extends TypedArrayConstructor> {
|
|
4
|
+
private keyToIndex;
|
|
5
|
+
private indexToKey;
|
|
6
|
+
private indexToValue;
|
|
7
|
+
get [Symbol.toStringTag](): string;
|
|
8
|
+
constructor(array: DynamicTypedArray<T>);
|
|
9
|
+
entries(): IterableIterator<[key: number, value: number]>;
|
|
10
|
+
keys(): IterableIterator<number>;
|
|
11
|
+
values(): IterableIterator<number>;
|
|
12
|
+
has(key: number): boolean;
|
|
13
|
+
get(key: number): number | undefined;
|
|
14
|
+
set(key: number, value: number): void;
|
|
15
|
+
delete(key: number): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedSparseMap = void 0;
|
|
4
|
+
const errors_1 = require("@blackglory/errors");
|
|
5
|
+
class TypedSparseMap {
|
|
6
|
+
constructor(array) {
|
|
7
|
+
this.keyToIndex = [];
|
|
8
|
+
this.indexToKey = [];
|
|
9
|
+
(0, errors_1.assert)(array.length === 0, 'array should be empty');
|
|
10
|
+
this.indexToValue = array;
|
|
11
|
+
}
|
|
12
|
+
get [Symbol.toStringTag]() {
|
|
13
|
+
return this.constructor.name;
|
|
14
|
+
}
|
|
15
|
+
*entries() {
|
|
16
|
+
for (let i = 0; i < this.indexToKey.length; i++) {
|
|
17
|
+
yield [
|
|
18
|
+
this.indexToKey[i],
|
|
19
|
+
this.indexToValue.internalTypedArray[i]
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
keys() {
|
|
24
|
+
return this.indexToKey.values();
|
|
25
|
+
}
|
|
26
|
+
*values() {
|
|
27
|
+
for (let i = 0; i < this.indexToKey.length; i++) {
|
|
28
|
+
yield this.indexToValue.internalTypedArray[i];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
has(key) {
|
|
32
|
+
const index = this.keyToIndex[key];
|
|
33
|
+
return this.indexToKey[index] === key;
|
|
34
|
+
}
|
|
35
|
+
get(key) {
|
|
36
|
+
const index = this.keyToIndex[key];
|
|
37
|
+
if (this.indexToKey[index] === key) {
|
|
38
|
+
return this.indexToValue.internalTypedArray[index];
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
set(key, value) {
|
|
45
|
+
const index = this.keyToIndex[key];
|
|
46
|
+
if (this.indexToKey[index] === key) {
|
|
47
|
+
this.indexToValue.internalTypedArray[index] = value;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const index = this.indexToKey.length;
|
|
51
|
+
this.indexToKey.push(key);
|
|
52
|
+
this.indexToValue.push(value);
|
|
53
|
+
this.keyToIndex[key] = index;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
delete(key) {
|
|
57
|
+
const index = this.keyToIndex[key];
|
|
58
|
+
if (this.indexToKey[index] === key) {
|
|
59
|
+
const lastKey = this.indexToKey.pop();
|
|
60
|
+
const lastValue = this.indexToValue.pop();
|
|
61
|
+
if (key !== lastKey) {
|
|
62
|
+
this.indexToKey[index] = lastKey;
|
|
63
|
+
this.indexToValue.internalTypedArray[index] = lastValue;
|
|
64
|
+
this.keyToIndex[lastKey] = index;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.TypedSparseMap = TypedSparseMap;
|
|
70
|
+
//# sourceMappingURL=typed-sparse-map.js.map
|