@x-oasis/integer-buffer-set 0.1.19 → 0.1.23
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 +23 -1
- package/dist/index.d.ts +50 -25
- package/dist/integer-buffer-set.cjs.development.js +330 -84
- 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 +330 -84
- package/dist/integer-buffer-set.esm.js.map +1 -1
- package/dist/types.d.ts +24 -0
- package/package.json +6 -2
- package/src/index.ts +472 -139
- package/src/types.ts +36 -0
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import Heap from '@x-oasis/heap';
|
|
2
|
+
import isClamped from '@x-oasis/is-clamped';
|
|
3
|
+
import invariant from '@x-oasis/invariant';
|
|
4
|
+
import returnHook from '@x-oasis/return-hook';
|
|
2
5
|
|
|
3
6
|
function _defineProperties(target, props) {
|
|
4
7
|
for (var i = 0; i < props.length; i++) {
|
|
@@ -32,45 +35,102 @@ function _toPropertyKey(arg) {
|
|
|
32
35
|
return typeof key === "symbol" ? key : String(key);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
bufferSetRange = options.bufferSetRange;
|
|
38
|
-
var lowValue = safeRange.lowValue,
|
|
39
|
-
highValue = safeRange.highValue;
|
|
40
|
-
var maxValue = bufferSetRange.maxValue,
|
|
41
|
-
minValue = bufferSetRange.minValue;
|
|
42
|
-
return lowValue - minValue > maxValue - highValue;
|
|
38
|
+
var defaultMetaExtractor = function defaultMetaExtractor(value) {
|
|
39
|
+
return value;
|
|
43
40
|
};
|
|
41
|
+
var defaultBufferSize = 10;
|
|
44
42
|
var IntegerBufferSet = /*#__PURE__*/function () {
|
|
45
|
-
function IntegerBufferSet() {
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
function IntegerBufferSet(props) {
|
|
44
|
+
if (props === void 0) {
|
|
45
|
+
props = {};
|
|
46
|
+
}
|
|
47
|
+
var _props = props,
|
|
48
|
+
_props$name = _props.name,
|
|
49
|
+
name = _props$name === void 0 ? 'default_buffer' : _props$name,
|
|
50
|
+
indexExtractor = _props.indexExtractor,
|
|
51
|
+
_props$bufferSize = _props.bufferSize,
|
|
52
|
+
bufferSize = _props$bufferSize === void 0 ? defaultBufferSize : _props$bufferSize,
|
|
53
|
+
_props$metaExtractor = _props.metaExtractor,
|
|
54
|
+
metaExtractor = _props$metaExtractor === void 0 ? defaultMetaExtractor : _props$metaExtractor;
|
|
55
|
+
this._metaExtractor = metaExtractor;
|
|
56
|
+
this._indexExtractor = indexExtractor;
|
|
57
|
+
this._name = name;
|
|
58
|
+
this._indexToMetaMap = new Map();
|
|
59
|
+
this._metaToPositionMap = new Map();
|
|
60
|
+
this._positionToMetaList = [];
|
|
61
|
+
this._metaToIndexMap = new Map();
|
|
62
|
+
this._onTheFlyIndices = [];
|
|
63
|
+
this._bufferSize = bufferSize;
|
|
48
64
|
this._smallValues = new Heap([], this._smallerComparator);
|
|
49
65
|
this._largeValues = new Heap([], this._greaterComparator);
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
66
|
+
this.getNewPositionForIndex = this.getNewPositionForIndex.bind(this);
|
|
67
|
+
this.getIndexPosition = this.getIndexPosition.bind(this);
|
|
68
|
+
this.replacePositionInFliedIndices = this.replacePositionInFliedIndices.bind(this);
|
|
69
|
+
this.replaceFurthestIndexPosition = this.replaceFurthestIndexPosition.bind(this);
|
|
70
|
+
this._isOnTheFlyFullReturnHook = returnHook(this.setIsOnTheFlyFull.bind(this));
|
|
71
|
+
this._loopMS = Date.now();
|
|
72
|
+
this._lastUpdatedMS = this._loopMS;
|
|
55
73
|
}
|
|
56
74
|
var _proto = IntegerBufferSet.prototype;
|
|
57
|
-
_proto.
|
|
58
|
-
|
|
75
|
+
_proto.setIsOnTheFlyFull = function setIsOnTheFlyFull(val) {
|
|
76
|
+
if (val != null) {
|
|
77
|
+
var data = this._onTheFlyIndices.filter(function (v) {
|
|
78
|
+
return v;
|
|
79
|
+
});
|
|
80
|
+
this._isOnTheFlyFull = data.length === this._bufferSize;
|
|
81
|
+
}
|
|
59
82
|
};
|
|
60
|
-
_proto.
|
|
61
|
-
|
|
62
|
-
|
|
83
|
+
_proto.getOnTheFlyUncriticalPosition = function getOnTheFlyUncriticalPosition(safeRange) {
|
|
84
|
+
var startIndex = safeRange.startIndex,
|
|
85
|
+
endIndex = safeRange.endIndex;
|
|
86
|
+
for (var idx = 0; idx < this._onTheFlyIndices.length; idx++) {
|
|
87
|
+
var meta = this._onTheFlyIndices[idx];
|
|
88
|
+
var metaIndex = this._metaToIndexMap.get(meta);
|
|
89
|
+
if (!isClamped(startIndex, metaIndex, endIndex)) {
|
|
90
|
+
return idx;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
};
|
|
95
|
+
_proto.initialize = function initialize() {
|
|
96
|
+
return {
|
|
97
|
+
smallValues: new Heap([], this._smallerComparator),
|
|
98
|
+
largeValues: new Heap([], this._greaterComparator),
|
|
99
|
+
valueToPositionObject: {}
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
_proto.getIndexMeta = function getIndexMeta(index) {
|
|
103
|
+
return this._metaExtractor(index);
|
|
104
|
+
};
|
|
105
|
+
_proto.getMetaIndex = function getMetaIndex(meta) {
|
|
106
|
+
if (this._indexExtractor) return this._indexExtractor(meta);
|
|
107
|
+
return this._metaToIndexMap.get(meta);
|
|
108
|
+
};
|
|
109
|
+
_proto.setMetaIndex = function setMetaIndex(meta, index) {
|
|
110
|
+
if (!this._indexExtractor) {
|
|
111
|
+
return this._metaToIndexMap.set(meta, index);
|
|
63
112
|
}
|
|
64
|
-
return
|
|
113
|
+
return false;
|
|
65
114
|
};
|
|
66
|
-
_proto.
|
|
67
|
-
|
|
68
|
-
|
|
115
|
+
_proto.deleteMetaIndex = function deleteMetaIndex(meta) {
|
|
116
|
+
return this._metaToIndexMap["delete"](meta);
|
|
117
|
+
};
|
|
118
|
+
_proto.replaceMetaToIndexMap = function replaceMetaToIndexMap(newMetaToIndexMap) {
|
|
119
|
+
if (!this._indexExtractor) {
|
|
120
|
+
return this._metaToIndexMap = newMetaToIndexMap;
|
|
69
121
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
this.
|
|
122
|
+
return false;
|
|
123
|
+
};
|
|
124
|
+
_proto.getIndexPosition = function getIndexPosition(index) {
|
|
125
|
+
return this.getMetaIndex(this.getIndexMeta(index));
|
|
126
|
+
};
|
|
127
|
+
_proto.getNewPositionForIndex = function getNewPositionForIndex(index) {
|
|
128
|
+
var meta = this.getIndexMeta(index);
|
|
129
|
+
!(this._metaToPositionMap.get(meta) === undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, "Shouldn't try to find new position for value already stored in BufferSet") : invariant(false) : void 0;
|
|
130
|
+
var newPosition = this._positionToMetaList.length;
|
|
131
|
+
this._pushToHeaps(newPosition, index);
|
|
132
|
+
this._setMetaIndex(meta, index);
|
|
133
|
+
this._setMetaPosition(meta, newPosition);
|
|
74
134
|
return newPosition;
|
|
75
135
|
};
|
|
76
136
|
_proto.getMinValue = function getMinValue() {
|
|
@@ -81,67 +141,228 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
81
141
|
var _this$_largeValues$pe;
|
|
82
142
|
return (_this$_largeValues$pe = this._largeValues.peek()) == null ? void 0 : _this$_largeValues$pe.value;
|
|
83
143
|
};
|
|
84
|
-
_proto.
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
144
|
+
_proto.replacePositionInFliedIndices = function replacePositionInFliedIndices(newIndex, safeRange) {
|
|
145
|
+
var startIndex = safeRange.startIndex,
|
|
146
|
+
endIndex = safeRange.endIndex;
|
|
147
|
+
if (this._isOnTheFlyFull) {
|
|
148
|
+
if (!isClamped(startIndex, newIndex, endIndex)) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
var pos = this.getOnTheFlyUncriticalPosition(safeRange);
|
|
152
|
+
if (pos != null) return pos;
|
|
93
153
|
}
|
|
154
|
+
return null;
|
|
94
155
|
};
|
|
95
|
-
_proto.
|
|
96
|
-
|
|
97
|
-
|
|
156
|
+
_proto.getFliedPosition = function getFliedPosition(newIndex, safeRange) {
|
|
157
|
+
var pos = this.replacePositionInFliedIndices(newIndex, safeRange);
|
|
158
|
+
if (pos != null) {
|
|
159
|
+
var meta = this.getIndexMeta(newIndex);
|
|
160
|
+
this._onTheFlyIndices[pos] = meta;
|
|
161
|
+
this._setMetaIndex(meta, newIndex);
|
|
162
|
+
return this._isOnTheFlyFullReturnHook(pos);
|
|
98
163
|
}
|
|
99
|
-
|
|
100
|
-
|
|
164
|
+
return null;
|
|
165
|
+
};
|
|
166
|
+
_proto.getPosition = function getPosition(newIndex, safeRange) {
|
|
167
|
+
this.prepare();
|
|
168
|
+
var meta = this.getIndexMeta(newIndex);
|
|
169
|
+
var prevMetaPosition = this._metaToPositionMap.get(meta);
|
|
170
|
+
if (prevMetaPosition !== undefined) {
|
|
171
|
+
var onTheFlyPositionMeta = this._onTheFlyIndices[prevMetaPosition];
|
|
172
|
+
if (onTheFlyPositionMeta) {
|
|
173
|
+
if (onTheFlyPositionMeta === meta) {
|
|
174
|
+
return prevMetaPosition;
|
|
175
|
+
}
|
|
176
|
+
var _positionToReplace = this._replaceFurthestIndexPosition(newIndex, safeRange);
|
|
177
|
+
if (this._isOnTheFlyFull) return this.getFliedPosition(newIndex, safeRange);
|
|
178
|
+
while (this._onTheFlyIndices[_positionToReplace]) {
|
|
179
|
+
_positionToReplace = this._replaceFurthestIndexPosition(newIndex, safeRange);
|
|
180
|
+
}
|
|
181
|
+
if (_positionToReplace != null) {
|
|
182
|
+
this._setMetaIndex(meta, newIndex);
|
|
183
|
+
this._onTheFlyIndices[_positionToReplace] = onTheFlyPositionMeta;
|
|
184
|
+
return this._isOnTheFlyFullReturnHook(_positionToReplace);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
this._onTheFlyIndices[prevMetaPosition] = meta;
|
|
188
|
+
return this._isOnTheFlyFullReturnHook(prevMetaPosition);
|
|
101
189
|
}
|
|
102
|
-
this.
|
|
103
|
-
if (this.
|
|
104
|
-
|
|
190
|
+
if (!this.isBufferFull) return this._isOnTheFlyFullReturnHook(this.getNewPositionForIndex(newIndex));
|
|
191
|
+
if (this._isOnTheFlyFull) return this.getFliedPosition(newIndex, safeRange);
|
|
192
|
+
var positionToReplace;
|
|
193
|
+
var prevIndexMeta = this._indexToMetaMap.get(newIndex);
|
|
194
|
+
if (!prevIndexMeta) {
|
|
195
|
+
this._cleanHeaps();
|
|
196
|
+
positionToReplace = this._replaceFurthestIndexPosition(newIndex, safeRange);
|
|
197
|
+
} else {
|
|
198
|
+
positionToReplace = this._metaToPositionMap.get(prevIndexMeta);
|
|
105
199
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
200
|
+
this._onTheFlyIndices[positionToReplace] = meta;
|
|
201
|
+
this._setMetaIndex(meta, newIndex);
|
|
202
|
+
this._setMetaPosition(meta, positionToReplace);
|
|
203
|
+
return this._isOnTheFlyFullReturnHook(positionToReplace);
|
|
204
|
+
};
|
|
205
|
+
_proto.replaceFurthestIndexPosition = function replaceFurthestIndexPosition(newIndex, safeRange) {
|
|
206
|
+
if (!this.isBufferFull) {
|
|
207
|
+
return this._isOnTheFlyFullReturnHook(this.getNewPositionForIndex(newIndex));
|
|
208
|
+
}
|
|
209
|
+
return this._replaceFurthestIndexPosition(newIndex, safeRange);
|
|
210
|
+
};
|
|
211
|
+
_proto._replaceFurthestIndexPosition = function _replaceFurthestIndexPosition(newIndex, safeRange) {
|
|
212
|
+
if (this._largeValues.empty() || this._smallValues.empty()) {
|
|
213
|
+
return this._isOnTheFlyFullReturnHook(this.getNewPositionForIndex(newIndex));
|
|
111
214
|
}
|
|
112
215
|
var minValue = this._smallValues.peek().value;
|
|
113
216
|
var maxValue = this._largeValues.peek().value;
|
|
114
|
-
|
|
115
|
-
|
|
217
|
+
var indexToReplace;
|
|
218
|
+
if (!safeRange) {
|
|
219
|
+
if (Math.abs(newIndex - minValue) > Math.abs(newIndex - maxValue)) {
|
|
220
|
+
indexToReplace = minValue;
|
|
221
|
+
this._smallValues.pop();
|
|
222
|
+
} else {
|
|
223
|
+
indexToReplace = maxValue;
|
|
224
|
+
this._largeValues.pop();
|
|
225
|
+
}
|
|
226
|
+
var _replacedMeta = this._indexToMetaMap.get(indexToReplace);
|
|
227
|
+
var _position = this._metaToPositionMap.get(_replacedMeta);
|
|
228
|
+
return _position;
|
|
116
229
|
}
|
|
117
|
-
var
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
valueToReplace = minValue;
|
|
230
|
+
var lowValue = safeRange.startIndex,
|
|
231
|
+
highValue = safeRange.endIndex;
|
|
232
|
+
if (isClamped(lowValue, minValue, highValue) && isClamped(lowValue, maxValue, highValue)) {
|
|
233
|
+
return null;
|
|
234
|
+
} else if (isClamped(lowValue, minValue, highValue) && !isClamped(lowValue, maxValue, highValue)) {
|
|
235
|
+
indexToReplace = maxValue;
|
|
236
|
+
this._largeValues.pop();
|
|
237
|
+
} else if (!isClamped(lowValue, minValue, highValue) && isClamped(lowValue, maxValue, highValue)) {
|
|
238
|
+
indexToReplace = minValue;
|
|
239
|
+
this._smallValues.pop();
|
|
240
|
+
} else if (lowValue - minValue > maxValue - highValue) {
|
|
241
|
+
indexToReplace = minValue;
|
|
130
242
|
this._smallValues.pop();
|
|
131
243
|
} else {
|
|
132
|
-
|
|
244
|
+
indexToReplace = maxValue;
|
|
133
245
|
this._largeValues.pop();
|
|
134
246
|
}
|
|
135
|
-
var
|
|
136
|
-
|
|
137
|
-
this._valueToPositionMap[newValue] = position;
|
|
138
|
-
this._pushToHeaps(position, newValue);
|
|
139
|
-
var _i = this._vacantPositions.findIndex(function (v) {
|
|
140
|
-
return v === position;
|
|
141
|
-
});
|
|
142
|
-
if (_i !== -1) this._vacantPositions.splice(_i, 1);
|
|
247
|
+
var replacedMeta = this._indexToMetaMap.get(indexToReplace);
|
|
248
|
+
var position = this._metaToPositionMap.get(replacedMeta);
|
|
143
249
|
return position;
|
|
144
250
|
};
|
|
251
|
+
_proto.shuffle = function shuffle() {
|
|
252
|
+
var _this = this;
|
|
253
|
+
var indices = new Array(this.bufferSize);
|
|
254
|
+
for (var idx = 0; idx < indices.length; idx++) {
|
|
255
|
+
var meta = this._onTheFlyIndices[idx] || this._positionToMetaList[idx];
|
|
256
|
+
var targetIndex = this.getMetaIndex(meta);
|
|
257
|
+
indices[idx] = targetIndex;
|
|
258
|
+
}
|
|
259
|
+
var _arr = new Array(indices.length);
|
|
260
|
+
var _available = [];
|
|
261
|
+
var indexToMetaMap = new Map();
|
|
262
|
+
var metaToIndexMap = new Map();
|
|
263
|
+
var metaToPositionMap = new Map();
|
|
264
|
+
var _loop = function _loop() {
|
|
265
|
+
var currentIndex = indices[_idx];
|
|
266
|
+
var currentMeta = _this._metaExtractor(currentIndex);
|
|
267
|
+
if (currentMeta == null) return "continue";
|
|
268
|
+
indexToMetaMap.set(currentIndex, currentMeta);
|
|
269
|
+
metaToIndexMap.set(currentMeta, currentIndex);
|
|
270
|
+
if (currentMeta === _this._positionToMetaList[_idx]) {
|
|
271
|
+
_arr[_idx] = currentMeta;
|
|
272
|
+
return "continue";
|
|
273
|
+
}
|
|
274
|
+
var _i = _this._positionToMetaList.findIndex(function (v) {
|
|
275
|
+
return v === currentMeta;
|
|
276
|
+
});
|
|
277
|
+
if (_i !== -1) {
|
|
278
|
+
_arr[_i] = currentMeta;
|
|
279
|
+
return "continue";
|
|
280
|
+
}
|
|
281
|
+
_available.push(currentMeta);
|
|
282
|
+
};
|
|
283
|
+
for (var _idx = 0; _idx < indices.length; _idx++) {
|
|
284
|
+
var _ret = _loop();
|
|
285
|
+
if (_ret === "continue") continue;
|
|
286
|
+
}
|
|
287
|
+
var _this$initialize = this.initialize(),
|
|
288
|
+
smallValues = _this$initialize.smallValues,
|
|
289
|
+
largeValues = _this$initialize.largeValues;
|
|
290
|
+
var positionToMetaList = [];
|
|
291
|
+
for (var position = 0; position < indices.length; position++) {
|
|
292
|
+
var value = indices[position];
|
|
293
|
+
if (_arr[position] != null) {
|
|
294
|
+
positionToMetaList[position] = _arr[position];
|
|
295
|
+
metaToPositionMap.set(_arr[position], position);
|
|
296
|
+
var element = {
|
|
297
|
+
position: position,
|
|
298
|
+
value: value
|
|
299
|
+
};
|
|
300
|
+
smallValues.push(element);
|
|
301
|
+
largeValues.push(element);
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
var _meta = _available.shift();
|
|
305
|
+
if (_meta != null) {
|
|
306
|
+
positionToMetaList[position] = _meta;
|
|
307
|
+
metaToPositionMap.set(_meta, position);
|
|
308
|
+
var _element = {
|
|
309
|
+
position: position,
|
|
310
|
+
value: value
|
|
311
|
+
};
|
|
312
|
+
smallValues.push(_element);
|
|
313
|
+
largeValues.push(_element);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
this._positionToMetaList = positionToMetaList;
|
|
317
|
+
this._smallValues = smallValues;
|
|
318
|
+
this._largeValues = largeValues;
|
|
319
|
+
this._indexToMetaMap = indexToMetaMap;
|
|
320
|
+
this.replaceMetaToIndexMap(metaToIndexMap);
|
|
321
|
+
this._metaToPositionMap = metaToPositionMap;
|
|
322
|
+
this._onTheFlyIndices = [];
|
|
323
|
+
try {
|
|
324
|
+
var _indices = new Array(this.bufferSize);
|
|
325
|
+
for (var _idx2 = 0; _idx2 < _indices.length; _idx2++) {
|
|
326
|
+
var _meta2 = this._onTheFlyIndices[_idx2] || this._positionToMetaList[_idx2];
|
|
327
|
+
var _targetIndex = this.getMetaIndex(_meta2);
|
|
328
|
+
if (_meta2 != null) {
|
|
329
|
+
_indices[_idx2] = {
|
|
330
|
+
meta: _meta2,
|
|
331
|
+
targetIndex: _targetIndex,
|
|
332
|
+
recyclerKey: this._name + "_" + _idx2
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return _indices;
|
|
337
|
+
} catch (err) {
|
|
338
|
+
this.readyToStartNextLoop();
|
|
339
|
+
return this._positionToMetaList;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
_proto.getIndices = function getIndices() {
|
|
343
|
+
try {
|
|
344
|
+
var indices = new Array(this.bufferSize);
|
|
345
|
+
for (var idx = 0; idx < indices.length; idx++) {
|
|
346
|
+
var meta = this._onTheFlyIndices[idx] || this._positionToMetaList[idx];
|
|
347
|
+
var targetIndex = this.getMetaIndex(meta);
|
|
348
|
+
if (meta !== this.getIndexMeta(targetIndex)) {
|
|
349
|
+
return this.shuffle();
|
|
350
|
+
}
|
|
351
|
+
if (meta != null) {
|
|
352
|
+
indices[idx] = {
|
|
353
|
+
meta: meta,
|
|
354
|
+
targetIndex: targetIndex,
|
|
355
|
+
recyclerKey: this._name + "_" + idx
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
this._onTheFlyIndices = [];
|
|
360
|
+
return indices;
|
|
361
|
+
} catch (err) {
|
|
362
|
+
this.readyToStartNextLoop();
|
|
363
|
+
return this._positionToMetaList;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
145
366
|
_proto._pushToHeaps = function _pushToHeaps(position, value) {
|
|
146
367
|
var element = {
|
|
147
368
|
position: position,
|
|
@@ -150,6 +371,30 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
150
371
|
this._smallValues.push(element);
|
|
151
372
|
this._largeValues.push(element);
|
|
152
373
|
};
|
|
374
|
+
_proto._setMetaPosition = function _setMetaPosition(meta, position) {
|
|
375
|
+
var prevMetaOnPosition = this._positionToMetaList[position];
|
|
376
|
+
if (prevMetaOnPosition) this._metaToPositionMap["delete"](prevMetaOnPosition);
|
|
377
|
+
this._positionToMetaList[position] = meta;
|
|
378
|
+
this._metaToPositionMap.set(meta, position);
|
|
379
|
+
};
|
|
380
|
+
_proto._setMetaIndex = function _setMetaIndex(meta, index) {
|
|
381
|
+
var prevMetaIndex = this.getMetaIndex(meta);
|
|
382
|
+
if (prevMetaIndex !== undefined) {
|
|
383
|
+
this._indexToMetaMap["delete"](prevMetaIndex);
|
|
384
|
+
}
|
|
385
|
+
this.setMetaIndex(meta, index);
|
|
386
|
+
this._indexToMetaMap.set(index, meta);
|
|
387
|
+
return false;
|
|
388
|
+
};
|
|
389
|
+
_proto.readyToStartNextLoop = function readyToStartNextLoop() {
|
|
390
|
+
this._lastUpdatedMS = Date.now();
|
|
391
|
+
};
|
|
392
|
+
_proto.prepare = function prepare() {
|
|
393
|
+
if (this._loopMS === this._lastUpdatedMS) return;
|
|
394
|
+
this._loopMS = this._lastUpdatedMS;
|
|
395
|
+
this._onTheFlyIndices = [];
|
|
396
|
+
this._isOnTheFlyFull = false;
|
|
397
|
+
};
|
|
153
398
|
_proto._cleanHeaps = function _cleanHeaps() {
|
|
154
399
|
this._cleanHeap(this._smallValues);
|
|
155
400
|
this._cleanHeap(this._largeValues);
|
|
@@ -165,7 +410,7 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
165
410
|
var newLargeValues = new Heap([], this._greaterComparator);
|
|
166
411
|
while (!sourceHeap.empty()) {
|
|
167
412
|
var element = sourceHeap.pop();
|
|
168
|
-
if (this.
|
|
413
|
+
if (this._metaToPositionMap.get(this._indexToMetaMap.get(element.value)) != null) {
|
|
169
414
|
newSmallValues.push(element);
|
|
170
415
|
newLargeValues.push(element);
|
|
171
416
|
}
|
|
@@ -174,7 +419,7 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
174
419
|
this._largeValues = newLargeValues;
|
|
175
420
|
};
|
|
176
421
|
_proto._cleanHeap = function _cleanHeap(heap) {
|
|
177
|
-
while (!heap.empty() && this.
|
|
422
|
+
while (!heap.empty() && this._metaToPositionMap.get(this._indexToMetaMap.get(heap.peek().value)) == null) {
|
|
178
423
|
heap.pop();
|
|
179
424
|
}
|
|
180
425
|
};
|
|
@@ -185,18 +430,19 @@ var IntegerBufferSet = /*#__PURE__*/function () {
|
|
|
185
430
|
return lhs.value > rhs.value;
|
|
186
431
|
};
|
|
187
432
|
_createClass(IntegerBufferSet, [{
|
|
188
|
-
key: "
|
|
433
|
+
key: "bufferSize",
|
|
189
434
|
get: function get() {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return
|
|
435
|
+
return this._bufferSize;
|
|
436
|
+
}
|
|
437
|
+
}, {
|
|
438
|
+
key: "isBufferFull",
|
|
439
|
+
get: function get() {
|
|
440
|
+
return this._positionToMetaList.length >= this._bufferSize;
|
|
196
441
|
}
|
|
197
442
|
}]);
|
|
198
443
|
return IntegerBufferSet;
|
|
199
444
|
}();
|
|
200
445
|
|
|
201
446
|
export default IntegerBufferSet;
|
|
447
|
+
export { defaultBufferSize };
|
|
202
448
|
//# sourceMappingURL=integer-buffer-set.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integer-buffer-set.esm.js","sources":["../src/index.ts"],"sourcesContent":["// import invariant from 'invariant';\nimport Heap from '@x-oasis/heap';\n\ntype HeapItem = {\n position: number;\n value: number;\n};\n\nconst defaultUseMinValueFn = (options: {\n safeRange: {\n lowValue: number;\n highValue: number;\n };\n bufferSetRange: {\n maxValue: number;\n minValue: number;\n };\n currentIndex: number;\n}) => {\n const { safeRange, bufferSetRange } = options;\n const { lowValue, highValue } = safeRange;\n const { maxValue, minValue } = bufferSetRange;\n return lowValue - minValue > maxValue - highValue;\n};\n\n// Data structure that allows to store values and assign positions to them\n// in a way to minimize changing positions of stored values when new ones are\n// added or when some values are replaced. Stored elements are alwasy assigned\n// a consecutive set of positoins startin from 0 up to count of elements less 1\n// Following actions can be executed\n// * get position assigned to given value (null if value is not stored)\n// * create new entry for new value and get assigned position back\n// * replace value that is furthest from specified value range with new value\n// and get it's position back\n// All operations take amortized log(n) time where n is number of elements in\n// the set.\nclass IntegerBufferSet {\n private _size: number;\n private _valueToPositionMap: {\n [key: string]: number;\n };\n private _smallValues: Heap<HeapItem>;\n private _largeValues: Heap<HeapItem>;\n private _vacantPositions: Array<number>;\n\n constructor() {\n this._valueToPositionMap = {};\n this._size = 0;\n this._smallValues = new Heap([], this._smallerComparator);\n this._largeValues = new Heap([], this._greaterComparator);\n\n this.getNewPositionForValue = this.getNewPositionForValue.bind(this);\n this.getValuePosition = this.getValuePosition.bind(this);\n this.getSize = this.getSize.bind(this);\n this.replaceFurthestValuePosition =\n this.replaceFurthestValuePosition.bind(this);\n\n this._vacantPositions = [];\n }\n\n getSize() {\n return this._size;\n }\n\n get indices() {\n const indices = [];\n for (const key in this._valueToPositionMap) {\n const value = this._valueToPositionMap[key];\n indices[value] = key;\n }\n return indices;\n }\n\n getValuePosition(value: number): null | number {\n if (this._valueToPositionMap[value] === undefined) {\n return null;\n }\n return this._valueToPositionMap[value];\n }\n\n getNewPositionForValue(value: number) {\n if (this._valueToPositionMap[value] !== undefined) {\n console.warn(\n \"Shouldn't try to find new position for value already stored in BufferSet\"\n );\n }\n // invariant(\n // this._valueToPositionMap[value] === undefined,\n // \"Shouldn't try to find new position for value already stored in BufferSet\"\n // );\n const newPosition = this._size;\n this._size++;\n this._pushToHeaps(newPosition, value);\n this._valueToPositionMap[value] = newPosition;\n return newPosition;\n }\n\n getMinValue() {\n return this._smallValues.peek()?.value;\n }\n\n getMaxValue() {\n return this._largeValues.peek()?.value;\n }\n\n setPositionValue(position: number, value: number) {\n const originalPosition = this._valueToPositionMap[value];\n if (originalPosition !== undefined) {\n const index = this._vacantPositions.findIndex(\n (v) => v === originalPosition\n );\n if (index === -1) this._vacantPositions.push(originalPosition);\n delete this._valueToPositionMap[value];\n this._valueToPositionMap[value] = position;\n }\n }\n\n replaceFurthestValuePosition(\n lowValue: number,\n highValue: number,\n newValue: number,\n useMinValueFn: (options: {\n safeRange: {\n lowValue: number;\n highValue: number;\n };\n bufferSetRange: {\n maxValue: number;\n minValue: number;\n };\n currentIndex: number;\n }) => boolean = defaultUseMinValueFn\n ): null | number {\n if (this._valueToPositionMap[newValue] !== undefined) {\n console.warn(\n \"Shouldn't try to replace values with value already stored value in \" +\n 'BufferSet'\n );\n }\n // invariant(\n // this._valueToPositionMap[newValue] === undefined,\n // \"Shouldn't try to replace values with value already stored value in \" +\n // 'BufferSet'\n // );\n\n this._cleanHeaps();\n if (this._smallValues.empty() || this._largeValues.empty()) {\n // Threre are currently no values stored. We will have to create new\n // position for this value.\n return null;\n }\n\n if (this._vacantPositions.length) {\n const position = this._vacantPositions.pop();\n this._valueToPositionMap[newValue] = position;\n this._pushToHeaps(position, newValue);\n return position;\n }\n\n const minValue = this._smallValues.peek()!.value;\n const maxValue = this._largeValues.peek()!.value;\n if (minValue >= lowValue && maxValue <= highValue) {\n // All values currently stored are necessary, we can't reuse any of them.\n return null;\n }\n\n let valueToReplace;\n if (\n useMinValueFn({\n safeRange: {\n lowValue,\n highValue,\n },\n bufferSetRange: {\n minValue,\n maxValue,\n },\n currentIndex: newValue,\n })\n ) {\n // if (lowValue - minValue > maxValue - highValue) {\n // minValue is further from provided range. We will reuse it's position.\n valueToReplace = minValue;\n this._smallValues.pop();\n } else {\n valueToReplace = maxValue;\n this._largeValues.pop();\n }\n const position = this._valueToPositionMap[valueToReplace];\n delete this._valueToPositionMap[valueToReplace];\n this._valueToPositionMap[newValue] = position;\n this._pushToHeaps(position, newValue);\n\n const _i = this._vacantPositions.findIndex((v) => v === position);\n if (_i !== -1) this._vacantPositions.splice(_i, 1);\n\n return position;\n }\n\n _pushToHeaps(position: number, value: number) {\n const element = {\n position,\n value,\n };\n // We can reuse the same object in both heaps, because we don't mutate them\n this._smallValues.push(element);\n this._largeValues.push(element);\n }\n\n _cleanHeaps() {\n // We not usually only remove object from one heap while moving value.\n // Here we make sure that there is no stale data on top of heaps.\n this._cleanHeap(this._smallValues);\n this._cleanHeap(this._largeValues);\n const minHeapSize = Math.min(\n this._smallValues.size(),\n this._largeValues.size()\n );\n const maxHeapSize = Math.max(\n this._smallValues.size(),\n this._largeValues.size()\n );\n if (maxHeapSize > 10 * minHeapSize) {\n // There are many old values in one of heaps. We need to get rid of them\n // to not use too avoid memory leaks\n this._recreateHeaps();\n }\n }\n\n _recreateHeaps() {\n const sourceHeap =\n this._smallValues.size() < this._largeValues.size()\n ? this._smallValues\n : this._largeValues;\n const newSmallValues = new Heap<HeapItem>(\n [], // Initial data in the heap\n this._smallerComparator\n );\n const newLargeValues = new Heap<HeapItem>(\n [], // Initial datat in the heap\n this._greaterComparator\n );\n while (!sourceHeap.empty()) {\n const element = sourceHeap.pop()!;\n // Push all stil valid elements to new heaps\n if (this._valueToPositionMap[element.value] !== undefined) {\n newSmallValues.push(element);\n newLargeValues.push(element);\n }\n }\n this._smallValues = newSmallValues;\n this._largeValues = newLargeValues;\n }\n\n _cleanHeap(heap: Heap<HeapItem>) {\n while (\n !heap.empty() &&\n this._valueToPositionMap[heap.peek()!.value] === undefined\n ) {\n heap.pop();\n }\n }\n\n _smallerComparator(lhs: HeapItem, rhs: HeapItem) {\n return lhs.value < rhs.value;\n }\n\n _greaterComparator(lhs: HeapItem, rhs: HeapItem) {\n return lhs.value > rhs.value;\n }\n}\n\nexport default IntegerBufferSet;\n"],"names":["defaultUseMinValueFn","options","safeRange","bufferSetRange","lowValue","highValue","maxValue","minValue","IntegerBufferSet","_valueToPositionMap","_size","_smallValues","Heap","_smallerComparator","_largeValues","_greaterComparator","getNewPositionForValue","bind","getValuePosition","getSize","replaceFurthestValuePosition","_vacantPositions","_proto","prototype","value","undefined","console","warn","newPosition","_pushToHeaps","getMinValue","_this$_smallValues$pe","peek","getMaxValue","_this$_largeValues$pe","setPositionValue","position","originalPosition","index","findIndex","v","push","newValue","useMinValueFn","_cleanHeaps","empty","length","pop","valueToReplace","currentIndex","_i","splice","element","_cleanHeap","minHeapSize","Math","min","size","maxHeapSize","max","_recreateHeaps","sourceHeap","newSmallValues","newLargeValues","heap","lhs","rhs","_createClass","key","get","indices"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAoBA,CAAIC,OAU7B;EACC,IAAQC,SAAS,GAAqBD,OAAO,CAArCC,SAAS;IAAEC,cAAc,GAAKF,OAAO,CAA1BE,cAAc;EACjC,IAAQC,QAAQ,GAAgBF,SAAS,CAAjCE,QAAQ;IAAEC,SAAS,GAAKH,SAAS,CAAvBG,SAAS;EAC3B,IAAQC,QAAQ,GAAeH,cAAc,CAArCG,QAAQ;IAAEC,QAAQ,GAAKJ,cAAc,CAA3BI,QAAQ;EAC1B,OAAOH,QAAQ,GAAGG,QAAQ,GAAGD,QAAQ,GAAGD,SAAS;AACnD,CAAC;AAAC,IAaIG,gBAAgB;EASpB,SAAAA;IACE,IAAI,CAACC,mBAAmB,GAAG,EAAE;IAC7B,IAAI,CAACC,KAAK,GAAG,CAAC;IACd,IAAI,CAACC,YAAY,GAAG,IAAIC,IAAI,CAAC,EAAE,EAAE,IAAI,CAACC,kBAAkB,CAAC;IACzD,IAAI,CAACC,YAAY,GAAG,IAAIF,IAAI,CAAC,EAAE,EAAE,IAAI,CAACG,kBAAkB,CAAC;IAEzD,IAAI,CAACC,sBAAsB,GAAG,IAAI,CAACA,sBAAsB,CAACC,IAAI,CAAC,IAAI,CAAC;IACpE,IAAI,CAACC,gBAAgB,GAAG,IAAI,CAACA,gBAAgB,CAACD,IAAI,CAAC,IAAI,CAAC;IACxD,IAAI,CAACE,OAAO,GAAG,IAAI,CAACA,OAAO,CAACF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B,IAAI,CAACW,OAAO,CAAC;;;IAGhC,IAAI,CAACzC,YAAY,GAAGmD,cAAc;IAClC,IAAI,CAAChD,YAAY,GAAGiD,cAAc;GACnC;EAAAzC,MAAA,CAED+B,UAAU,GAAV,SAAAA,WAAWW,IAAoB;IAC7B,OACE,CAACA,IAAI,CAACnB,KAAK,EAAE,IACb,IAAI,CAACpC,mBAAmB,CAACuD,IAAI,CAAChC,IAAI,EAAG,CAACR,KAAK,CAAC,KAAKC,SAAS,EAC1D;MACAuC,IAAI,CAACjB,GAAG,EAAE;;GAEb;EAAAzB,MAAA,CAEDT,kBAAkB,GAAlB,SAAAA,mBAAmBoD,GAAa,EAAEC,GAAa;IAC7C,OAAOD,GAAG,CAACzC,KAAK,GAAG0C,GAAG,CAAC1C,KAAK;GAC7B;EAAAF,MAAA,CAEDP,kBAAkB,GAAlB,SAAAA,mBAAmBkD,GAAa,EAAEC,GAAa;IAC7C,OAAOD,GAAG,CAACzC,KAAK,GAAG0C,GAAG,CAAC1C,KAAK;GAC7B;EAAA2C,YAAA,CAAA3D,gBAAA;IAAA4D,GAAA;IAAAC,GAAA,EA7MD,SAAAA;MACE,IAAMC,OAAO,GAAG,EAAE;MAClB,KAAK,IAAMF,GAAG,IAAI,IAAI,CAAC3D,mBAAmB,EAAE;QAC1C,IAAMe,KAAK,GAAG,IAAI,CAACf,mBAAmB,CAAC2D,GAAG,CAAC;QAC3CE,OAAO,CAAC9C,KAAK,CAAC,GAAG4C,GAAG;;MAEtB,OAAOE,OAAO;;;EACf,OAAA9D,gBAAA;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"integer-buffer-set.esm.js","sources":["../src/index.ts"],"sourcesContent":["import Heap from '@x-oasis/heap';\nimport isClamped from '@x-oasis/is-clamped';\nimport invariant from '@x-oasis/invariant';\nimport returnHook, { ReturnHook } from '@x-oasis/return-hook';\nimport {\n HeapItem,\n SafeRange,\n MetaExtractor,\n IndexExtractor,\n IntegerBufferSetProps,\n MetaToIndexMap,\n MetaToPositionMap,\n IndexToMetaMap,\n} from './types';\n\nconst defaultMetaExtractor = (value) => value;\nexport const defaultBufferSize = 10;\n\n// !!!!! should do meta validation...meta should has an index...\n// value: original data `index` value\n// value(index) => meta => position\n// `index to getIndices, meta to find index`\n\n// Data structure that allows to store values and assign positions to them\n// in a way to minimize changing positions of stored values when new ones are\n// added or when some values are replaced. Stored elements are alwasy assigned\n// a consecutive set of positoins startin from 0 up to count of elements less 1\n// Following actions can be executed\n// * get position assigned to given value (null if value is not stored)\n// * create new entry for new value and get assigned position back\n// * replace value that is furthest from specified value range with new value\n// and get it's position back\n// All operations take amortized log(n) time where n is number of elements in\n// the set.\n// feature: add / delete / update item will also in consider..\nclass IntegerBufferSet<Meta = any> {\n private _name: string;\n private _bufferSize: number;\n\n private _indexToMetaMap: IndexToMetaMap<Meta>;\n private _metaToPositionMap: MetaToPositionMap<Meta>;\n private _positionToMetaList: Array<Meta>;\n private _metaToIndexMap: MetaToIndexMap<Meta>;\n\n private _smallValues: Heap<HeapItem>;\n private _largeValues: Heap<HeapItem>;\n private _metaExtractor: MetaExtractor<Meta>;\n private _indexExtractor: IndexExtractor<Meta>;\n\n private _onTheFlyIndices: Array<Meta>;\n\n private _isOnTheFlyFull: boolean;\n private _isOnTheFlyFullReturnHook: ReturnHook;\n\n private _loopMS: number;\n private _lastUpdatedMS: number;\n\n constructor(props: IntegerBufferSetProps<Meta> = {}) {\n const {\n name = 'default_buffer',\n indexExtractor,\n bufferSize = defaultBufferSize,\n metaExtractor = defaultMetaExtractor,\n } = props;\n this._metaExtractor = metaExtractor;\n this._indexExtractor = indexExtractor;\n\n this._name = name;\n\n /**\n * this._indexToMetaMap is used to find the prev meta when finding a position for index.\n */\n this._indexToMetaMap = new Map();\n this._metaToPositionMap = new Map();\n this._positionToMetaList = [];\n this._metaToIndexMap = new Map();\n this._onTheFlyIndices = [];\n\n this._bufferSize = bufferSize;\n\n this._smallValues = new Heap([], this._smallerComparator);\n this._largeValues = new Heap([], this._greaterComparator);\n\n this.getNewPositionForIndex = this.getNewPositionForIndex.bind(this);\n this.getIndexPosition = this.getIndexPosition.bind(this);\n this.replacePositionInFliedIndices =\n this.replacePositionInFliedIndices.bind(this);\n this.replaceFurthestIndexPosition =\n this.replaceFurthestIndexPosition.bind(this);\n this._isOnTheFlyFullReturnHook = returnHook(\n this.setIsOnTheFlyFull.bind(this)\n );\n\n this._loopMS = Date.now();\n this._lastUpdatedMS = this._loopMS;\n }\n\n get bufferSize() {\n return this._bufferSize;\n }\n\n setIsOnTheFlyFull(val: any) {\n if (val != null) {\n const data = this._onTheFlyIndices.filter((v) => v);\n this._isOnTheFlyFull = data.length === this._bufferSize;\n }\n }\n\n get isBufferFull() {\n return this._positionToMetaList.length >= this._bufferSize;\n }\n\n getOnTheFlyUncriticalPosition(safeRange: SafeRange) {\n const { startIndex, endIndex } = safeRange;\n for (let idx = 0; idx < this._onTheFlyIndices.length; idx++) {\n const meta = this._onTheFlyIndices[idx];\n const metaIndex = this._metaToIndexMap.get(meta);\n if (!isClamped(startIndex, metaIndex, endIndex)) {\n return idx;\n }\n }\n return null;\n }\n\n initialize() {\n return {\n smallValues: new Heap([], this._smallerComparator),\n largeValues: new Heap([], this._greaterComparator),\n valueToPositionObject: {},\n };\n }\n\n getIndexMeta(index: number) {\n return this._metaExtractor(index);\n }\n\n getMetaIndex(meta: Meta) {\n if (this._indexExtractor) return this._indexExtractor(meta);\n return this._metaToIndexMap.get(meta);\n }\n\n setMetaIndex(meta: Meta, index: number) {\n if (!this._indexExtractor) {\n return this._metaToIndexMap.set(meta, index);\n }\n return false;\n }\n\n deleteMetaIndex(meta: Meta) {\n return this._metaToIndexMap.delete(meta);\n }\n\n replaceMetaToIndexMap(newMetaToIndexMap: MetaToIndexMap<Meta>) {\n if (!this._indexExtractor) {\n return (this._metaToIndexMap = newMetaToIndexMap);\n }\n return false;\n }\n\n getIndexPosition(index: number): undefined | number {\n return this.getMetaIndex(this.getIndexMeta(index));\n }\n\n getNewPositionForIndex(index: number) {\n const meta = this.getIndexMeta(index);\n invariant(\n this._metaToPositionMap.get(meta) === undefined,\n \"Shouldn't try to find new position for value already stored in BufferSet\"\n );\n const newPosition = this._positionToMetaList.length;\n\n this._pushToHeaps(newPosition, index);\n this._setMetaIndex(meta, index);\n this._setMetaPosition(meta, newPosition);\n\n return newPosition;\n }\n\n getMinValue() {\n return this._smallValues.peek()?.value;\n }\n\n getMaxValue() {\n return this._largeValues.peek()?.value;\n }\n\n replacePositionInFliedIndices(newIndex: number, safeRange: SafeRange) {\n const { startIndex, endIndex } = safeRange;\n\n if (this._isOnTheFlyFull) {\n // newIndex is not critical index, do nothing\n if (!isClamped(startIndex, newIndex, endIndex)) {\n return null;\n }\n // if `newIndex` is critical index, replace an un-committed\n // index value from _onTheFlyIndices.\n const pos = this.getOnTheFlyUncriticalPosition(safeRange);\n if (pos != null) return pos;\n }\n return null;\n }\n\n getFliedPosition(newIndex: number, safeRange: SafeRange) {\n const pos = this.replacePositionInFliedIndices(newIndex, safeRange);\n if (pos != null) {\n const meta = this.getIndexMeta(newIndex);\n this._onTheFlyIndices[pos] = meta;\n this._setMetaIndex(meta, newIndex);\n return this._isOnTheFlyFullReturnHook(pos);\n }\n return null;\n }\n\n /**\n *\n * @param newIndex\n * @param safeRange\n * @returns\n *\n *\n * _positionToMetaList maybe undefined on next loop\n */\n getPosition(newIndex: number, safeRange?: SafeRange) {\n this.prepare();\n const meta = this.getIndexMeta(newIndex);\n const prevMetaPosition = this._metaToPositionMap.get(meta);\n\n if (prevMetaPosition !== undefined) {\n const onTheFlyPositionMeta = this._onTheFlyIndices[prevMetaPosition];\n // the occupied meta should change position\n if (onTheFlyPositionMeta) {\n // such as place item 11 twice...\n if (onTheFlyPositionMeta === meta) {\n return prevMetaPosition;\n }\n let positionToReplace = this._replaceFurthestIndexPosition(\n newIndex,\n safeRange\n );\n if (this._isOnTheFlyFull)\n return this.getFliedPosition(newIndex, safeRange);\n\n while (this._onTheFlyIndices[positionToReplace]) {\n positionToReplace = this._replaceFurthestIndexPosition(\n newIndex,\n safeRange\n );\n }\n\n if (positionToReplace != null) {\n this._setMetaIndex(meta, newIndex);\n this._onTheFlyIndices[positionToReplace] = onTheFlyPositionMeta;\n return this._isOnTheFlyFullReturnHook(positionToReplace);\n }\n }\n this._onTheFlyIndices[prevMetaPosition] = meta;\n return this._isOnTheFlyFullReturnHook(prevMetaPosition);\n }\n\n // placed on new buffered position\n if (!this.isBufferFull)\n return this._isOnTheFlyFullReturnHook(\n this.getNewPositionForIndex(newIndex)\n );\n\n if (this._isOnTheFlyFull) return this.getFliedPosition(newIndex, safeRange);\n\n let positionToReplace;\n const prevIndexMeta = this._indexToMetaMap.get(newIndex);\n\n // Index has already been stored, but we cant use its old position directly...\n // 1:index -> meta, meta may be reused later\n\n // 2: temp use index -> meta -> position, this issue should exist for follows...\n if (!prevIndexMeta) {\n this._cleanHeaps();\n positionToReplace = this._replaceFurthestIndexPosition(\n newIndex,\n safeRange\n );\n } else {\n positionToReplace = this._metaToPositionMap.get(prevIndexMeta);\n }\n\n this._onTheFlyIndices[positionToReplace] = meta;\n this._setMetaIndex(meta, newIndex);\n this._setMetaPosition(meta, positionToReplace);\n // should not push to heap, pop only\n // this._pushToHeaps(positionToReplace, newIndex)\n\n return this._isOnTheFlyFullReturnHook(positionToReplace);\n }\n\n replaceFurthestIndexPosition(\n newIndex: number,\n safeRange?: {\n startIndex: number;\n endIndex: number;\n }\n ) {\n if (!this.isBufferFull) {\n return this._isOnTheFlyFullReturnHook(\n this.getNewPositionForIndex(newIndex)\n );\n }\n\n return this._replaceFurthestIndexPosition(newIndex, safeRange);\n }\n\n _replaceFurthestIndexPosition(\n newIndex: number,\n safeRange?: {\n startIndex: number;\n endIndex: number;\n }\n ) {\n if (this._largeValues.empty() || this._smallValues.empty()) {\n return this._isOnTheFlyFullReturnHook(\n this.getNewPositionForIndex(newIndex)\n );\n }\n\n const minValue = this._smallValues.peek()!.value;\n const maxValue = this._largeValues.peek()!.value;\n\n let indexToReplace;\n\n if (!safeRange) {\n // far from min\n if (Math.abs(newIndex - minValue) > Math.abs(newIndex - maxValue)) {\n indexToReplace = minValue;\n this._smallValues.pop();\n } else {\n indexToReplace = maxValue;\n this._largeValues.pop();\n }\n const replacedMeta = this._indexToMetaMap.get(indexToReplace);\n const position = this._metaToPositionMap.get(replacedMeta);\n\n return position;\n }\n\n const { startIndex: lowValue, endIndex: highValue } = safeRange;\n\n // All values currently stored are necessary, we can't reuse any of them.\n if (\n isClamped(lowValue, minValue, highValue) &&\n isClamped(lowValue, maxValue, highValue)\n ) {\n return null;\n } else if (\n isClamped(lowValue, minValue, highValue) &&\n !isClamped(lowValue, maxValue, highValue)\n ) {\n indexToReplace = maxValue;\n this._largeValues.pop();\n } else if (\n !isClamped(lowValue, minValue, highValue) &&\n isClamped(lowValue, maxValue, highValue)\n ) {\n indexToReplace = minValue;\n this._smallValues.pop();\n } else if (lowValue - minValue > maxValue - highValue) {\n // minValue is further from provided range. We will reuse it's position.\n indexToReplace = minValue;\n this._smallValues.pop();\n } else {\n indexToReplace = maxValue;\n this._largeValues.pop();\n }\n\n const replacedMeta = this._indexToMetaMap.get(indexToReplace);\n const position = this._metaToPositionMap.get(replacedMeta);\n\n return position;\n }\n\n shuffle() {\n const indices = new Array(this.bufferSize);\n for (let idx = 0; idx < indices.length; idx++) {\n const meta = this._onTheFlyIndices[idx] || this._positionToMetaList[idx];\n const targetIndex = this.getMetaIndex(meta);\n indices[idx] = targetIndex;\n }\n\n const _arr = new Array(indices.length);\n const _available = [];\n const indexToMetaMap = new Map();\n const metaToIndexMap = new Map();\n const metaToPositionMap = new Map();\n for (let idx = 0; idx < indices.length; idx++) {\n const currentIndex = indices[idx];\n const currentMeta = this._metaExtractor(currentIndex);\n if (currentMeta == null) continue;\n\n indexToMetaMap.set(currentIndex, currentMeta);\n metaToIndexMap.set(currentMeta, currentIndex);\n\n if (currentMeta === this._positionToMetaList[idx]) {\n _arr[idx] = currentMeta;\n continue;\n }\n const _i = this._positionToMetaList.findIndex((v) => v === currentMeta);\n if (_i !== -1) {\n _arr[_i] = currentMeta;\n continue;\n }\n\n _available.push(currentMeta);\n }\n\n const { smallValues, largeValues } = this.initialize();\n const positionToMetaList = [];\n\n for (let position = 0; position < indices.length; position++) {\n const value = indices[position];\n if (_arr[position] != null) {\n positionToMetaList[position] = _arr[position];\n metaToPositionMap.set(_arr[position], position);\n const element = { position, value };\n smallValues.push(element);\n largeValues.push(element);\n continue;\n }\n const meta = _available.shift();\n if (meta != null) {\n positionToMetaList[position] = meta;\n metaToPositionMap.set(meta, position);\n\n const element = { position, value };\n smallValues.push(element);\n largeValues.push(element);\n }\n }\n\n this._positionToMetaList = positionToMetaList;\n this._smallValues = smallValues;\n this._largeValues = largeValues;\n this._indexToMetaMap = indexToMetaMap;\n this.replaceMetaToIndexMap(metaToIndexMap);\n this._metaToPositionMap = metaToPositionMap;\n this._onTheFlyIndices = [];\n\n try {\n const indices = new Array(this.bufferSize);\n for (let idx = 0; idx < indices.length; idx++) {\n const meta =\n this._onTheFlyIndices[idx] || this._positionToMetaList[idx];\n const targetIndex = this.getMetaIndex(meta);\n if (meta != null) {\n indices[idx] = {\n meta,\n targetIndex,\n recyclerKey: `${this._name}_${idx}`,\n };\n }\n }\n return indices;\n } catch (err) {\n this.readyToStartNextLoop();\n return this._positionToMetaList;\n }\n }\n\n // key point: `meta` should be preserved..\n getIndices() {\n try {\n const indices = new Array(this.bufferSize);\n for (let idx = 0; idx < indices.length; idx++) {\n const meta =\n this._onTheFlyIndices[idx] || this._positionToMetaList[idx];\n const targetIndex = this.getMetaIndex(meta);\n // which means source data has changed. such as one element has been deleted\n if (meta !== this.getIndexMeta(targetIndex)) {\n return this.shuffle();\n }\n if (meta != null) {\n indices[idx] = {\n meta,\n targetIndex,\n recyclerKey: `${this._name}_${idx}`,\n };\n }\n }\n // clear on the fly indices after return indices.\n this._onTheFlyIndices = [];\n\n return indices;\n } catch (err) {\n this.readyToStartNextLoop();\n return this._positionToMetaList;\n }\n }\n\n _pushToHeaps(position: number, value: number) {\n const element = { position, value };\n // We can reuse the same object in both heaps, because we don't mutate them\n this._smallValues.push(element);\n this._largeValues.push(element);\n }\n\n _setMetaPosition(meta: Meta, position: number) {\n const prevMetaOnPosition = this._positionToMetaList[position];\n if (prevMetaOnPosition) this._metaToPositionMap.delete(prevMetaOnPosition);\n this._positionToMetaList[position] = meta;\n this._metaToPositionMap.set(meta, position);\n }\n\n /**\n *\n * @param meta\n * @param index\n * @returns true means index not changed\n */\n _setMetaIndex(meta: Meta, index: number) {\n const prevMetaIndex = this.getMetaIndex(meta);\n if (prevMetaIndex !== undefined) {\n // no need to set\n // if (prevMetaIndex === index) return true;\n this._indexToMetaMap.delete(prevMetaIndex);\n }\n this.setMetaIndex(meta, index);\n this._indexToMetaMap.set(index, meta);\n return false;\n }\n\n readyToStartNextLoop() {\n this._lastUpdatedMS = Date.now();\n }\n\n prepare() {\n if (this._loopMS === this._lastUpdatedMS) return;\n this._loopMS = this._lastUpdatedMS;\n\n this._onTheFlyIndices = [];\n this._isOnTheFlyFull = false;\n }\n\n _cleanHeaps() {\n // We not usually only remove object from one heap while moving value.\n // Here we make sure that there is no stale data on top of heaps.\n this._cleanHeap(this._smallValues);\n this._cleanHeap(this._largeValues);\n const minHeapSize = Math.min(\n this._smallValues.size(),\n this._largeValues.size()\n );\n const maxHeapSize = Math.max(\n this._smallValues.size(),\n this._largeValues.size()\n );\n if (maxHeapSize > 10 * minHeapSize) {\n // There are many old values in one of heaps. We need to get rid of them\n // to not use too avoid memory leaks\n this._recreateHeaps();\n }\n }\n _recreateHeaps() {\n const sourceHeap =\n this._smallValues.size() < this._largeValues.size()\n ? this._smallValues\n : this._largeValues;\n const newSmallValues = new Heap<HeapItem>(\n [], // Initial data in the heap\n this._smallerComparator\n );\n const newLargeValues = new Heap<HeapItem>(\n [], // Initial datat in the heap\n this._greaterComparator\n );\n while (!sourceHeap.empty()) {\n const element = sourceHeap.pop()!;\n // Push all still valid elements to new heaps\n if (\n this._metaToPositionMap.get(this._indexToMetaMap.get(element.value)) !=\n null\n ) {\n newSmallValues.push(element);\n newLargeValues.push(element);\n }\n }\n this._smallValues = newSmallValues;\n this._largeValues = newLargeValues;\n }\n\n _cleanHeap(heap: Heap<HeapItem>) {\n while (\n !heap.empty() &&\n this._metaToPositionMap.get(\n this._indexToMetaMap.get(heap.peek()!.value)\n ) == null\n ) {\n heap.pop();\n }\n }\n\n _smallerComparator(lhs: HeapItem, rhs: HeapItem) {\n return lhs.value < rhs.value;\n }\n\n _greaterComparator(lhs: HeapItem, rhs: HeapItem) {\n return lhs.value > rhs.value;\n }\n}\n\nexport default IntegerBufferSet;\n"],"names":["defaultMetaExtractor","value","defaultBufferSize","IntegerBufferSet","props","_props","_props$name","name","indexExtractor","_props$bufferSize","bufferSize","_props$metaExtractor","metaExtractor","_metaExtractor","_indexExtractor","_name","_indexToMetaMap","Map","_metaToPositionMap","_positionToMetaList","_metaToIndexMap","_onTheFlyIndices","_bufferSize","_smallValues","Heap","_smallerComparator","_largeValues","_greaterComparator","getNewPositionForIndex","bind","getIndexPosition","replacePositionInFliedIndices","replaceFurthestIndexPosition","_isOnTheFlyFullReturnHook","returnHook","setIsOnTheFlyFull","_loopMS","Date","now","_lastUpdatedMS","_proto","prototype","val","data","filter","v","_isOnTheFlyFull","length","getOnTheFlyUncriticalPosition","safeRange","startIndex","endIndex","idx","meta","metaIndex","get","isClamped","initialize","smallValues","largeValues","valueToPositionObject","getIndexMeta","index","getMetaIndex","setMetaIndex","set","deleteMetaIndex","replaceMetaToIndexMap","newMetaToIndexMap","undefined","process","env","NODE_ENV","invariant","newPosition","_pushToHeaps","_setMetaIndex","_setMetaPosition","getMinValue","_this$_smallValues$pe","peek","getMaxValue","_this$_largeValues$pe","newIndex","pos","getFliedPosition","getPosition","prepare","prevMetaPosition","onTheFlyPositionMeta","positionToReplace","_replaceFurthestIndexPosition","isBufferFull","prevIndexMeta","_cleanHeaps","empty","minValue","maxValue","indexToReplace","Math","abs","pop","replacedMeta","position","lowValue","highValue","shuffle","indices","Array","targetIndex","_arr","_available","indexToMetaMap","metaToIndexMap","metaToPositionMap","_loop","currentIndex","currentMeta","_this","_i","findIndex","push","_ret","_this$initialize","positionToMetaList","element","shift","recyclerKey","err","readyToStartNextLoop","getIndices","prevMetaOnPosition","prevMetaIndex","_cleanHeap","minHeapSize","min","size","maxHeapSize","max","_recreateHeaps","sourceHeap","newSmallValues","newLargeValues","heap","lhs","rhs","_createClass","key"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAoBA,CAAIC,KAAK;EAAA,OAAKA,KAAK;AAAA;IAChCC,iBAAiB,GAAG;AAAG,IAmB9BC,gBAAgB;EAsBpB,SAAAA,iBAAYC;QAAAA;MAAAA,QAAqC,EAAE;;IACjD,IAAAC,MAAA,GAKID,KAAK;MAAAE,WAAA,GAAAD,MAAA,CAJPE,IAAI;MAAJA,IAAI,GAAAD,WAAA,cAAG,gBAAgB,GAAAA,WAAA;MACvBE,cAAc,GAAAH,MAAA,CAAdG,cAAc;MAAAC,iBAAA,GAAAJ,MAAA,CACdK,UAAU;MAAVA,UAAU,GAAAD,iBAAA,cAAGP,iBAAiB,GAAAO,iBAAA;MAAAE,oBAAA,GAAAN,MAAA,CAC9BO,aAAa;MAAbA,aAAa,GAAAD,oBAAA,cAAGX,oBAAoB,GAAAW,oBAAA;IAEtC,IAAI,CAACE,cAAc,GAAGD,aAAa;IACnC,IAAI,CAACE,eAAe,GAAGN,cAAc;IAErC,IAAI,CAACO,KAAK,GAAGR,IAAI;IAKjB,IAAI,CAACS,eAAe,GAAG,IAAIC,GAAG,EAAE;IAChC,IAAI,CAACC,kBAAkB,GAAG,IAAID,GAAG,EAAE;IACnC,IAAI,CAACE,mBAAmB,GAAG,EAAE;IAC7B,IAAI,CAACC,eAAe,GAAG,IAAIH,GAAG,EAAE;IAChC,IAAI,CAACI,g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AO,CAAC;QAC5BiB,cAAc,CAACrB,IAAI,CAACI,OAAO,CAAC;;;IAGhC,IAAI,CAACtG,YAAY,GAAGsH,cAAc;IAClC,IAAI,CAACnH,YAAY,GAAGoH,cAAc;GACnC;EAAAtG,MAAA,CAED6F,UAAU,GAAV,SAAAA,WAAWU,IAAoB;IAC7B,OACE,CAACA,IAAI,CAAChD,KAAK,EAAE,IACb,IAAI,CAAC7E,kBAAkB,CAACqC,GAAG,CACzB,IAAI,CAACvC,eAAe,CAACuC,GAAG,CAACwF,IAAI,CAAC/D,IAAI,EAAG,CAAC/E,KAAK,CAAC,CAC7C,IAAI,IAAI,EACT;MACA8I,IAAI,CAAC1C,GAAG,EAAE;;GAEb;EAAA7D,MAAA,CAEDf,kBAAkB,GAAlB,SAAAA,mBAAmBuH,GAAa,EAAEC,GAAa;IAC7C,OAAOD,GAAG,CAAC/I,KAAK,GAAGgJ,GAAG,CAAChJ,KAAK;GAC7B;EAAAuC,MAAA,CAEDb,kBAAkB,GAAlB,SAAAA,mBAAmBqH,GAAa,EAAEC,GAAa;IAC7C,OAAOD,GAAG,CAAC/I,KAAK,GAAGgJ,GAAG,CAAChJ,KAAK;GAC7B;EAAAiJ,YAAA,CAAA/I,gBAAA;IAAAgJ,GAAA;IAAA5F,GAAA,EAzfD,SAAAA;MACE,OAAO,IAAI,CAACjC,WAAW;;;IACxB6H,GAAA;IAAA5F,GAAA,EASD,SAAAA;MACE,OAAO,IAAI,CAACpC,mBAAmB,CAAC4B,MAAM,IAAI,IAAI,CAACzB,WAAW;;;EAC3D,OAAAnB,gBAAA;AAAA;;;;;"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare type MetaToIndexMap<T> = Map<T, number>;
|
|
2
|
+
export declare type MetaToPositionMap<T> = Map<T, number>;
|
|
3
|
+
export declare type IndexToMetaMap<T> = Map<number, T>;
|
|
4
|
+
export declare type MetaExtractor<T> = (index: number) => T;
|
|
5
|
+
export declare type IndexExtractor<T> = (meta: T) => number;
|
|
6
|
+
export declare type IntegerBufferSetProps<T> = {
|
|
7
|
+
name?: string;
|
|
8
|
+
bufferSize?: number;
|
|
9
|
+
metaExtractor?: MetaExtractor<T>;
|
|
10
|
+
indexExtractor?: IndexExtractor<T>;
|
|
11
|
+
};
|
|
12
|
+
export declare type HeapItem = {
|
|
13
|
+
position: number;
|
|
14
|
+
value: number;
|
|
15
|
+
};
|
|
16
|
+
export declare type SafeRange = {
|
|
17
|
+
startIndex: number;
|
|
18
|
+
endIndex: number;
|
|
19
|
+
};
|
|
20
|
+
export declare type BufferResultToken = {
|
|
21
|
+
meta: any;
|
|
22
|
+
targetIndex: number;
|
|
23
|
+
recyclerKey: string;
|
|
24
|
+
};
|