@x-oasis/recycler 0.1.30 → 0.1.31
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 +5 -4
- package/dist/recycler.cjs.development.js +10 -53
- package/dist/recycler.cjs.development.js.map +1 -1
- package/dist/recycler.cjs.production.min.js +1 -1
- package/dist/recycler.cjs.production.min.js.map +1 -1
- package/dist/recycler.esm.js +10 -53
- package/dist/recycler.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +10 -10
- package/dist/FixedBuffer.d.ts +0 -14
- package/src/FixedBuffer.ts +0 -54
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import IntegerBufferSet from '@x-oasis/integer-buffer-set';
|
|
2
2
|
import { OnProcess, RecyclerProps } from './types';
|
|
3
3
|
declare class Recycler {
|
|
4
4
|
private _queue;
|
|
@@ -9,12 +9,13 @@ declare class Recycler {
|
|
|
9
9
|
private _indexExtractor;
|
|
10
10
|
private _getType;
|
|
11
11
|
constructor(props?: RecyclerProps);
|
|
12
|
-
get queue():
|
|
12
|
+
get queue(): IntegerBufferSet<any>[];
|
|
13
13
|
get thresholdIndexValue(): number;
|
|
14
14
|
get recyclerReservedBufferPerBatch(): number;
|
|
15
15
|
getIndices(): any[];
|
|
16
|
-
addBuffer(type: string):
|
|
17
|
-
ensureBuffer(type: string):
|
|
16
|
+
addBuffer(type: string): IntegerBufferSet<any>;
|
|
17
|
+
ensureBuffer(type: string): IntegerBufferSet<any>;
|
|
18
|
+
reset(): void;
|
|
18
19
|
updateIndices(props: {
|
|
19
20
|
safeRange: {
|
|
20
21
|
startIndex: number;
|
|
@@ -43,53 +43,6 @@ var RECYCLER_THRESHOLD_INDEX_VALUE = 0;
|
|
|
43
43
|
var RECYCLER_RESERVED_BUFFER_PER_BATCH = 4;
|
|
44
44
|
var RECYCLER_BUFFER_SIZE = 10;
|
|
45
45
|
|
|
46
|
-
var FixedBuffer = /*#__PURE__*/function () {
|
|
47
|
-
function FixedBuffer(props) {
|
|
48
|
-
this._thresholdIndexValue = 0;
|
|
49
|
-
var _props$thresholdIndex = props.thresholdIndexValue,
|
|
50
|
-
thresholdIndexValue = _props$thresholdIndex === void 0 ? 0 : _props$thresholdIndex,
|
|
51
|
-
_props$bufferSize = props.bufferSize,
|
|
52
|
-
bufferSize = _props$bufferSize === void 0 ? RECYCLER_BUFFER_SIZE : _props$bufferSize,
|
|
53
|
-
_props$recyclerType = props.recyclerType,
|
|
54
|
-
recyclerType = _props$recyclerType === void 0 ? DEFAULT_RECYCLER_TYPE : _props$recyclerType,
|
|
55
|
-
metaExtractor = props.metaExtractor,
|
|
56
|
-
indexExtractor = props.indexExtractor;
|
|
57
|
-
this._bufferSet = new IntegerBufferSet({
|
|
58
|
-
bufferSize: bufferSize,
|
|
59
|
-
metaExtractor: metaExtractor,
|
|
60
|
-
indexExtractor: indexExtractor,
|
|
61
|
-
name: recyclerType
|
|
62
|
-
});
|
|
63
|
-
this._recyclerType = recyclerType;
|
|
64
|
-
this._thresholdIndexValue = thresholdIndexValue;
|
|
65
|
-
}
|
|
66
|
-
var _proto = FixedBuffer.prototype;
|
|
67
|
-
_proto.place = function place(index, safeRange) {
|
|
68
|
-
this._bufferSet.getPosition(index, safeRange);
|
|
69
|
-
};
|
|
70
|
-
_proto.getMaxValue = function getMaxValue() {
|
|
71
|
-
return this._bufferSet.getMaxValue();
|
|
72
|
-
};
|
|
73
|
-
_proto.getMinValue = function getMinValue() {
|
|
74
|
-
return this._bufferSet.getMinValue();
|
|
75
|
-
};
|
|
76
|
-
_proto.getIndices = function getIndices() {
|
|
77
|
-
return this._bufferSet.getIndices();
|
|
78
|
-
};
|
|
79
|
-
_createClass(FixedBuffer, [{
|
|
80
|
-
key: "thresholdIndexValue",
|
|
81
|
-
get: function get() {
|
|
82
|
-
return this._thresholdIndexValue;
|
|
83
|
-
}
|
|
84
|
-
}, {
|
|
85
|
-
key: "recyclerType",
|
|
86
|
-
get: function get() {
|
|
87
|
-
return this._recyclerType;
|
|
88
|
-
}
|
|
89
|
-
}]);
|
|
90
|
-
return FixedBuffer;
|
|
91
|
-
}();
|
|
92
|
-
|
|
93
46
|
var Recycler = /*#__PURE__*/function () {
|
|
94
47
|
function Recycler(props) {
|
|
95
48
|
var _this = this;
|
|
@@ -126,15 +79,14 @@ var Recycler = /*#__PURE__*/function () {
|
|
|
126
79
|
_proto.addBuffer = function addBuffer(type) {
|
|
127
80
|
if (!type) return null;
|
|
128
81
|
var index = this._queue.findIndex(function (buffer) {
|
|
129
|
-
return buffer.
|
|
82
|
+
return buffer.getType() === type;
|
|
130
83
|
});
|
|
131
84
|
if (index !== -1) return this._queue[index];
|
|
132
|
-
var buffer = new
|
|
133
|
-
|
|
85
|
+
var buffer = new IntegerBufferSet({
|
|
86
|
+
type: type,
|
|
134
87
|
metaExtractor: this._metaExtractor,
|
|
135
88
|
indexExtractor: this._indexExtractor,
|
|
136
|
-
bufferSize: this._recyclerBufferSize
|
|
137
|
-
thresholdIndexValue: this._thresholdIndexValue
|
|
89
|
+
bufferSize: this._recyclerBufferSize
|
|
138
90
|
});
|
|
139
91
|
this._queue.push(buffer);
|
|
140
92
|
return buffer;
|
|
@@ -142,6 +94,11 @@ var Recycler = /*#__PURE__*/function () {
|
|
|
142
94
|
_proto.ensureBuffer = function ensureBuffer(type) {
|
|
143
95
|
return this.addBuffer(type || DEFAULT_RECYCLER_TYPE);
|
|
144
96
|
};
|
|
97
|
+
_proto.reset = function reset() {
|
|
98
|
+
this.queue.forEach(function (buffer) {
|
|
99
|
+
return buffer.reset();
|
|
100
|
+
});
|
|
101
|
+
};
|
|
145
102
|
_proto.updateIndices = function updateIndices(props) {
|
|
146
103
|
var startIndex = props.startIndex,
|
|
147
104
|
safeRange = props.safeRange,
|
|
@@ -155,7 +112,7 @@ var Recycler = /*#__PURE__*/function () {
|
|
|
155
112
|
if (_index >= this._thresholdIndexValue) {
|
|
156
113
|
var recyclerType = this._getType(_index);
|
|
157
114
|
var buffer = this.ensureBuffer(recyclerType);
|
|
158
|
-
buffer.
|
|
115
|
+
buffer.getPosition(_index, safeRange);
|
|
159
116
|
if (typeof onProcess !== 'function' || onProcess(recyclerType, _index)) {
|
|
160
117
|
count += 1;
|
|
161
118
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recycler.cjs.development.js","sources":["../src/common.ts","../src/FixedBuffer.ts","../src/index.ts"],"sourcesContent":["export const DEFAULT_RECYCLER_TYPE = '__default_recycler_buffer__';\nexport const RECYCLER_THRESHOLD_INDEX_VALUE = 0;\nexport const RECYCLER_RESERVED_BUFFER_PER_BATCH = 4;\nexport const RECYCLER_BUFFER_SIZE = 10;\n// export const RECYCLER_RESERVED_BUFFER_SIZE_RATIO = 1.5;\n\nexport const defaultGetType = () => DEFAULT_RECYCLER_TYPE;\n","import IntegerBufferSet from '@x-oasis/integer-buffer-set';\nimport { SafeRange, FixedBufferProps } from './types';\nimport { DEFAULT_RECYCLER_TYPE, RECYCLER_BUFFER_SIZE } from './common';\n\nclass FixedBuffer {\n private _bufferSet: IntegerBufferSet;\n private _thresholdIndexValue = 0;\n\n private _recyclerType: string;\n\n constructor(props: FixedBufferProps) {\n const {\n thresholdIndexValue = 0,\n bufferSize = RECYCLER_BUFFER_SIZE,\n recyclerType = DEFAULT_RECYCLER_TYPE,\n metaExtractor,\n indexExtractor,\n } = props;\n this._bufferSet = new IntegerBufferSet({\n bufferSize,\n metaExtractor,\n indexExtractor,\n name: recyclerType,\n });\n this._recyclerType = recyclerType;\n this._thresholdIndexValue = thresholdIndexValue;\n }\n\n get thresholdIndexValue() {\n return this._thresholdIndexValue;\n }\n\n get recyclerType() {\n return this._recyclerType;\n }\n\n place(index: number, safeRange: SafeRange) {\n this._bufferSet.getPosition(index, safeRange);\n }\n\n getMaxValue() {\n return this._bufferSet.getMaxValue();\n }\n\n getMinValue() {\n return this._bufferSet.getMinValue();\n }\n\n getIndices() {\n return this._bufferSet.getIndices();\n }\n}\n\nexport default FixedBuffer;\n","import FixedBuffer from './FixedBuffer';\nimport { OnProcess, RecyclerProps } from './types';\nimport {\n DEFAULT_RECYCLER_TYPE,\n RECYCLER_BUFFER_SIZE,\n RECYCLER_RESERVED_BUFFER_PER_BATCH,\n // RECYCLER_RESERVED_BUFFER_SIZE_RATIO,\n RECYCLER_THRESHOLD_INDEX_VALUE,\n} from './common';\n\nclass Recycler {\n private _queue: Array<FixedBuffer> = [];\n\n /**\n * start index\n */\n private _thresholdIndexValue = 0;\n private _recyclerReservedBufferPerBatch: number;\n /**\n * buffer size, the oversize node will run into recycle strategy\n */\n private _recyclerBufferSize: number;\n private _metaExtractor: (index: number) => any;\n private _indexExtractor: (meta: any) => number;\n private _getType: (index: number) => string;\n\n constructor(props?: RecyclerProps) {\n const {\n getType,\n metaExtractor,\n indexExtractor,\n recyclerTypes = [],\n recyclerBufferSize = RECYCLER_BUFFER_SIZE,\n thresholdIndexValue = RECYCLER_THRESHOLD_INDEX_VALUE,\n recyclerReservedBufferPerBatch = RECYCLER_RESERVED_BUFFER_PER_BATCH,\n } = props || {};\n\n this._metaExtractor = metaExtractor;\n this._indexExtractor = indexExtractor;\n this._getType = getType;\n this._recyclerBufferSize = recyclerBufferSize;\n this._thresholdIndexValue = thresholdIndexValue;\n this._recyclerReservedBufferPerBatch = recyclerReservedBufferPerBatch;\n recyclerTypes.forEach((type) => this.addBuffer(type));\n }\n\n get queue() {\n return this._queue;\n }\n\n get thresholdIndexValue() {\n return this._thresholdIndexValue;\n }\n\n get recyclerReservedBufferPerBatch() {\n return this._recyclerReservedBufferPerBatch;\n }\n\n getIndices() {\n return this._queue.reduce((acc, cur) => acc.concat(cur.getIndices()), []);\n }\n\n addBuffer(type: string) {\n if (!type) return null;\n const index = this._queue.findIndex(\n (buffer) => buffer.recyclerType === type\n );\n if (index !== -1) return this._queue[index];\n const buffer = new FixedBuffer({\n recyclerType: type,\n metaExtractor: this._metaExtractor,\n indexExtractor: this._indexExtractor,\n bufferSize: this._recyclerBufferSize,\n thresholdIndexValue: this._thresholdIndexValue,\n });\n this._queue.push(buffer);\n return buffer;\n }\n\n ensureBuffer(type: string) {\n return this.addBuffer(type || DEFAULT_RECYCLER_TYPE);\n }\n\n updateIndices(props: {\n /**\n * index in range should not be recycled\n */\n safeRange: {\n startIndex: number;\n endIndex: number;\n };\n startIndex: number;\n maxCount: number;\n step?: number;\n onProcess?: OnProcess;\n }) {\n const { startIndex, safeRange, step = 1, maxCount, onProcess } = props;\n let count = 0;\n let _index = Math.max(startIndex, 0);\n while (count < maxCount && this._metaExtractor(_index)) {\n if (_index >= this._thresholdIndexValue) {\n const recyclerType = this._getType(_index);\n const buffer = this.ensureBuffer(recyclerType);\n buffer.place(_index, safeRange);\n\n if (\n typeof onProcess !== 'function' ||\n onProcess(recyclerType, _index)\n ) {\n count += 1;\n }\n }\n _index += step;\n }\n }\n\n getMinValue() {\n let minValue = Number.MAX_SAFE_INTEGER;\n this._queue.forEach((buffer) => {\n const v = buffer.getMinValue();\n if (typeof v === 'number') minValue = Math.min(v, minValue);\n });\n return minValue;\n }\n\n getMaxValue() {\n let maxValue = 0;\n this._queue.forEach((buffer) => {\n const v = buffer.getMaxValue();\n if (typeof v === 'number') maxValue = Math.max(v, maxValue);\n });\n return maxValue;\n }\n}\n\nexport default Recycler;\n"],"names":["DEFAULT_RECYCLER_TYPE","RECYCLER_THRESHOLD_INDEX_VALUE","RECYCLER_RESERVED_BUFFER_PER_BATCH","RECYCLER_BUFFER_SIZE","FixedBuffer","props","_props$thresholdIndex","thresholdIndexValue","_props$bufferSize","bufferSize","_props$recyclerType","recyclerType","metaExtractor","indexExtractor","_bufferSet","IntegerBufferSet","name","_recyclerType","_thresholdIndexValue","_proto","prototype","place","index","safeRange","getPosition","getMaxValue","getMinValue","getIndices","_createClass","key","get","Recycler","_ref","getType","_ref$recyclerTypes","recyclerTypes","_ref$recyclerBufferSi","recyclerBufferSize","_ref$thresholdIndexVa","_ref$recyclerReserved","recyclerReservedBufferPerBatch","_metaExtractor","_indexExtractor","_getType","_recyclerBufferSize","_recyclerReservedBufferPerBatch","forEach","type","_this","addBuffer","_queue","reduce","acc","cur","concat","findIndex","buffer","push","ensureBuffer","updateIndices","startIndex","_props$step","step","maxCount","onProcess","count","_index","Math","max","minValue","Number","MAX_SAFE_INTEGER","v","min","maxValue"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAMA,qBAAqB,GAAG,6BAA6B;AAC3D,IAAMC,8BAA8B,GAAG,CAAC;AACxC,IAAMC,kCAAkC,GAAG,CAAC;AAC5C,IAAMC,oBAAoB,GAAG,EAAE;;ACDiC,IAEjEC,WAAW;EAMf,SAAAA,YAAYC,KAAuB;IAJ3B,yBAAoB,GAAG,CAAC;IAK9B,IAAAC,qBAAA,GAMID,KAAK,CALPE,mBAAmB;MAAnBA,mBAAmB,GAAAD,qBAAA,cAAG,CAAC,GAAAA,qBAAA;MAAAE,iBAAA,GAKrBH,KAAK,CAJPI,UAAU;MAAVA,UAAU,GAAAD,iBAAA,cAAGL,oBAAoB,GAAAK,iBAAA;MAAAE,mBAAA,GAI/BL,KAAK,CAHPM,YAAY;MAAZA,YAAY,GAAAD,mBAAA,cAAGV,qBAAqB,GAAAU,mBAAA;MACpCE,aAAa,GAEXP,KAAK,CAFPO,aAAa;MACbC,cAAc,GACZR,KAAK,CADPQ,cAAc;IAEhB,IAAI,CAACC,UAAU,GAAG,IAAIC,gBAAgB,CAAC;MACrCN,UAAU,EAAVA,UAAU;MACVG,aAAa,EAAbA,aAAa;MACbC,cAAc,EAAdA,cAAc;MACdG,IAAI,EAAEL;KACP,CAAC;IACF,IAAI,CAACM,aAAa,GAAGN,YAAY;IACjC,IAAI,CAACO,oBAAoB,GAAGX,mBAAmB;;EAChD,IAAAY,MAAA,GAAAf,WAAA,CAAAgB,SAAA;EAAAD,MAAA,CAUDE,KAAK,GAAL,SAAAA,MAAMC,KAA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AAM,CAACJ,OAAO,CAAC,UAACU,MAAM;MACzB,IAAMgB,CAAC,GAAGhB,MAAM,CAAC9B,WAAW,EAAE;MAC9B,IAAI,OAAO8C,CAAC,KAAK,QAAQ,EAAEH,QAAQ,GAAGF,IAAI,CAACM,GAAG,CAACD,CAAC,EAAEH,QAAQ,CAAC;KAC5D,CAAC;IACF,OAAOA,QAAQ;GAChB;EAAAlD,MAAA,CAEDM,WAAW,GAAX,SAAAA;IACE,IAAIiD,QAAQ,GAAG,CAAC;IAChB,IAAI,CAACxB,MAAM,CAACJ,OAAO,CAAC,UAACU,MAAM;MACzB,IAAMgB,CAAC,GAAGhB,MAAM,CAAC/B,WAAW,EAAE;MAC9B,IAAI,OAAO+C,CAAC,KAAK,QAAQ,EAAEE,QAAQ,GAAGP,IAAI,CAACC,GAAG,CAACI,CAAC,EAAEE,QAAQ,CAAC;KAC5D,CAAC;IACF,OAAOA,QAAQ;GAChB;EAAA9C,YAAA,CAAAG,QAAA;IAAAF,GAAA;IAAAC,GAAA,EAtFD,SAAAA;MACE,OAAO,IAAI,CAACoB,MAAM;;;IACnBrB,GAAA;IAAAC,GAAA,EAED,SAAAA;MACE,OAAO,IAAI,CAACZ,oBAAoB;;;IACjCW,GAAA;IAAAC,GAAA,EAED,SAAAA;MACE,OAAO,IAAI,CAACe,+BAA+B;;;EAC5C,OAAAd,QAAA;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"recycler.cjs.development.js","sources":["../src/common.ts","../src/index.ts"],"sourcesContent":["export const DEFAULT_RECYCLER_TYPE = '__default_recycler_buffer__';\nexport const RECYCLER_THRESHOLD_INDEX_VALUE = 0;\nexport const RECYCLER_RESERVED_BUFFER_PER_BATCH = 4;\nexport const RECYCLER_BUFFER_SIZE = 10;\n// export const RECYCLER_RESERVED_BUFFER_SIZE_RATIO = 1.5;\n\nexport const defaultGetType = () => DEFAULT_RECYCLER_TYPE;\n","import IntegerBufferSet from '@x-oasis/integer-buffer-set';\nimport { OnProcess, RecyclerProps } from './types';\nimport {\n DEFAULT_RECYCLER_TYPE,\n RECYCLER_BUFFER_SIZE,\n RECYCLER_RESERVED_BUFFER_PER_BATCH,\n RECYCLER_THRESHOLD_INDEX_VALUE,\n} from './common';\n\nclass Recycler {\n private _queue: Array<IntegerBufferSet> = [];\n\n /**\n * start index\n */\n private _thresholdIndexValue = 0;\n private _recyclerReservedBufferPerBatch: number;\n /**\n * buffer size, the oversize node will run into recycle strategy\n */\n private _recyclerBufferSize: number;\n private _metaExtractor: (index: number) => any;\n private _indexExtractor: (meta: any) => number;\n private _getType: (index: number) => string;\n\n constructor(props?: RecyclerProps) {\n const {\n getType,\n metaExtractor,\n indexExtractor,\n recyclerTypes = [],\n recyclerBufferSize = RECYCLER_BUFFER_SIZE,\n thresholdIndexValue = RECYCLER_THRESHOLD_INDEX_VALUE,\n recyclerReservedBufferPerBatch = RECYCLER_RESERVED_BUFFER_PER_BATCH,\n } = props || {};\n\n this._metaExtractor = metaExtractor;\n this._indexExtractor = indexExtractor;\n this._getType = getType;\n this._recyclerBufferSize = recyclerBufferSize;\n this._thresholdIndexValue = thresholdIndexValue;\n this._recyclerReservedBufferPerBatch = recyclerReservedBufferPerBatch;\n recyclerTypes.forEach((type) => this.addBuffer(type));\n }\n\n get queue() {\n return this._queue;\n }\n\n get thresholdIndexValue() {\n return this._thresholdIndexValue;\n }\n\n get recyclerReservedBufferPerBatch() {\n return this._recyclerReservedBufferPerBatch;\n }\n\n getIndices() {\n return this._queue.reduce((acc, cur) => acc.concat(cur.getIndices()), []);\n }\n\n addBuffer(type: string) {\n if (!type) return null;\n const index = this._queue.findIndex((buffer) => buffer.getType() === type);\n if (index !== -1) return this._queue[index];\n const buffer = new IntegerBufferSet({\n type,\n metaExtractor: this._metaExtractor,\n indexExtractor: this._indexExtractor,\n bufferSize: this._recyclerBufferSize,\n });\n this._queue.push(buffer);\n return buffer;\n }\n\n ensureBuffer(type: string) {\n return this.addBuffer(type || DEFAULT_RECYCLER_TYPE);\n }\n\n reset() {\n this.queue.forEach((buffer) => buffer.reset());\n }\n\n updateIndices(props: {\n /**\n * index in range should not be recycled\n */\n safeRange: {\n startIndex: number;\n endIndex: number;\n };\n startIndex: number;\n maxCount: number;\n step?: number;\n onProcess?: OnProcess;\n }) {\n const { startIndex, safeRange, step = 1, maxCount, onProcess } = props;\n let count = 0;\n let _index = Math.max(startIndex, 0);\n while (count < maxCount && this._metaExtractor(_index)) {\n if (_index >= this._thresholdIndexValue) {\n const recyclerType = this._getType(_index);\n const buffer = this.ensureBuffer(recyclerType);\n buffer.getPosition(_index, safeRange);\n\n if (\n typeof onProcess !== 'function' ||\n onProcess(recyclerType, _index)\n ) {\n count += 1;\n }\n }\n _index += step;\n }\n }\n\n getMinValue() {\n let minValue = Number.MAX_SAFE_INTEGER;\n this._queue.forEach((buffer) => {\n const v = buffer.getMinValue();\n if (typeof v === 'number') minValue = Math.min(v, minValue);\n });\n return minValue;\n }\n\n getMaxValue() {\n let maxValue = 0;\n this._queue.forEach((buffer) => {\n const v = buffer.getMaxValue();\n if (typeof v === 'number') maxValue = Math.max(v, maxValue);\n });\n return maxValue;\n }\n}\n\nexport default Recycler;\n"],"names":["DEFAULT_RECYCLER_TYPE","RECYCLER_THRESHOLD_INDEX_VALUE","RECYCLER_RESERVED_BUFFER_PER_BATCH","RECYCLER_BUFFER_SIZE","Recycler","props","_ref","getType","metaExtractor","indexExtractor","_ref$recyclerTypes","recyclerTypes","_ref$recyclerBufferSi","recyclerBufferSize","_ref$thresholdIndexVa","thresholdIndexValue","_ref$recyclerReserved","recyclerReservedBufferPerBatch","_metaExtractor","_indexExtractor","_getType","_recyclerBufferSize","_thresholdIndexValue","_recyclerReservedBufferPerBatch","forEach","type","_this","addBuffer","_proto","prototype","getIndices","_queue","reduce","acc","cur","concat","index","findIndex","buffer","IntegerBufferSet","bufferSize","push","ensureBuffer","reset","queue","updateIndices","startIndex","safeRange","_props$step","step","maxCount","onProcess","count","_index","Math","max","recyclerType","getPosition","getMinValue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A;IACE,IAAIC,QAAQ,GAAG,CAAC;IAChB,IAAI,CAAClC,MAAM,CAACP,OAAO,CAAC,UAACc,MAAM;MACzB,IAAMwB,CAAC,GAAGxB,MAAM,CAAC0B,WAAW,EAAE;MAC9B,IAAI,OAAOF,CAAC,KAAK,QAAQ,EAAEG,QAAQ,GAAGX,IAAI,CAACC,GAAG,CAACO,CAAC,EAAEG,QAAQ,CAAC;KAC5D,CAAC;IACF,OAAOA,QAAQ;GAChB;EAAAC,YAAA,CAAA9D,QAAA;IAAA+D,GAAA;IAAAC,GAAA,EAvFD,SAAAA;MACE,OAAO,IAAI,CAACrC,MAAM;;;IACnBoC,GAAA;IAAAC,GAAA,EAED,SAAAA;MACE,OAAO,IAAI,CAAC9C,oBAAoB;;;IACjC6C,GAAA;IAAAC,GAAA,EAED,SAAAA;MACE,OAAO,IAAI,CAAC7C,+BAA+B;;;EAC5C,OAAAnB,QAAA;AAAA;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("@x-oasis/integer-buffer-set"))&&"object"==typeof e&&"default"in e?e.default:e;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("@x-oasis/integer-buffer-set"))&&"object"==typeof e&&"default"in e?e.default:e;exports.default=function(){function e(e){var t=this;this._queue=[],this._thresholdIndexValue=0;var r=e||{},u=r.getType,n=r.indexExtractor,i=r.recyclerTypes,o=void 0===i?[]:i,a=r.recyclerBufferSize,f=void 0===a?10:a,c=r.thresholdIndexValue,s=void 0===c?0:c,h=r.recyclerReservedBufferPerBatch,d=void 0===h?4:h;this._metaExtractor=r.metaExtractor,this._indexExtractor=n,this._getType=u,this._recyclerBufferSize=f,this._thresholdIndexValue=s,this._recyclerReservedBufferPerBatch=d,o.forEach((function(e){return t.addBuffer(e)}))}var r,u,n=e.prototype;return n.getIndices=function(){return this._queue.reduce((function(e,t){return e.concat(t.getIndices())}),[])},n.addBuffer=function(e){if(!e)return null;var r=this._queue.findIndex((function(t){return t.getType()===e}));if(-1!==r)return this._queue[r];var u=new t({type:e,metaExtractor:this._metaExtractor,indexExtractor:this._indexExtractor,bufferSize:this._recyclerBufferSize});return this._queue.push(u),u},n.ensureBuffer=function(e){return this.addBuffer(e||"__default_recycler_buffer__")},n.reset=function(){this.queue.forEach((function(e){return e.reset()}))},n.updateIndices=function(e){for(var t=e.safeRange,r=e.step,u=void 0===r?1:r,n=e.maxCount,i=e.onProcess,o=0,a=Math.max(e.startIndex,0);o<n&&this._metaExtractor(a);){if(a>=this._thresholdIndexValue){var f=this._getType(a);this.ensureBuffer(f).getPosition(a,t),("function"!=typeof i||i(f,a))&&(o+=1)}a+=u}},n.getMinValue=function(){var e=Number.MAX_SAFE_INTEGER;return this._queue.forEach((function(t){var r=t.getMinValue();"number"==typeof r&&(e=Math.min(r,e))})),e},n.getMaxValue=function(){var e=0;return this._queue.forEach((function(t){var r=t.getMaxValue();"number"==typeof r&&(e=Math.max(r,e))})),e},r=e,(u=[{key:"queue",get:function(){return this._queue}},{key:"thresholdIndexValue",get:function(){return this._thresholdIndexValue}},{key:"recyclerReservedBufferPerBatch",get:function(){return this._recyclerReservedBufferPerBatch}}])&&function(e,t){for(var r=0;r<t.length;r++){var u=t[r];u.enumerable=u.enumerable||!1,u.configurable=!0,"value"in u&&(u.writable=!0),Object.defineProperty(e,"symbol"==typeof(n=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var u=r.call(e,"string");if("object"!=typeof u)return u;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(u.key))?n:String(n),u)}var n}(r.prototype,u),Object.defineProperty(r,"prototype",{writable:!1}),e}();
|
|
2
2
|
//# sourceMappingURL=recycler.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recycler.cjs.production.min.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"recycler.cjs.production.min.js","sources":["../src/index.ts","../src/common.ts"],"sourcesContent":["import IntegerBufferSet from '@x-oasis/integer-buffer-set';\nimport { OnProcess, RecyclerProps } from './types';\nimport {\n DEFAULT_RECYCLER_TYPE,\n RECYCLER_BUFFER_SIZE,\n RECYCLER_RESERVED_BUFFER_PER_BATCH,\n RECYCLER_THRESHOLD_INDEX_VALUE,\n} from './common';\n\nclass Recycler {\n private _queue: Array<IntegerBufferSet> = [];\n\n /**\n * start index\n */\n private _thresholdIndexValue = 0;\n private _recyclerReservedBufferPerBatch: number;\n /**\n * buffer size, the oversize node will run into recycle strategy\n */\n private _recyclerBufferSize: number;\n private _metaExtractor: (index: number) => any;\n private _indexExtractor: (meta: any) => number;\n private _getType: (index: number) => string;\n\n constructor(props?: RecyclerProps) {\n const {\n getType,\n metaExtractor,\n indexExtractor,\n recyclerTypes = [],\n recyclerBufferSize = RECYCLER_BUFFER_SIZE,\n thresholdIndexValue = RECYCLER_THRESHOLD_INDEX_VALUE,\n recyclerReservedBufferPerBatch = RECYCLER_RESERVED_BUFFER_PER_BATCH,\n } = props || {};\n\n this._metaExtractor = metaExtractor;\n this._indexExtractor = indexExtractor;\n this._getType = getType;\n this._recyclerBufferSize = recyclerBufferSize;\n this._thresholdIndexValue = thresholdIndexValue;\n this._recyclerReservedBufferPerBatch = recyclerReservedBufferPerBatch;\n recyclerTypes.forEach((type) => this.addBuffer(type));\n }\n\n get queue() {\n return this._queue;\n }\n\n get thresholdIndexValue() {\n return this._thresholdIndexValue;\n }\n\n get recyclerReservedBufferPerBatch() {\n return this._recyclerReservedBufferPerBatch;\n }\n\n getIndices() {\n return this._queue.reduce((acc, cur) => acc.concat(cur.getIndices()), []);\n }\n\n addBuffer(type: string) {\n if (!type) return null;\n const index = this._queue.findIndex((buffer) => buffer.getType() === type);\n if (index !== -1) return this._queue[index];\n const buffer = new IntegerBufferSet({\n type,\n metaExtractor: this._metaExtractor,\n indexExtractor: this._indexExtractor,\n bufferSize: this._recyclerBufferSize,\n });\n this._queue.push(buffer);\n return buffer;\n }\n\n ensureBuffer(type: string) {\n return this.addBuffer(type || DEFAULT_RECYCLER_TYPE);\n }\n\n reset() {\n this.queue.forEach((buffer) => buffer.reset());\n }\n\n updateIndices(props: {\n /**\n * index in range should not be recycled\n */\n safeRange: {\n startIndex: number;\n endIndex: number;\n };\n startIndex: number;\n maxCount: number;\n step?: number;\n onProcess?: OnProcess;\n }) {\n const { startIndex, safeRange, step = 1, maxCount, onProcess } = props;\n let count = 0;\n let _index = Math.max(startIndex, 0);\n while (count < maxCount && this._metaExtractor(_index)) {\n if (_index >= this._thresholdIndexValue) {\n const recyclerType = this._getType(_index);\n const buffer = this.ensureBuffer(recyclerType);\n buffer.getPosition(_index, safeRange);\n\n if (\n typeof onProcess !== 'function' ||\n onProcess(recyclerType, _index)\n ) {\n count += 1;\n }\n }\n _index += step;\n }\n }\n\n getMinValue() {\n let minValue = Number.MAX_SAFE_INTEGER;\n this._queue.forEach((buffer) => {\n const v = buffer.getMinValue();\n if (typeof v === 'number') minValue = Math.min(v, minValue);\n });\n return minValue;\n }\n\n getMaxValue() {\n let maxValue = 0;\n this._queue.forEach((buffer) => {\n const v = buffer.getMaxValue();\n if (typeof v === 'number') maxValue = Math.max(v, maxValue);\n });\n return maxValue;\n }\n}\n\nexport default Recycler;\n","export const DEFAULT_RECYCLER_TYPE = '__default_recycler_buffer__';\nexport const RECYCLER_THRESHOLD_INDEX_VALUE = 0;\nexport const RECYCLER_RESERVED_BUFFER_PER_BATCH = 4;\nexport const RECYCLER_BUFFER_SIZE = 10;\n// export const RECYCLER_RESERVED_BUFFER_SIZE_RATIO = 1.5;\n\nexport const defaultGetType = () => DEFAULT_RECYCLER_TYPE;\n"],"names":["Recycler","props","this","_ref","getType","indexExtractor","_ref$recyclerTypes","recyclerTypes","_ref$recyclerBufferSi","recyclerBufferSize","_ref$thresholdIndexVa","thresholdIndexValue","_ref$recyclerReserved","recyclerReservedBufferPerBatch","_metaExtractor","metaExtractor","_indexExtractor","_getType","_recyclerBufferSize","_thresholdIndexValue","_recyclerReservedBufferPerBatch","forEach","type","_this","addBuffer","_proto","prototype","getIndices","_queue","reduce","acc","cur","concat","index","findIndex","buffer","IntegerBufferSet","bufferSize","push","ensureBuffer","reset","queue","updateIndices","safeRange","_props$step","step","maxCount","onProcess","count","_index","Math","max","startIndex","recyclerType","getPosition","getMinValue","minValue","Number","MAX_SAFE_INTEGER","v","min","getMaxValue","maxValue","key","get"],"mappings":"iMAyBE,SAAAA,EAAYC,cAfJC,YAAkC,GAKlCA,0BAAuB,EAW7B,IAAAC,EAQIF,GAAS,GAPXG,EAAOD,EAAPC,QAEAC,EAAcF,EAAdE,eAAcC,EAAAH,EACdI,cAAAA,WAAaD,EAAG,GAAEA,EAAAE,EAAAL,EAClBM,mBAAAA,WAAkBD,EC5BY,GD4BWA,EAAAE,EAAAP,EACzCQ,oBAAAA,WAAmBD,EC/BqB,ED+BYA,EAAAE,EAAAT,EACpDU,+BAAAA,WAA8BD,EC/Bc,ED+BuBA,EAGrEV,KAAKY,eARUX,EAAbY,cASFb,KAAKc,gBAAkBX,EACvBH,KAAKe,SAAWb,EAChBF,KAAKgB,oBAAsBT,EAC3BP,KAAKiB,qBAAuBR,EAC5BT,KAAKkB,gCAAkCP,EACvCN,EAAcc,SAAQ,SAACC,GAAI,OAAKC,EAAKC,UAAUF,MAChD,QAAAG,EAAAzB,EAAA0B,UAYA,OAZAD,EAcDE,WAAA,WACE,OAAOzB,KAAK0B,OAAOC,QAAO,SAACC,EAAKC,GAAG,OAAKD,EAAIE,OAAOD,EAAIJ,gBAAe,KACvEF,EAEDD,UAAA,SAAUF,GACR,IAAKA,EAAM,OAAO,KAClB,IAAMW,EAAQ/B,KAAK0B,OAAOM,WAAU,SAACC,GAAM,OAAKA,EAAO/B,YAAckB,KACrE,IAAe,IAAXW,EAAc,OAAO/B,KAAK0B,OAAOK,GACrC,IAAME,EAAS,IAAIC,EAAiB,CAClCd,KAAAA,EACAP,cAAeb,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m.js
CHANGED
|
@@ -37,53 +37,6 @@ var RECYCLER_THRESHOLD_INDEX_VALUE = 0;
|
|
|
37
37
|
var RECYCLER_RESERVED_BUFFER_PER_BATCH = 4;
|
|
38
38
|
var RECYCLER_BUFFER_SIZE = 10;
|
|
39
39
|
|
|
40
|
-
var FixedBuffer = /*#__PURE__*/function () {
|
|
41
|
-
function FixedBuffer(props) {
|
|
42
|
-
this._thresholdIndexValue = 0;
|
|
43
|
-
var _props$thresholdIndex = props.thresholdIndexValue,
|
|
44
|
-
thresholdIndexValue = _props$thresholdIndex === void 0 ? 0 : _props$thresholdIndex,
|
|
45
|
-
_props$bufferSize = props.bufferSize,
|
|
46
|
-
bufferSize = _props$bufferSize === void 0 ? RECYCLER_BUFFER_SIZE : _props$bufferSize,
|
|
47
|
-
_props$recyclerType = props.recyclerType,
|
|
48
|
-
recyclerType = _props$recyclerType === void 0 ? DEFAULT_RECYCLER_TYPE : _props$recyclerType,
|
|
49
|
-
metaExtractor = props.metaExtractor,
|
|
50
|
-
indexExtractor = props.indexExtractor;
|
|
51
|
-
this._bufferSet = new IntegerBufferSet({
|
|
52
|
-
bufferSize: bufferSize,
|
|
53
|
-
metaExtractor: metaExtractor,
|
|
54
|
-
indexExtractor: indexExtractor,
|
|
55
|
-
name: recyclerType
|
|
56
|
-
});
|
|
57
|
-
this._recyclerType = recyclerType;
|
|
58
|
-
this._thresholdIndexValue = thresholdIndexValue;
|
|
59
|
-
}
|
|
60
|
-
var _proto = FixedBuffer.prototype;
|
|
61
|
-
_proto.place = function place(index, safeRange) {
|
|
62
|
-
this._bufferSet.getPosition(index, safeRange);
|
|
63
|
-
};
|
|
64
|
-
_proto.getMaxValue = function getMaxValue() {
|
|
65
|
-
return this._bufferSet.getMaxValue();
|
|
66
|
-
};
|
|
67
|
-
_proto.getMinValue = function getMinValue() {
|
|
68
|
-
return this._bufferSet.getMinValue();
|
|
69
|
-
};
|
|
70
|
-
_proto.getIndices = function getIndices() {
|
|
71
|
-
return this._bufferSet.getIndices();
|
|
72
|
-
};
|
|
73
|
-
_createClass(FixedBuffer, [{
|
|
74
|
-
key: "thresholdIndexValue",
|
|
75
|
-
get: function get() {
|
|
76
|
-
return this._thresholdIndexValue;
|
|
77
|
-
}
|
|
78
|
-
}, {
|
|
79
|
-
key: "recyclerType",
|
|
80
|
-
get: function get() {
|
|
81
|
-
return this._recyclerType;
|
|
82
|
-
}
|
|
83
|
-
}]);
|
|
84
|
-
return FixedBuffer;
|
|
85
|
-
}();
|
|
86
|
-
|
|
87
40
|
var Recycler = /*#__PURE__*/function () {
|
|
88
41
|
function Recycler(props) {
|
|
89
42
|
var _this = this;
|
|
@@ -120,15 +73,14 @@ var Recycler = /*#__PURE__*/function () {
|
|
|
120
73
|
_proto.addBuffer = function addBuffer(type) {
|
|
121
74
|
if (!type) return null;
|
|
122
75
|
var index = this._queue.findIndex(function (buffer) {
|
|
123
|
-
return buffer.
|
|
76
|
+
return buffer.getType() === type;
|
|
124
77
|
});
|
|
125
78
|
if (index !== -1) return this._queue[index];
|
|
126
|
-
var buffer = new
|
|
127
|
-
|
|
79
|
+
var buffer = new IntegerBufferSet({
|
|
80
|
+
type: type,
|
|
128
81
|
metaExtractor: this._metaExtractor,
|
|
129
82
|
indexExtractor: this._indexExtractor,
|
|
130
|
-
bufferSize: this._recyclerBufferSize
|
|
131
|
-
thresholdIndexValue: this._thresholdIndexValue
|
|
83
|
+
bufferSize: this._recyclerBufferSize
|
|
132
84
|
});
|
|
133
85
|
this._queue.push(buffer);
|
|
134
86
|
return buffer;
|
|
@@ -136,6 +88,11 @@ var Recycler = /*#__PURE__*/function () {
|
|
|
136
88
|
_proto.ensureBuffer = function ensureBuffer(type) {
|
|
137
89
|
return this.addBuffer(type || DEFAULT_RECYCLER_TYPE);
|
|
138
90
|
};
|
|
91
|
+
_proto.reset = function reset() {
|
|
92
|
+
this.queue.forEach(function (buffer) {
|
|
93
|
+
return buffer.reset();
|
|
94
|
+
});
|
|
95
|
+
};
|
|
139
96
|
_proto.updateIndices = function updateIndices(props) {
|
|
140
97
|
var startIndex = props.startIndex,
|
|
141
98
|
safeRange = props.safeRange,
|
|
@@ -149,7 +106,7 @@ var Recycler = /*#__PURE__*/function () {
|
|
|
149
106
|
if (_index >= this._thresholdIndexValue) {
|
|
150
107
|
var recyclerType = this._getType(_index);
|
|
151
108
|
var buffer = this.ensureBuffer(recyclerType);
|
|
152
|
-
buffer.
|
|
109
|
+
buffer.getPosition(_index, safeRange);
|
|
153
110
|
if (typeof onProcess !== 'function' || onProcess(recyclerType, _index)) {
|
|
154
111
|
count += 1;
|
|
155
112
|
}
|
package/dist/recycler.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recycler.esm.js","sources":["../src/common.ts","../src/FixedBuffer.ts","../src/index.ts"],"sourcesContent":["export const DEFAULT_RECYCLER_TYPE = '__default_recycler_buffer__';\nexport const RECYCLER_THRESHOLD_INDEX_VALUE = 0;\nexport const RECYCLER_RESERVED_BUFFER_PER_BATCH = 4;\nexport const RECYCLER_BUFFER_SIZE = 10;\n// export const RECYCLER_RESERVED_BUFFER_SIZE_RATIO = 1.5;\n\nexport const defaultGetType = () => DEFAULT_RECYCLER_TYPE;\n","import IntegerBufferSet from '@x-oasis/integer-buffer-set';\nimport { SafeRange, FixedBufferProps } from './types';\nimport { DEFAULT_RECYCLER_TYPE, RECYCLER_BUFFER_SIZE } from './common';\n\nclass FixedBuffer {\n private _bufferSet: IntegerBufferSet;\n private _thresholdIndexValue = 0;\n\n private _recyclerType: string;\n\n constructor(props: FixedBufferProps) {\n const {\n thresholdIndexValue = 0,\n bufferSize = RECYCLER_BUFFER_SIZE,\n recyclerType = DEFAULT_RECYCLER_TYPE,\n metaExtractor,\n indexExtractor,\n } = props;\n this._bufferSet = new IntegerBufferSet({\n bufferSize,\n metaExtractor,\n indexExtractor,\n name: recyclerType,\n });\n this._recyclerType = recyclerType;\n this._thresholdIndexValue = thresholdIndexValue;\n }\n\n get thresholdIndexValue() {\n return this._thresholdIndexValue;\n }\n\n get recyclerType() {\n return this._recyclerType;\n }\n\n place(index: number, safeRange: SafeRange) {\n this._bufferSet.getPosition(index, safeRange);\n }\n\n getMaxValue() {\n return this._bufferSet.getMaxValue();\n }\n\n getMinValue() {\n return this._bufferSet.getMinValue();\n }\n\n getIndices() {\n return this._bufferSet.getIndices();\n }\n}\n\nexport default FixedBuffer;\n","import FixedBuffer from './FixedBuffer';\nimport { OnProcess, RecyclerProps } from './types';\nimport {\n DEFAULT_RECYCLER_TYPE,\n RECYCLER_BUFFER_SIZE,\n RECYCLER_RESERVED_BUFFER_PER_BATCH,\n // RECYCLER_RESERVED_BUFFER_SIZE_RATIO,\n RECYCLER_THRESHOLD_INDEX_VALUE,\n} from './common';\n\nclass Recycler {\n private _queue: Array<FixedBuffer> = [];\n\n /**\n * start index\n */\n private _thresholdIndexValue = 0;\n private _recyclerReservedBufferPerBatch: number;\n /**\n * buffer size, the oversize node will run into recycle strategy\n */\n private _recyclerBufferSize: number;\n private _metaExtractor: (index: number) => any;\n private _indexExtractor: (meta: any) => number;\n private _getType: (index: number) => string;\n\n constructor(props?: RecyclerProps) {\n const {\n getType,\n metaExtractor,\n indexExtractor,\n recyclerTypes = [],\n recyclerBufferSize = RECYCLER_BUFFER_SIZE,\n thresholdIndexValue = RECYCLER_THRESHOLD_INDEX_VALUE,\n recyclerReservedBufferPerBatch = RECYCLER_RESERVED_BUFFER_PER_BATCH,\n } = props || {};\n\n this._metaExtractor = metaExtractor;\n this._indexExtractor = indexExtractor;\n this._getType = getType;\n this._recyclerBufferSize = recyclerBufferSize;\n this._thresholdIndexValue = thresholdIndexValue;\n this._recyclerReservedBufferPerBatch = recyclerReservedBufferPerBatch;\n recyclerTypes.forEach((type) => this.addBuffer(type));\n }\n\n get queue() {\n return this._queue;\n }\n\n get thresholdIndexValue() {\n return this._thresholdIndexValue;\n }\n\n get recyclerReservedBufferPerBatch() {\n return this._recyclerReservedBufferPerBatch;\n }\n\n getIndices() {\n return this._queue.reduce((acc, cur) => acc.concat(cur.getIndices()), []);\n }\n\n addBuffer(type: string) {\n if (!type) return null;\n const index = this._queue.findIndex(\n (buffer) => buffer.recyclerType === type\n );\n if (index !== -1) return this._queue[index];\n const buffer = new FixedBuffer({\n recyclerType: type,\n metaExtractor: this._metaExtractor,\n indexExtractor: this._indexExtractor,\n bufferSize: this._recyclerBufferSize,\n thresholdIndexValue: this._thresholdIndexValue,\n });\n this._queue.push(buffer);\n return buffer;\n }\n\n ensureBuffer(type: string) {\n return this.addBuffer(type || DEFAULT_RECYCLER_TYPE);\n }\n\n updateIndices(props: {\n /**\n * index in range should not be recycled\n */\n safeRange: {\n startIndex: number;\n endIndex: number;\n };\n startIndex: number;\n maxCount: number;\n step?: number;\n onProcess?: OnProcess;\n }) {\n const { startIndex, safeRange, step = 1, maxCount, onProcess } = props;\n let count = 0;\n let _index = Math.max(startIndex, 0);\n while (count < maxCount && this._metaExtractor(_index)) {\n if (_index >= this._thresholdIndexValue) {\n const recyclerType = this._getType(_index);\n const buffer = this.ensureBuffer(recyclerType);\n buffer.place(_index, safeRange);\n\n if (\n typeof onProcess !== 'function' ||\n onProcess(recyclerType, _index)\n ) {\n count += 1;\n }\n }\n _index += step;\n }\n }\n\n getMinValue() {\n let minValue = Number.MAX_SAFE_INTEGER;\n this._queue.forEach((buffer) => {\n const v = buffer.getMinValue();\n if (typeof v === 'number') minValue = Math.min(v, minValue);\n });\n return minValue;\n }\n\n getMaxValue() {\n let maxValue = 0;\n this._queue.forEach((buffer) => {\n const v = buffer.getMaxValue();\n if (typeof v === 'number') maxValue = Math.max(v, maxValue);\n });\n return maxValue;\n }\n}\n\nexport default Recycler;\n"],"names":["DEFAULT_RECYCLER_TYPE","RECYCLER_THRESHOLD_INDEX_VALUE","RECYCLER_RESERVED_BUFFER_PER_BATCH","RECYCLER_BUFFER_SIZE","FixedBuffer","props","_props$thresholdIndex","thresholdIndexValue","_props$bufferSize","bufferSize","_props$recyclerType","recyclerType","metaExtractor","indexExtractor","_bufferSet","IntegerBufferSet","name","_recyclerType","_thresholdIndexValue","_proto","prototype","place","index","safeRange","getPosition","getMaxValue","getMinValue","getIndices","_createClass","key","get","Recycler","_ref","getType","_ref$recyclerTypes","recyclerTypes","_ref$recyclerBufferSi","recyclerBufferSize","_ref$thresholdIndexVa","_ref$recyclerReserved","recyclerReservedBufferPerBatch","_metaExtractor","_indexExtractor","_getType","_recyclerBufferSize","_recyclerReservedBufferPerBatch","forEach","type","_this","addBuffer","_queue","reduce","acc","cur","concat","findIndex","buffer","push","ensureBuffer","updateIndices","startIndex","_props$step","step","maxCount","onProcess","count","_index","Math","max","minValue","Number","MAX_SAFE_INTEGER","v","min","maxValue"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAMA,qBAAqB,GAAG,6BAA6B;AAC3D,IAAMC,8BAA8B,GAAG,CAAC;AACxC,IAAMC,kCAAkC,GAAG,CAAC;AAC5C,IAAMC,oBAAoB,GAAG,EAAE;;ACDiC,IAEjEC,WAAW;EAMf,SAAAA,YAAYC,KAAuB;IAJ3B,yBAAoB,GAAG,CAAC;IAK9B,IAAAC,qBAAA,GAMID,KAAK,CALPE,mBAAmB;MAAnBA,mBAAmB,GAAAD,qBAAA,cAAG,CAAC,GAAAA,qBAAA;MAAAE,iBAAA,GAKrBH,KAAK,CAJPI,UAAU;MAAVA,UAAU,GAAAD,iBAAA,cAAGL,oBAAoB,GAAAK,iBAAA;MAAAE,mBAAA,GAI/BL,KAAK,CAHPM,YAAY;MAAZA,YAAY,GAAAD,mBAAA,cAAGV,qBAAqB,GAAAU,mBAAA;MACpCE,aAAa,GAEXP,KAAK,CAFPO,aAAa;MACbC,cAAc,GACZR,KAAK,CADPQ,cAAc;IAEhB,IAAI,CAACC,UAAU,GAAG,IAAIC,gBAAgB,CAAC;MACrCN,UAAU,EAAVA,UAAU;MACVG,aAAa,EAAbA,aAAa;MACbC,cAAc,EAAdA,cAAc;MACdG,IAA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AEuD,MAAM,CAAC,EAC/B;UACAD,KAAK,IAAI,CAAC;;;MAGdC,MAAM,IAAIJ,IAAI;;GAEjB;EAAA3C,MAAA,CAEDO,WAAW,GAAX,SAAAA;IACE,IAAI2C,QAAQ,GAAGC,MAAM,CAACC,gBAAgB;IACtC,IAAI,CAACrB,MAAM,CAACJ,OAAO,CAAC,UAACU,MAAM;MACzB,IAAMgB,CAAC,GAAGhB,MAAM,CAAC9B,WAAW,EAAE;MAC9B,IAAI,OAAO8C,CAAC,KAAK,QAAQ,EAAEH,QAAQ,GAAGF,IAAI,CAACM,GAAG,CAACD,CAAC,EAAEH,QAAQ,CAAC;KAC5D,CAAC;IACF,OAAOA,QAAQ;GAChB;EAAAlD,MAAA,CAEDM,WAAW,GAAX,SAAAA;IACE,IAAIiD,QAAQ,GAAG,CAAC;IAChB,IAAI,CAACxB,MAAM,CAACJ,OAAO,CAAC,UAACU,MAAM;MACzB,IAAMgB,CAAC,GAAGhB,MAAM,CAAC/B,WAAW,EAAE;MAC9B,IAAI,OAAO+C,CAAC,KAAK,QAAQ,EAAEE,QAAQ,GAAGP,IAAI,CAACC,GAAG,CAACI,CAAC,EAAEE,QAAQ,CAAC;KAC5D,CAAC;IACF,OAAOA,QAAQ;GAChB;EAAA9C,YAAA,CAAAG,QAAA;IAAAF,GAAA;IAAAC,GAAA,EAtFD,SAAAA;MACE,OAAO,IAAI,CAACoB,MAAM;;;IACnBrB,GAAA;IAAAC,GAAA,EAED,SAAAA;MACE,OAAO,IAAI,CAACZ,oBAAoB;;;IACjCW,GAAA;IAAAC,GAAA,EAED,SAAAA;MACE,OAAO,IAAI,CAACe,+BAA+B;;;EAC5C,OAAAd,QAAA;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"recycler.esm.js","sources":["../src/common.ts","../src/index.ts"],"sourcesContent":["export const DEFAULT_RECYCLER_TYPE = '__default_recycler_buffer__';\nexport const RECYCLER_THRESHOLD_INDEX_VALUE = 0;\nexport const RECYCLER_RESERVED_BUFFER_PER_BATCH = 4;\nexport const RECYCLER_BUFFER_SIZE = 10;\n// export const RECYCLER_RESERVED_BUFFER_SIZE_RATIO = 1.5;\n\nexport const defaultGetType = () => DEFAULT_RECYCLER_TYPE;\n","import IntegerBufferSet from '@x-oasis/integer-buffer-set';\nimport { OnProcess, RecyclerProps } from './types';\nimport {\n DEFAULT_RECYCLER_TYPE,\n RECYCLER_BUFFER_SIZE,\n RECYCLER_RESERVED_BUFFER_PER_BATCH,\n RECYCLER_THRESHOLD_INDEX_VALUE,\n} from './common';\n\nclass Recycler {\n private _queue: Array<IntegerBufferSet> = [];\n\n /**\n * start index\n */\n private _thresholdIndexValue = 0;\n private _recyclerReservedBufferPerBatch: number;\n /**\n * buffer size, the oversize node will run into recycle strategy\n */\n private _recyclerBufferSize: number;\n private _metaExtractor: (index: number) => any;\n private _indexExtractor: (meta: any) => number;\n private _getType: (index: number) => string;\n\n constructor(props?: RecyclerProps) {\n const {\n getType,\n metaExtractor,\n indexExtractor,\n recyclerTypes = [],\n recyclerBufferSize = RECYCLER_BUFFER_SIZE,\n thresholdIndexValue = RECYCLER_THRESHOLD_INDEX_VALUE,\n recyclerReservedBufferPerBatch = RECYCLER_RESERVED_BUFFER_PER_BATCH,\n } = props || {};\n\n this._metaExtractor = metaExtractor;\n this._indexExtractor = indexExtractor;\n this._getType = getType;\n this._recyclerBufferSize = recyclerBufferSize;\n this._thresholdIndexValue = thresholdIndexValue;\n this._recyclerReservedBufferPerBatch = recyclerReservedBufferPerBatch;\n recyclerTypes.forEach((type) => this.addBuffer(type));\n }\n\n get queue() {\n return this._queue;\n }\n\n get thresholdIndexValue() {\n return this._thresholdIndexValue;\n }\n\n get recyclerReservedBufferPerBatch() {\n return this._recyclerReservedBufferPerBatch;\n }\n\n getIndices() {\n return this._queue.reduce((acc, cur) => acc.concat(cur.getIndices()), []);\n }\n\n addBuffer(type: string) {\n if (!type) return null;\n const index = this._queue.findIndex((buffer) => buffer.getType() === type);\n if (index !== -1) return this._queue[index];\n const buffer = new IntegerBufferSet({\n type,\n metaExtractor: this._metaExtractor,\n indexExtractor: this._indexExtractor,\n bufferSize: this._recyclerBufferSize,\n });\n this._queue.push(buffer);\n return buffer;\n }\n\n ensureBuffer(type: string) {\n return this.addBuffer(type || DEFAULT_RECYCLER_TYPE);\n }\n\n reset() {\n this.queue.forEach((buffer) => buffer.reset());\n }\n\n updateIndices(props: {\n /**\n * index in range should not be recycled\n */\n safeRange: {\n startIndex: number;\n endIndex: number;\n };\n startIndex: number;\n maxCount: number;\n step?: number;\n onProcess?: OnProcess;\n }) {\n const { startIndex, safeRange, step = 1, maxCount, onProcess } = props;\n let count = 0;\n let _index = Math.max(startIndex, 0);\n while (count < maxCount && this._metaExtractor(_index)) {\n if (_index >= this._thresholdIndexValue) {\n const recyclerType = this._getType(_index);\n const buffer = this.ensureBuffer(recyclerType);\n buffer.getPosition(_index, safeRange);\n\n if (\n typeof onProcess !== 'function' ||\n onProcess(recyclerType, _index)\n ) {\n count += 1;\n }\n }\n _index += step;\n }\n }\n\n getMinValue() {\n let minValue = Number.MAX_SAFE_INTEGER;\n this._queue.forEach((buffer) => {\n const v = buffer.getMinValue();\n if (typeof v === 'number') minValue = Math.min(v, minValue);\n });\n return minValue;\n }\n\n getMaxValue() {\n let maxValue = 0;\n this._queue.forEach((buffer) => {\n const v = buffer.getMaxValue();\n if (typeof v === 'number') maxValue = Math.max(v, maxValue);\n });\n return maxValue;\n }\n}\n\nexport default Recycler;\n"],"names":["DEFAULT_RECYCLER_TYPE","RECYCLER_THRESHOLD_INDEX_VALUE","RECYCLER_RESERVED_BUFFER_PER_BATCH","RECYCLER_BUFFER_SIZE","Recycler","props","_ref","getType","metaExtractor","indexExtractor","_ref$recyclerTypes","recyclerTypes","_ref$recyclerBufferSi","recyclerBufferSize","_ref$thresholdIndexVa","thresholdIndexValue","_ref$recyclerReserved","recyclerReservedBufferPerBatch","_metaExtractor","_indexExtractor","_getType","_recyclerBufferSize","_thresholdIndexValue","_recyclerReservedBufferPerBatch","forEach","type","_this","addBuffer","_proto","prototype","getIndices","_queue","reduce","acc","cur","concat","index","findIndex","buffer","IntegerBufferSet","bufferSize","push","ensureBuffer","reset","queue","updateIndices","startIndex","safeRange","_props$step","step","maxCount","onProcess","count","_index","Math","max","recyclerType","getPosition","getMinValue","minValue","Number","MAX_SAFE_INTEGER","v","min","getMaxValue","maxValue","_createClass","key","get"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAMA,qBAAqB,GAAG,6BAA6B;AAC3D,IAAMC,8BAA8B,GAAG,CAAC;AACxC,IAAMC,kCAAkC,GAAG,CAAC;AAC5C,IAAMC,oBAAoB,GAAG,EAAE;;ACIpB,IAEZC,QAAQ;EAgBZ,SAAAA,SAAYC,KAAqB;;IAfzB,WAAM,GAA4B,EAAE;IAKpC,yBAAoB,GAAG,CAAC;IAW9B,IAAAC,IAAA,GAQID,KAAK,IAAI,EAAE;MAPbE,OAAO,GAAAD,IAAA,CAAPC,OAAO;MACPC,aAAa,GAAAF,IAAA,CAAbE,aAAa;MACbC,cAAc,GAAAH,IAAA,CAAdG,cAAc;MAAAC,kBAAA,GAAAJ,IAAA,CACdK,aAAa;MAAbA,aAAa,GAAAD,kBAAA,cAAG,EAAE,GAAAA,kBAAA;MAAAE,qBAAA,GAAAN,IAAA,CAClBO,kBAAkB;MAAlBA,kBAAkB,GAAAD,qBAAA,cAAGT,oBAAoB,GAAAS,qBAAA;MAAAE,qBAAA,GAAAR,IAAA,CACzCS,mBAAmB;MAAnBA,mBAAmB,GAAAD,qBAAA,cAAGb,8BAA8B,GAAAa,qBAAA;MAAAE,qBAAA,GAAAV,IAAA,CACpDW,8BAA8B;MAA9BA,8BAA8B,GAAAD,qBAAA,cAAGd,kCAAkC,GAAAc,qBAAA;IAGrE,IAAI,CAACE,cAAc,GAAGV,aAAa;IACnC,IAAI,CAACW,eAAe,GAAGV,cAAc;IACrC,IAAI,CAACW,QAAQ,GAAGb,OAAO;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9B,IAAI,OAAOI,CAAC,KAAK,QAAQ,EAAEH,QAAQ,GAAGL,IAAI,CAACS,GAAG,CAACD,CAAC,EAAEH,QAAQ,CAAC;KAC5D,CAAC;IACF,OAAOA,QAAQ;GAChB;EAAA/B,MAAA,CAEDoC,WAAW,GAAX,SAAAA;IACE,IAAIC,QAAQ,GAAG,CAAC;IAChB,IAAI,CAAClC,MAAM,CAACP,OAAO,CAAC,UAACc,MAAM;MACzB,IAAMwB,CAAC,GAAGxB,MAAM,CAAC0B,WAAW,EAAE;MAC9B,IAAI,OAAOF,CAAC,KAAK,QAAQ,EAAEG,QAAQ,GAAGX,IAAI,CAACC,GAAG,CAACO,CAAC,EAAEG,QAAQ,CAAC;KAC5D,CAAC;IACF,OAAOA,QAAQ;GAChB;EAAAC,YAAA,CAAA9D,QAAA;IAAA+D,GAAA;IAAAC,GAAA,EAvFD,SAAAA;MACE,OAAO,IAAI,CAACrC,MAAM;;;IACnBoC,GAAA;IAAAC,GAAA,EAED,SAAAA;MACE,OAAO,IAAI,CAAC9C,oBAAoB;;;IACjC6C,GAAA;IAAAC,GAAA,EAED,SAAAA;MACE,OAAO,IAAI,CAAC7C,+BAA+B;;;EAC5C,OAAAnB,QAAA;AAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-oasis/recycler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.31",
|
|
4
4
|
"description": "IntegerBufferSet function",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"tsdx": "^0.14.1"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@x-oasis/integer-buffer-set": "0.1.
|
|
19
|
+
"@x-oasis/integer-buffer-set": "0.1.31"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsdx build --tsconfig tsconfig.build.json",
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import IntegerBufferSet from '@x-oasis/integer-buffer-set';
|
|
2
2
|
import { OnProcess, RecyclerProps } from './types';
|
|
3
3
|
import {
|
|
4
4
|
DEFAULT_RECYCLER_TYPE,
|
|
5
5
|
RECYCLER_BUFFER_SIZE,
|
|
6
6
|
RECYCLER_RESERVED_BUFFER_PER_BATCH,
|
|
7
|
-
// RECYCLER_RESERVED_BUFFER_SIZE_RATIO,
|
|
8
7
|
RECYCLER_THRESHOLD_INDEX_VALUE,
|
|
9
8
|
} from './common';
|
|
10
9
|
|
|
11
10
|
class Recycler {
|
|
12
|
-
private _queue: Array<
|
|
11
|
+
private _queue: Array<IntegerBufferSet> = [];
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* start index
|
|
@@ -62,16 +61,13 @@ class Recycler {
|
|
|
62
61
|
|
|
63
62
|
addBuffer(type: string) {
|
|
64
63
|
if (!type) return null;
|
|
65
|
-
const index = this._queue.findIndex(
|
|
66
|
-
(buffer) => buffer.recyclerType === type
|
|
67
|
-
);
|
|
64
|
+
const index = this._queue.findIndex((buffer) => buffer.getType() === type);
|
|
68
65
|
if (index !== -1) return this._queue[index];
|
|
69
|
-
const buffer = new
|
|
70
|
-
|
|
66
|
+
const buffer = new IntegerBufferSet({
|
|
67
|
+
type,
|
|
71
68
|
metaExtractor: this._metaExtractor,
|
|
72
69
|
indexExtractor: this._indexExtractor,
|
|
73
70
|
bufferSize: this._recyclerBufferSize,
|
|
74
|
-
thresholdIndexValue: this._thresholdIndexValue,
|
|
75
71
|
});
|
|
76
72
|
this._queue.push(buffer);
|
|
77
73
|
return buffer;
|
|
@@ -81,6 +77,10 @@ class Recycler {
|
|
|
81
77
|
return this.addBuffer(type || DEFAULT_RECYCLER_TYPE);
|
|
82
78
|
}
|
|
83
79
|
|
|
80
|
+
reset() {
|
|
81
|
+
this.queue.forEach((buffer) => buffer.reset());
|
|
82
|
+
}
|
|
83
|
+
|
|
84
84
|
updateIndices(props: {
|
|
85
85
|
/**
|
|
86
86
|
* index in range should not be recycled
|
|
@@ -101,7 +101,7 @@ class Recycler {
|
|
|
101
101
|
if (_index >= this._thresholdIndexValue) {
|
|
102
102
|
const recyclerType = this._getType(_index);
|
|
103
103
|
const buffer = this.ensureBuffer(recyclerType);
|
|
104
|
-
buffer.
|
|
104
|
+
buffer.getPosition(_index, safeRange);
|
|
105
105
|
|
|
106
106
|
if (
|
|
107
107
|
typeof onProcess !== 'function' ||
|
package/dist/FixedBuffer.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { SafeRange, FixedBufferProps } from './types';
|
|
2
|
-
declare class FixedBuffer {
|
|
3
|
-
private _bufferSet;
|
|
4
|
-
private _thresholdIndexValue;
|
|
5
|
-
private _recyclerType;
|
|
6
|
-
constructor(props: FixedBufferProps);
|
|
7
|
-
get thresholdIndexValue(): number;
|
|
8
|
-
get recyclerType(): string;
|
|
9
|
-
place(index: number, safeRange: SafeRange): void;
|
|
10
|
-
getMaxValue(): number;
|
|
11
|
-
getMinValue(): number;
|
|
12
|
-
getIndices(): any;
|
|
13
|
-
}
|
|
14
|
-
export default FixedBuffer;
|
package/src/FixedBuffer.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import IntegerBufferSet from '@x-oasis/integer-buffer-set';
|
|
2
|
-
import { SafeRange, FixedBufferProps } from './types';
|
|
3
|
-
import { DEFAULT_RECYCLER_TYPE, RECYCLER_BUFFER_SIZE } from './common';
|
|
4
|
-
|
|
5
|
-
class FixedBuffer {
|
|
6
|
-
private _bufferSet: IntegerBufferSet;
|
|
7
|
-
private _thresholdIndexValue = 0;
|
|
8
|
-
|
|
9
|
-
private _recyclerType: string;
|
|
10
|
-
|
|
11
|
-
constructor(props: FixedBufferProps) {
|
|
12
|
-
const {
|
|
13
|
-
thresholdIndexValue = 0,
|
|
14
|
-
bufferSize = RECYCLER_BUFFER_SIZE,
|
|
15
|
-
recyclerType = DEFAULT_RECYCLER_TYPE,
|
|
16
|
-
metaExtractor,
|
|
17
|
-
indexExtractor,
|
|
18
|
-
} = props;
|
|
19
|
-
this._bufferSet = new IntegerBufferSet({
|
|
20
|
-
bufferSize,
|
|
21
|
-
metaExtractor,
|
|
22
|
-
indexExtractor,
|
|
23
|
-
name: recyclerType,
|
|
24
|
-
});
|
|
25
|
-
this._recyclerType = recyclerType;
|
|
26
|
-
this._thresholdIndexValue = thresholdIndexValue;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get thresholdIndexValue() {
|
|
30
|
-
return this._thresholdIndexValue;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get recyclerType() {
|
|
34
|
-
return this._recyclerType;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
place(index: number, safeRange: SafeRange) {
|
|
38
|
-
this._bufferSet.getPosition(index, safeRange);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getMaxValue() {
|
|
42
|
-
return this._bufferSet.getMaxValue();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
getMinValue() {
|
|
46
|
-
return this._bufferSet.getMinValue();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
getIndices() {
|
|
50
|
-
return this._bufferSet.getIndices();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export default FixedBuffer;
|