@x-oasis/integer-buffer-set 0.1.20 → 0.1.24
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/dist/index.d.ts +12 -18
- package/dist/integer-buffer-set.cjs.development.js +133 -242
- package/dist/integer-buffer-set.cjs.development.js.map +1 -1
- package/dist/integer-buffer-set.cjs.production.min.js +1 -1
- package/dist/integer-buffer-set.cjs.production.min.js.map +1 -1
- package/dist/integer-buffer-set.esm.js +133 -242
- package/dist/integer-buffer-set.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +208 -360
|
@@ -20,37 +20,6 @@ function _createClass(Constructor, protoProps, staticProps) {
|
|
|
20
20
|
});
|
|
21
21
|
return Constructor;
|
|
22
22
|
}
|
|
23
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
24
|
-
if (!o) return;
|
|
25
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
26
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
27
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
28
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
29
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
30
|
-
}
|
|
31
|
-
function _arrayLikeToArray(arr, len) {
|
|
32
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
33
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
34
|
-
return arr2;
|
|
35
|
-
}
|
|
36
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
37
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
38
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
39
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
40
|
-
if (it) o = it;
|
|
41
|
-
var i = 0;
|
|
42
|
-
return function () {
|
|
43
|
-
if (i >= o.length) return {
|
|
44
|
-
done: true
|
|
45
|
-
};
|
|
46
|
-
return {
|
|
47
|
-
done: false,
|
|
48
|
-
value: o[i++]
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
53
|
-
}
|
|
54
23
|
function _toPrimitive(input, hint) {
|
|
55
24
|
if (typeof input !== "object" || input === null) return input;
|
|
56
25
|
var prim = input[Symbol.toPrimitive];
|
|
@@ -70,6 +39,7 @@ var defaultMetaExtractor = function defaultMetaExtractor(value) {
|
|
|
70
39
|
return value;
|
|
71
40
|
};
|
|
72
41
|
var defaultBufferSize = 10;
|
|
42
|
+
var thresholdNumber = Number.MAX_SAFE_INTEGER - 100000;
|
|
73
43
|
var IntegerBufferSet = /*#__PURE__*/function () {
|
|
74
44
|
function IntegerBufferSet(props) {
|
|
75
45
|
if (props === void 0) {
|
|
@@ -91,37 +61,39 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
91
61
|
this._positionToMetaList = [];
|
|
92
62
|
this._metaToIndexMap = new Map();
|
|
93
63
|
this._onTheFlyIndices = [];
|
|
94
|
-
this._size = 0;
|
|
95
64
|
this._bufferSize = bufferSize;
|
|
96
65
|
this._smallValues = new Heap([], this._smallerComparator);
|
|
97
66
|
this._largeValues = new Heap([], this._greaterComparator);
|
|
98
67
|
this.getNewPositionForIndex = this.getNewPositionForIndex.bind(this);
|
|
99
68
|
this.getIndexPosition = this.getIndexPosition.bind(this);
|
|
100
|
-
this.getSize = this.getSize.bind(this);
|
|
101
|
-
this.replacePositionInFliedIndices = this.replacePositionInFliedIndices.bind(this);
|
|
102
69
|
this.replaceFurthestIndexPosition = this.replaceFurthestIndexPosition.bind(this);
|
|
103
70
|
this._isOnTheFlyFullReturnHook = returnHook(this.setIsOnTheFlyFull.bind(this));
|
|
104
71
|
this._loopMS = Date.now();
|
|
105
72
|
this._lastUpdatedMS = this._loopMS;
|
|
106
73
|
}
|
|
107
74
|
var _proto = IntegerBufferSet.prototype;
|
|
108
|
-
_proto.
|
|
109
|
-
return
|
|
75
|
+
_proto.isThresholdMeta = function isThresholdMeta(meta) {
|
|
76
|
+
if (typeof meta === 'number' && meta > thresholdNumber) return true;
|
|
77
|
+
return false;
|
|
110
78
|
};
|
|
111
79
|
_proto.setIsOnTheFlyFull = function setIsOnTheFlyFull(val) {
|
|
112
80
|
if (val != null) {
|
|
113
81
|
var data = this._onTheFlyIndices.filter(function (v) {
|
|
114
|
-
return v;
|
|
82
|
+
return v != null;
|
|
115
83
|
});
|
|
116
84
|
this._isOnTheFlyFull = data.length === this._bufferSize;
|
|
117
85
|
}
|
|
118
86
|
};
|
|
87
|
+
_proto.resetOnTheFlies = function resetOnTheFlies() {
|
|
88
|
+
this._isOnTheFlyFull = false;
|
|
89
|
+
this._onTheFlyIndices = [];
|
|
90
|
+
};
|
|
119
91
|
_proto.getOnTheFlyUncriticalPosition = function getOnTheFlyUncriticalPosition(safeRange) {
|
|
120
92
|
var startIndex = safeRange.startIndex,
|
|
121
93
|
endIndex = safeRange.endIndex;
|
|
122
94
|
for (var idx = 0; idx < this._onTheFlyIndices.length; idx++) {
|
|
123
95
|
var meta = this._onTheFlyIndices[idx];
|
|
124
|
-
var metaIndex = this.
|
|
96
|
+
var metaIndex = this.getMetaIndex(meta);
|
|
125
97
|
if (!isClamped(startIndex, metaIndex, endIndex)) {
|
|
126
98
|
return idx;
|
|
127
99
|
}
|
|
@@ -131,14 +103,16 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
131
103
|
_proto.initialize = function initialize() {
|
|
132
104
|
return {
|
|
133
105
|
smallValues: new Heap([], this._smallerComparator),
|
|
134
|
-
largeValues: new Heap([], this._greaterComparator)
|
|
135
|
-
valueToPositionObject: {}
|
|
106
|
+
largeValues: new Heap([], this._greaterComparator)
|
|
136
107
|
};
|
|
137
108
|
};
|
|
138
109
|
_proto.getIndexMeta = function getIndexMeta(index) {
|
|
110
|
+
if (index == null || index < 0) return null;
|
|
139
111
|
return this._metaExtractor(index);
|
|
140
112
|
};
|
|
141
113
|
_proto.getMetaIndex = function getMetaIndex(meta) {
|
|
114
|
+
if (meta == null) return -1;
|
|
115
|
+
if (this.isThresholdMeta(meta)) return -1;
|
|
142
116
|
if (this._indexExtractor) return this._indexExtractor(meta);
|
|
143
117
|
return this._metaToIndexMap.get(meta);
|
|
144
118
|
};
|
|
@@ -177,111 +151,53 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
177
151
|
var _this$_largeValues$pe;
|
|
178
152
|
return (_this$_largeValues$pe = this._largeValues.peek()) == null ? void 0 : _this$_largeValues$pe.value;
|
|
179
153
|
};
|
|
180
|
-
_proto.
|
|
181
|
-
_proto.findPositionMeta = function findPositionMeta(position) {
|
|
182
|
-
for (var _iterator = _createForOfIteratorHelperLoose(this._metaToPositionMap), _step; !(_step = _iterator()).done;) {
|
|
183
|
-
var _step$value = _step.value,
|
|
184
|
-
meta = _step$value[0],
|
|
185
|
-
pos = _step$value[1];
|
|
186
|
-
if (pos === position) return meta;
|
|
187
|
-
}
|
|
188
|
-
return null;
|
|
189
|
-
};
|
|
190
|
-
_proto.rebuildHeapsWithMeta = function rebuildHeapsWithMeta(metaToPositionMap) {
|
|
191
|
-
var _this$initialize = this.initialize(),
|
|
192
|
-
smallValues = _this$initialize.smallValues,
|
|
193
|
-
largeValues = _this$initialize.largeValues;
|
|
194
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(metaToPositionMap), _step2; !(_step2 = _iterator2()).done;) {
|
|
195
|
-
var _step2$value = _step2.value,
|
|
196
|
-
meta = _step2$value[0],
|
|
197
|
-
position = _step2$value[1];
|
|
198
|
-
var index = this.getMetaIndex(meta);
|
|
199
|
-
var token = {
|
|
200
|
-
index: index,
|
|
201
|
-
position: position
|
|
202
|
-
};
|
|
203
|
-
smallValues.push(token);
|
|
204
|
-
largeValues.push(token);
|
|
205
|
-
}
|
|
206
|
-
this._smallValues = smallValues;
|
|
207
|
-
this._largeValues = largeValues;
|
|
208
|
-
};
|
|
209
|
-
_proto.setPositionIndex = function setPositionIndex(position, index) {
|
|
210
|
-
var meta = this._metaExtractor(index);
|
|
211
|
-
var originalPosition = this._metaToPositionMap.get(meta);
|
|
212
|
-
if (originalPosition !== undefined) {
|
|
213
|
-
if (originalPosition === position) return true;
|
|
214
|
-
this.deleteMetaIndex(meta);
|
|
215
|
-
}
|
|
216
|
-
var metaToReplace = this.findPositionMeta(position);
|
|
217
|
-
if (metaToReplace) this._metaToPositionMap["delete"](metaToReplace);
|
|
218
|
-
this._metaToPositionMap.set(meta, position);
|
|
219
|
-
this.rebuildHeapsWithMeta(this._metaToPositionMap);
|
|
220
|
-
return true;
|
|
221
|
-
};
|
|
222
|
-
_proto.getMetaPosition = function getMetaPosition(meta) {
|
|
223
|
-
return this._metaToPositionMap.get(meta);
|
|
224
|
-
};
|
|
225
|
-
_proto.replacePositionInFliedIndices = function replacePositionInFliedIndices(newIndex, safeRange) {
|
|
226
|
-
var startIndex = safeRange.startIndex,
|
|
227
|
-
endIndex = safeRange.endIndex;
|
|
154
|
+
_proto.getFliedPosition = function getFliedPosition(newIndex, safeRange) {
|
|
228
155
|
if (this._isOnTheFlyFull) {
|
|
229
|
-
if (
|
|
230
|
-
return
|
|
156
|
+
if (safeRange && isClamped(safeRange.startIndex, newIndex, safeRange.endIndex)) {
|
|
157
|
+
return this.getOnTheFlyUncriticalPosition(safeRange);
|
|
231
158
|
}
|
|
232
|
-
var pos = this.getOnTheFlyUncriticalPosition(safeRange);
|
|
233
|
-
if (pos != null) return pos;
|
|
234
|
-
}
|
|
235
|
-
return null;
|
|
236
|
-
};
|
|
237
|
-
_proto.getFliedPosition = function getFliedPosition(newIndex, safeRange) {
|
|
238
|
-
var pos = this.replacePositionInFliedIndices(newIndex, safeRange);
|
|
239
|
-
if (pos != null) {
|
|
240
|
-
var meta = this.getIndexMeta(newIndex);
|
|
241
|
-
this._onTheFlyIndices[pos] = meta;
|
|
242
|
-
this._setMetaIndex(meta, newIndex);
|
|
243
|
-
return this._isOnTheFlyFullReturnHook(pos);
|
|
244
159
|
}
|
|
245
160
|
return null;
|
|
246
161
|
};
|
|
247
162
|
_proto.getPosition = function getPosition(newIndex, safeRange) {
|
|
248
163
|
this.prepare();
|
|
249
164
|
var meta = this.getIndexMeta(newIndex);
|
|
250
|
-
var
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
if (!this.isBufferFull) return this._isOnTheFlyFullReturnHook(this.getNewPositionForIndex(newIndex));
|
|
272
|
-
if (this._isOnTheFlyFull) return this.getFliedPosition(newIndex, safeRange);
|
|
273
|
-
var positionToReplace;
|
|
274
|
-
var prevIndexMeta = this._indexToMetaMap.get(newIndex);
|
|
275
|
-
if (!prevIndexMeta) {
|
|
276
|
-
this._cleanHeaps();
|
|
277
|
-
positionToReplace = this._replaceFurthestIndexPosition(newIndex, safeRange);
|
|
165
|
+
var metaPosition = this._metaToPositionMap.get(meta);
|
|
166
|
+
var position, indexMeta;
|
|
167
|
+
if (metaPosition !== undefined) {
|
|
168
|
+
position = this.commitPosition({
|
|
169
|
+
newIndex: newIndex,
|
|
170
|
+
meta: meta,
|
|
171
|
+
safeRange: safeRange,
|
|
172
|
+
position: metaPosition
|
|
173
|
+
});
|
|
174
|
+
} else if (!this.isBufferFull) {
|
|
175
|
+
position = this.getNewPositionForIndex(newIndex);
|
|
176
|
+
} else if (this._isOnTheFlyFull) {
|
|
177
|
+
position = this.getFliedPosition(newIndex, safeRange);
|
|
178
|
+
} else if ((indexMeta = this._indexToMetaMap.get(newIndex)) && this._metaToPositionMap.get(indexMeta)) {
|
|
179
|
+
position = this.commitPosition({
|
|
180
|
+
newIndex: newIndex,
|
|
181
|
+
meta: meta,
|
|
182
|
+
safeRange: safeRange,
|
|
183
|
+
position: this._metaToPositionMap.get(indexMeta)
|
|
184
|
+
});
|
|
278
185
|
} else {
|
|
279
|
-
|
|
186
|
+
this._cleanHeaps();
|
|
187
|
+
position = this.commitPosition({
|
|
188
|
+
newIndex: newIndex,
|
|
189
|
+
meta: meta,
|
|
190
|
+
safeRange: safeRange,
|
|
191
|
+
position: this._replaceFurthestIndexPosition(newIndex, safeRange)
|
|
192
|
+
});
|
|
280
193
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
194
|
+
if (position != null) {
|
|
195
|
+
this._onTheFlyIndices[position] = meta;
|
|
196
|
+
this._setMetaIndex(meta, newIndex);
|
|
197
|
+
this._metaToPositionMap.set(meta, position);
|
|
198
|
+
return this._isOnTheFlyFullReturnHook(position);
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
285
201
|
};
|
|
286
202
|
_proto.replaceFurthestIndexPosition = function replaceFurthestIndexPosition(newIndex, safeRange) {
|
|
287
203
|
if (!this.isBufferFull) {
|
|
@@ -293,9 +209,16 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
293
209
|
if (this._largeValues.empty() || this._smallValues.empty()) {
|
|
294
210
|
return this._isOnTheFlyFullReturnHook(this.getNewPositionForIndex(newIndex));
|
|
295
211
|
}
|
|
212
|
+
var indexToReplace;
|
|
296
213
|
var minValue = this._smallValues.peek().value;
|
|
297
214
|
var maxValue = this._largeValues.peek().value;
|
|
298
|
-
|
|
215
|
+
if (maxValue > thresholdNumber) {
|
|
216
|
+
indexToReplace = maxValue;
|
|
217
|
+
this._largeValues.pop();
|
|
218
|
+
var _replacedMeta = this._indexToMetaMap.get(indexToReplace);
|
|
219
|
+
var _position = this._metaToPositionMap.get(_replacedMeta);
|
|
220
|
+
return _position;
|
|
221
|
+
}
|
|
299
222
|
if (!safeRange) {
|
|
300
223
|
if (Math.abs(newIndex - minValue) > Math.abs(newIndex - maxValue)) {
|
|
301
224
|
indexToReplace = minValue;
|
|
@@ -304,9 +227,9 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
304
227
|
indexToReplace = maxValue;
|
|
305
228
|
this._largeValues.pop();
|
|
306
229
|
}
|
|
307
|
-
var
|
|
308
|
-
var
|
|
309
|
-
return
|
|
230
|
+
var _replacedMeta2 = this._indexToMetaMap.get(indexToReplace);
|
|
231
|
+
var _position2 = this._metaToPositionMap.get(_replacedMeta2);
|
|
232
|
+
return _position2;
|
|
310
233
|
}
|
|
311
234
|
var lowValue = safeRange.startIndex,
|
|
312
235
|
highValue = safeRange.endIndex;
|
|
@@ -341,7 +264,6 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
341
264
|
var _available = [];
|
|
342
265
|
var indexToMetaMap = new Map();
|
|
343
266
|
var metaToIndexMap = new Map();
|
|
344
|
-
var metaToPositionMap = new Map();
|
|
345
267
|
var _loop = function _loop() {
|
|
346
268
|
var currentIndex = indices[_idx];
|
|
347
269
|
var currentMeta = _this._metaExtractor(currentIndex);
|
|
@@ -365,71 +287,43 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
365
287
|
var _ret = _loop();
|
|
366
288
|
if (_ret === "continue") continue;
|
|
367
289
|
}
|
|
368
|
-
var _this$initialize2 = this.initialize(),
|
|
369
|
-
smallValues = _this$initialize2.smallValues,
|
|
370
|
-
largeValues = _this$initialize2.largeValues;
|
|
371
290
|
var positionToMetaList = [];
|
|
291
|
+
this._indexToMetaMap = indexToMetaMap;
|
|
292
|
+
this.replaceMetaToIndexMap(metaToIndexMap);
|
|
372
293
|
for (var position = 0; position < indices.length; position++) {
|
|
373
|
-
var value = indices[position];
|
|
374
294
|
if (_arr[position] != null) {
|
|
375
295
|
positionToMetaList[position] = _arr[position];
|
|
376
|
-
metaToPositionMap.set(_arr[position], position);
|
|
377
|
-
var element = {
|
|
378
|
-
position: position,
|
|
379
|
-
value: value
|
|
380
|
-
};
|
|
381
|
-
smallValues.push(element);
|
|
382
|
-
largeValues.push(element);
|
|
383
296
|
continue;
|
|
384
297
|
}
|
|
385
298
|
var _meta = _available.shift();
|
|
386
299
|
if (_meta != null) {
|
|
387
300
|
positionToMetaList[position] = _meta;
|
|
388
|
-
metaToPositionMap.set(_meta, position);
|
|
389
|
-
var _element = {
|
|
390
|
-
position: position,
|
|
391
|
-
value: value
|
|
392
|
-
};
|
|
393
|
-
smallValues.push(_element);
|
|
394
|
-
largeValues.push(_element);
|
|
395
301
|
}
|
|
396
302
|
}
|
|
397
303
|
this._positionToMetaList = positionToMetaList;
|
|
398
|
-
this.
|
|
399
|
-
this._largeValues = largeValues;
|
|
400
|
-
this._indexToMetaMap = indexToMetaMap;
|
|
401
|
-
this.replaceMetaToIndexMap(metaToIndexMap);
|
|
402
|
-
this._metaToPositionMap = metaToPositionMap;
|
|
403
|
-
this._onTheFlyIndices = [];
|
|
404
|
-
try {
|
|
405
|
-
var _indices = new Array(this.bufferSize);
|
|
406
|
-
for (var _idx2 = 0; _idx2 < _indices.length; _idx2++) {
|
|
407
|
-
var _meta2 = this._onTheFlyIndices[_idx2] || this._positionToMetaList[_idx2];
|
|
408
|
-
var _targetIndex = this.getMetaIndex(_meta2);
|
|
409
|
-
if (_meta2 != null) {
|
|
410
|
-
_indices[_idx2] = {
|
|
411
|
-
meta: _meta2,
|
|
412
|
-
targetIndex: _targetIndex,
|
|
413
|
-
recyclerKey: this._name + "_" + _idx2
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
return _indices;
|
|
418
|
-
} catch (err) {
|
|
419
|
-
this.readyToStartNextLoop();
|
|
420
|
-
return this._positionToMetaList;
|
|
421
|
-
}
|
|
304
|
+
return this.getIndices();
|
|
422
305
|
};
|
|
423
306
|
_proto.getIndices = function getIndices() {
|
|
307
|
+
var _this$initialize = this.initialize(),
|
|
308
|
+
smallValues = _this$initialize.smallValues,
|
|
309
|
+
largeValues = _this$initialize.largeValues;
|
|
424
310
|
try {
|
|
425
|
-
var indices = new Array(this.
|
|
311
|
+
var indices = new Array(this._positionToMetaList.length);
|
|
312
|
+
var metaToPositionMap = new Map();
|
|
426
313
|
for (var idx = 0; idx < indices.length; idx++) {
|
|
427
314
|
var meta = this._onTheFlyIndices[idx] || this._positionToMetaList[idx];
|
|
428
315
|
var targetIndex = this.getMetaIndex(meta);
|
|
429
|
-
if (meta
|
|
316
|
+
if (!this.isThresholdMeta(meta) && meta != this.getIndexMeta(targetIndex)) {
|
|
430
317
|
return this.shuffle();
|
|
431
318
|
}
|
|
432
|
-
if (meta != null) {
|
|
319
|
+
if (meta != null && !this.isThresholdMeta(meta)) {
|
|
320
|
+
var element = {
|
|
321
|
+
position: idx,
|
|
322
|
+
value: targetIndex
|
|
323
|
+
};
|
|
324
|
+
smallValues.push(element);
|
|
325
|
+
largeValues.push(element);
|
|
326
|
+
metaToPositionMap.set(meta, idx);
|
|
433
327
|
indices[idx] = {
|
|
434
328
|
meta: meta,
|
|
435
329
|
targetIndex: targetIndex,
|
|
@@ -437,11 +331,19 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
437
331
|
};
|
|
438
332
|
}
|
|
439
333
|
}
|
|
440
|
-
this.
|
|
334
|
+
this._smallValues = smallValues;
|
|
335
|
+
this._largeValues = largeValues;
|
|
336
|
+
this._metaToPositionMap = metaToPositionMap;
|
|
337
|
+
this._positionToMetaList = indices.map(function (v) {
|
|
338
|
+
return v == null ? void 0 : v.meta;
|
|
339
|
+
});
|
|
340
|
+
this.resetOnTheFlies();
|
|
441
341
|
return indices;
|
|
442
342
|
} catch (err) {
|
|
443
|
-
|
|
343
|
+
console.log('err ', err);
|
|
444
344
|
return this._positionToMetaList;
|
|
345
|
+
} finally {
|
|
346
|
+
this.readyToStartNextLoop();
|
|
445
347
|
}
|
|
446
348
|
};
|
|
447
349
|
_proto._pushToHeaps = function _pushToHeaps(position, value) {
|
|
@@ -453,11 +355,26 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
453
355
|
this._largeValues.push(element);
|
|
454
356
|
};
|
|
455
357
|
_proto._setMetaPosition = function _setMetaPosition(meta, position) {
|
|
456
|
-
var prevMetaOnPosition = this._positionToMetaList[position];
|
|
457
|
-
if (prevMetaOnPosition) this._metaToPositionMap["delete"](prevMetaOnPosition);
|
|
458
358
|
this._positionToMetaList[position] = meta;
|
|
459
359
|
this._metaToPositionMap.set(meta, position);
|
|
460
360
|
};
|
|
361
|
+
_proto.commitPosition = function commitPosition(props) {
|
|
362
|
+
var newIndex = props.newIndex,
|
|
363
|
+
safeRange = props.safeRange,
|
|
364
|
+
position = props.position,
|
|
365
|
+
meta = props.meta;
|
|
366
|
+
var onTheFlyPositionMeta = this._onTheFlyIndices[position];
|
|
367
|
+
var positionToReplace = position;
|
|
368
|
+
if (onTheFlyPositionMeta) {
|
|
369
|
+
if (onTheFlyPositionMeta === meta) return position;
|
|
370
|
+
if (this._isOnTheFlyFull) return this.getFliedPosition(newIndex, safeRange);
|
|
371
|
+
positionToReplace = this._replaceFurthestIndexPosition(newIndex, safeRange);
|
|
372
|
+
while (this._onTheFlyIndices[positionToReplace]) {
|
|
373
|
+
positionToReplace = this._replaceFurthestIndexPosition(newIndex, safeRange);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return positionToReplace;
|
|
377
|
+
};
|
|
461
378
|
_proto._setMetaIndex = function _setMetaIndex(meta, index) {
|
|
462
379
|
var prevMetaIndex = this.getMetaIndex(meta);
|
|
463
380
|
if (prevMetaIndex !== undefined) {
|
|
@@ -477,68 +394,42 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
477
394
|
this._isOnTheFlyFull = false;
|
|
478
395
|
};
|
|
479
396
|
_proto._cleanHeaps = function _cleanHeaps() {
|
|
480
|
-
|
|
481
|
-
|
|
397
|
+
for (var idx = 0; idx < this._positionToMetaList.length; idx++) {
|
|
398
|
+
if (this._positionToMetaList[idx] == null) {
|
|
399
|
+
this._recreateHeaps();
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
482
403
|
var minHeapSize = Math.min(this._smallValues.size(), this._largeValues.size());
|
|
483
404
|
var maxHeapSize = Math.max(this._smallValues.size(), this._largeValues.size());
|
|
484
405
|
if (maxHeapSize > 10 * minHeapSize) {
|
|
485
406
|
this._recreateHeaps();
|
|
486
407
|
}
|
|
487
408
|
};
|
|
488
|
-
_proto.rebuildHeapsWithValues = function rebuildHeapsWithValues(arr) {
|
|
489
|
-
var valueToPositionObject = {};
|
|
490
|
-
var newSmallValues = new Heap([], this._smallerComparator);
|
|
491
|
-
var newLargeValues = new Heap([], this._greaterComparator);
|
|
492
|
-
arr.forEach(function (element) {
|
|
493
|
-
var position = element.position,
|
|
494
|
-
value = element.value;
|
|
495
|
-
if (value !== undefined) {
|
|
496
|
-
var _element2 = {
|
|
497
|
-
position: position,
|
|
498
|
-
value: value
|
|
499
|
-
};
|
|
500
|
-
newSmallValues.push(_element2);
|
|
501
|
-
newLargeValues.push(_element2);
|
|
502
|
-
valueToPositionObject[value] = position;
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
var _arr = new Array(this._bufferSize).fill(2);
|
|
506
|
-
Object.keys(valueToPositionObject).map(function (key) {
|
|
507
|
-
return _arr[valueToPositionObject[key]] = 1;
|
|
508
|
-
});
|
|
509
|
-
_arr.forEach(function (_i, position) {
|
|
510
|
-
if (_i === 2) {
|
|
511
|
-
var value = Number.MAX_SAFE_INTEGER - position;
|
|
512
|
-
var element = {
|
|
513
|
-
position: position,
|
|
514
|
-
value: value
|
|
515
|
-
};
|
|
516
|
-
newSmallValues.push(element);
|
|
517
|
-
newLargeValues.push(element);
|
|
518
|
-
valueToPositionObject[value] = position;
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
this._smallValues = newSmallValues;
|
|
522
|
-
this._largeValues = newLargeValues;
|
|
523
|
-
};
|
|
524
409
|
_proto._recreateHeaps = function _recreateHeaps() {
|
|
525
|
-
var
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
var
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
410
|
+
var _this$initialize2 = this.initialize(),
|
|
411
|
+
smallValues = _this$initialize2.smallValues,
|
|
412
|
+
largeValues = _this$initialize2.largeValues;
|
|
413
|
+
for (var position = 0; position < this._positionToMetaList.length; position++) {
|
|
414
|
+
var meta = this._positionToMetaList[position];
|
|
415
|
+
var value = this.getMetaIndex(meta);
|
|
416
|
+
if (!meta || value === -1 || value == null) {
|
|
417
|
+
value = Number.MAX_SAFE_INTEGER - position;
|
|
418
|
+
}
|
|
419
|
+
var element = {
|
|
420
|
+
position: position,
|
|
421
|
+
value: value
|
|
422
|
+
};
|
|
423
|
+
smallValues.push(element);
|
|
424
|
+
largeValues.push(element);
|
|
425
|
+
if (value > thresholdNumber) {
|
|
426
|
+
this._setMetaPosition(value, position);
|
|
427
|
+
this._setMetaIndex(value, value);
|
|
533
428
|
}
|
|
534
429
|
}
|
|
535
|
-
this.
|
|
536
|
-
this.
|
|
537
|
-
|
|
538
|
-
_proto._cleanHeap = function _cleanHeap(heap) {
|
|
539
|
-
while (!heap.empty() && this._metaToPositionMap.get(this._indexToMetaMap.get(heap.peek().value)) == null) {
|
|
540
|
-
heap.pop();
|
|
541
|
-
}
|
|
430
|
+
this._largeValues.peek().value;
|
|
431
|
+
this._smallValues = smallValues;
|
|
432
|
+
this._largeValues = largeValues;
|
|
542
433
|
};
|
|
543
434
|
_proto._smallerComparator = function _smallerComparator(lhs, rhs) {
|
|
544
435
|
return lhs.value < rhs.value;
|