@x-oasis/recycler 0.1.35 → 0.1.36

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import IntegerBufferSet from '@x-oasis/integer-buffer-set';
2
2
  import { OnRecyclerProcess, RecyclerProps, SafeRange } from './types';
3
3
  export { OnRecyclerProcess, RecyclerProps };
4
- declare class Recycler {
4
+ declare class Recycler<ItemMeta = any> {
5
5
  private _queue;
6
6
  private _thresholdIndexValue;
7
7
  private _recyclerReservedBufferPerBatch;
@@ -11,12 +11,12 @@ declare class Recycler {
11
11
  private _getType;
12
12
  private _getMetaType;
13
13
  constructor(props?: RecyclerProps);
14
- get queue(): IntegerBufferSet<any>[];
14
+ get queue(): IntegerBufferSet<ItemMeta>[];
15
15
  get thresholdIndexValue(): number;
16
16
  get recyclerReservedBufferPerBatch(): number;
17
- getIndices(): any[];
18
- addBuffer(type: string): IntegerBufferSet<any>;
19
- ensureBuffer(type: string): IntegerBufferSet<any>;
17
+ getIndices(): import("@x-oasis/integer-buffer-set/dist/types").BufferIndicesItem<ItemMeta>[];
18
+ addBuffer(type: string): IntegerBufferSet<ItemMeta>;
19
+ ensureBuffer(type: string): IntegerBufferSet<ItemMeta>;
20
20
  reset(): void;
21
21
  updateIndices(props: {
22
22
  safeRange: SafeRange;
@@ -1 +1 @@
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 { OnRecyclerProcess, RecyclerProps, SafeRange, ItemMeta } 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';\nexport { OnRecyclerProcess, RecyclerProps };\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 private _getMetaType: (meta: ItemMeta) => string;\n\n constructor(props?: RecyclerProps) {\n const {\n getType,\n metaExtractor,\n getMetaType,\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._getMetaType = getMetaType;\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 getMetaType: this._getMetaType,\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: SafeRange;\n startIndex: number;\n maxCount: number;\n step?: number;\n onProcess?: OnRecyclerProcess;\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","getMetaType","indexExtractor","_ref$recyclerTypes","recyclerTypes","_ref$recyclerBufferSi","recyclerBufferSize","_ref$thresholdIndexVa","thresholdIndexValue","_ref$recyclerReserved","recyclerReservedBufferPerBatch","_metaExtractor","_indexExtractor","_getType","_getMetaType","_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,IAGZC,QAAQ;EAiBZ,SAAAA,SAAYC,KAAqB;;IAhBzB,WAAM,GAA4B,EAAE;IAKpC,yBAAoB,GAAG,CAAC;IAY9B,IAAAC,IAAA,GASID,KAAK,IAAI,EAAE;MARbE,OAAO,GAAAD,IAAA,CAAPC,OAAO;MACPC,aAAa,GAAAF,IAAA,CAAbE,aAAa;MACbC,WAAW,GAAAH,IAAA,CAAXG,WAAW;MACXC,cAAc,GAAAJ,IAAA,CAAdI,cAAc;MAAAC,kBAAA,GAAAL,IAAA,CACdM,aAAa;MAAbA,aAAa,GAAAD,kBAAA,cAAG,EAAE,GAAAA,kBAAA;MAAAE,qBAAA,GAAAP,IAAA,CAClBQ,kBAAkB;MAAlBA,kBAAkB,GAAAD,qBAAA,cAAGV,oBAAoB,GAAAU,qBAAA;MAAAE,qBAAA,GAAAT,IAAA,CACzCU,mBAAmB;MAAnBA,mBAAmB,GAAAD,qBAAA,cAAGd,8BAA8B,GAAAc,qBAAA;MAAAE,qBAAA,GAAAX,IAAA,CACpDY,8BAA8B;MAA9BA,8BAA8B,GAAAD,qBAAA,cAAGf,kCAAkC,GAAAe,qBAAA;IAGrE,IAAI,CAACE,cAAc,GAAGX,aAAa;IACnC,IAAI,CAACY,eAAe,GAAGV,cAAc;IACrC,IAAI,CAACW,QAAQ,GAAGd,OAAO;IACvB,IAAI,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MAAM;MACzB,IAAMwB,CAAC,GAAGxB,MAAM,CAACoB,WAAW,EAAE;MAC9B,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,CAAAhE,QAAA;IAAAiE,GAAA;IAAAC,GAAA,EArFD,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,OAAArB,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, { IndicesItem } from '@x-oasis/integer-buffer-set';\nimport { OnRecyclerProcess, RecyclerProps, SafeRange } 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';\nexport { OnRecyclerProcess, RecyclerProps };\n\nclass Recycler<ItemMeta = any> {\n private _queue: IntegerBufferSet<ItemMeta>[] = [];\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) => ItemMeta;\n private _indexExtractor: (meta: ItemMeta) => number;\n private _getType: (index: number) => string;\n private _getMetaType: (meta: ItemMeta) => string;\n\n constructor(props?: RecyclerProps) {\n const {\n getType,\n metaExtractor,\n getMetaType,\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._getMetaType = getMetaType;\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<IndicesItem<ItemMeta>[]>(\n (acc, cur) => acc.concat(cur.getIndices()),\n []\n );\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<ItemMeta>({\n type,\n getMetaType: this._getMetaType,\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 /**\n * should be invoked after getIndices...\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: SafeRange;\n startIndex: number;\n maxCount: number;\n step?: number;\n onProcess?: OnRecyclerProcess;\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","getMetaType","indexExtractor","_ref$recyclerTypes","recyclerTypes","_ref$recyclerBufferSi","recyclerBufferSize","_ref$thresholdIndexVa","thresholdIndexValue","_ref$recyclerReserved","recyclerReservedBufferPerBatch","_metaExtractor","_indexExtractor","_getType","_getMetaType","_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,IAGZC,QAAQ;EAiBZ,SAAAA,SAAYC,KAAqB;;IAhBzB,WAAM,GAAiC,EAAE;IAKzC,yBAAoB,GAAG,CAAC;IAY9B,IAAAC,IAAA,GASID,KAAK,IAAI,EAAE;MARbE,OAAO,GAAAD,IAAA,CAAPC,OAAO;MACPC,aAAa,GAAAF,IAAA,CAAbE,aAAa;MACbC,WAAW,GAAAH,IAAA,CAAXG,WAAW;MACXC,cAAc,GAAAJ,IAAA,CAAdI,cAAc;MAAAC,kBAAA,GAAAL,IAAA,CACdM,aAAa;MAAbA,aAAa,GAAAD,kBAAA,cAAG,EAAE,GAAAA,kBAAA;MAAAE,qBAAA,GAAAP,IAAA,CAClBQ,kBAAkB;MAAlBA,kBAAkB,GAAAD,qBAAA,cAAGV,oBAAoB,GAAAU,qBAAA;MAAAE,qBAAA,GAAAT,IAAA,CACzCU,mBAAmB;MAAnBA,mBAAmB,GAAAD,qBAAA,cAAGd,8BAA8B,GAAAc,qBAAA;MAAAE,qBAAA,GAAAX,IAAA,CACpDY,8BAA8B;MAA9BA,8BAA8B,GAAAD,qBAAA,cAAGf,kCAAkC,GAAAe,qBAAA;IAGrE,IAAI,CAACE,cAAc,GAAGX,aAAa;IACnC,IAAI,CAACY,eAAe,GAAGV,c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AgB;IACtC,IAAI,CAAC9B,MAAM,CAACP,OAAO,CAAC,UAACc,MAAM;MACzB,IAAMwB,CAAC,GAAGxB,MAAM,CAACoB,WAAW,EAAE;MAC9B,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,CAAAhE,QAAA;IAAAiE,GAAA;IAAAC,GAAA,EA3FD,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,OAAArB,QAAA;AAAA;;;;"}
@@ -1 +1 @@
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 { OnRecyclerProcess, RecyclerProps, SafeRange, ItemMeta } 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';\nexport { OnRecyclerProcess, RecyclerProps };\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 private _getMetaType: (meta: ItemMeta) => string;\n\n constructor(props?: RecyclerProps) {\n const {\n getType,\n metaExtractor,\n getMetaType,\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._getMetaType = getMetaType;\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 getMetaType: this._getMetaType,\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: SafeRange;\n startIndex: number;\n maxCount: number;\n step?: number;\n onProcess?: OnRecyclerProcess;\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","getMetaType","indexExtractor","_ref$recyclerTypes","recyclerTypes","_ref$recyclerBufferSi","recyclerBufferSize","_ref$thresholdIndexVa","thresholdIndexValue","_ref$recyclerReserved","recyclerReservedBufferPerBatch","_metaExtractor","metaExtractor","_indexExtractor","_getType","_getMetaType","_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":"iMA2BE,SAAAA,EAAYC,cAhBJC,YAAkC,GAKlCA,0BAAuB,EAY7B,IAAAC,EASIF,GAAS,GARXG,EAAOD,EAAPC,QAEAC,EAAWF,EAAXE,YACAC,EAAcH,EAAdG,eAAcC,EAAAJ,EACdK,cAAAA,WAAaD,EAAG,GAAEA,EAAAE,EAAAN,EAClBO,mBAAAA,WAAkBD,EC/BY,GD+BWA,EAAAE,EAAAR,EACzCS,oBAAAA,WAAmBD,EClCqB,EDkCYA,EAAAE,EAAAV,EACpDW,+BAAAA,WAA8BD,EClCc,EDkCuBA,EAGrEX,KAAKa,eATUZ,EAAba,cAUFd,KAAKe,gBAAkBX,EACvBJ,KAAKgB,SAAWd,EAChBF,KAAKiB,aAAed,EACpBH,KAAKkB,oBAAsBV,EAC3BR,KAAKmB,qBAAuBT,EAC5BV,KAAKoB,gCAAkCR,EACvCN,EAAce,SAAQ,SAACC,GAAI,OAAKC,EAAKC,UAAUF,MAChD,QAAAG,EAAA3B,EAAA4B,UAYA,OAZAD,EAcDE,WAAA,WACE,OAAO3B,KAAK4B,OAAOC,QAAO,SAACC,EAAKC,GAAG,OAAKD,EAAIE,OAAOD,EAAIJ,gBAAe,KACvEF,EAEDD,UAAA,SAAUF,GACR,IAAKA,EAAM,OAAO,KAClB,IAAMW,EAAQjC,KAAK4B,OAAOM,WAAU,SAACC,GAAM,OAAKA,EAAOjC,YAAcoB,KACrE,IAAe,IAAXW,EAAc,OAAOjC,KAAK4B,OAAOK,GACrC,IAAME,EAAS,IAAIC,EAAiB,CAClCd,KAAAA,EACAnB,YAAaH,KAAKiB,aAClBH,cAAed,KAAKa,eACpBT,eAAgBJ,KAAKe,gBACrBsB,WAAYrC,KAAKkB,sBAGnB,OADAlB,KAAK4B,OAAOU,KAAKH,GACVA,GACRV,EAEDc,aAAA,SAAajB,GACX,OAAOtB,KAAKwB,UAAUF,GCjFW,gCDkFlCG,EAEDe,MAAA,WACExC,KAAKyC,MAAMpB,SAAQ,SAACc,GAAM,OAAKA,EAAOK,YACvCf,EAEDiB,cAAA,SAAc3C,GAaZ,IAHA,IAAoB4C,EAA6C5C,EAA7C4C,UAASC,EAAoC7C,EAAlC8C,KAAAA,WAAID,EAAG,EAACA,EAAEE,EAAwB/C,EAAxB+C,SAAUC,EAAchD,EAAdgD,UAC/CC,EAAQ,EACRC,EAASC,KAAKC,IAF+CpD,EAAzDqD,WAE0B,GAC3BJ,EAAQF,GAAY9C,KAAKa,eAAeoC,IAAS,CACtD,GAAIA,GAAUjD,KAAKmB,qBAAsB,CACvC,IAAMkC,EAAerD,KAAKgB,SAASiC,GACpBjD,KAAKuC,aAAac,GAC1BC,YAAYL,EAAQN,IAGJ,mBAAdI,GACPA,EAAUM,EAAcJ,MAExBD,GAAS,GAGbC,GAAUJ,IAEbpB,EAED8B,YAAA,WACE,IAAIC,EAAWC,OAAOC,iBAKtB,OAJA1D,KAAK4B,OAAOP,SAAQ,SAACc,GACnB,IAAMwB,EAAIxB,EAAOoB,cACA,iBAANI,IAAgBH,EAAWN,KAAKU,IAAID,EAAGH,OAE7CA,GACR/B,EAEDoC,YAAA,WACE,IAAIC,EAAW,EAKf,OAJA9D,KAAK4B,OAAOP,SAAQ,SAACc,GACnB,IAAMwB,EAAIxB,EAAO0B,cACA,iBAANF,IAAgBG,EAAWZ,KAAKC,IAAIQ,EAAGG,OAE7CA,KACRhE,OAAAiE,YAAAC,IArFD,WACE,OAAOhE,KAAK4B,UACbmC,0BAAAC,IAED,WACE,OAAOhE,KAAKmB,wBACb4C,qCAAAC,IAED,WACE,OAAOhE,KAAKoB,kiBACbtB"}
1
+ {"version":3,"file":"recycler.cjs.production.min.js","sources":["../src/index.ts","../src/common.ts"],"sourcesContent":["import IntegerBufferSet, { IndicesItem } from '@x-oasis/integer-buffer-set';\nimport { OnRecyclerProcess, RecyclerProps, SafeRange } 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';\nexport { OnRecyclerProcess, RecyclerProps };\n\nclass Recycler<ItemMeta = any> {\n private _queue: IntegerBufferSet<ItemMeta>[] = [];\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) => ItemMeta;\n private _indexExtractor: (meta: ItemMeta) => number;\n private _getType: (index: number) => string;\n private _getMetaType: (meta: ItemMeta) => string;\n\n constructor(props?: RecyclerProps) {\n const {\n getType,\n metaExtractor,\n getMetaType,\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._getMetaType = getMetaType;\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<IndicesItem<ItemMeta>[]>(\n (acc, cur) => acc.concat(cur.getIndices()),\n []\n );\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<ItemMeta>({\n type,\n getMetaType: this._getMetaType,\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 /**\n * should be invoked after getIndices...\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: SafeRange;\n startIndex: number;\n maxCount: number;\n step?: number;\n onProcess?: OnRecyclerProcess;\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","getMetaType","indexExtractor","_ref$recyclerTypes","recyclerTypes","_ref$recyclerBufferSi","recyclerBufferSize","_ref$thresholdIndexVa","thresholdIndexValue","_ref$recyclerReserved","recyclerReservedBufferPerBatch","_metaExtractor","metaExtractor","_indexExtractor","_getType","_getMetaType","_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":"iMA2BE,SAAAA,EAAYC,cAhBJC,YAAuC,GAKvCA,0BAAuB,EAY7B,IAAAC,EASIF,GAAS,GARXG,EAAOD,EAAPC,QAEAC,EAAWF,EAAXE,YACAC,EAAcH,EAAdG,eAAcC,EAAAJ,EACdK,cAAAA,WAAaD,EAAG,GAAEA,EAAAE,EAAAN,EAClBO,mBAAAA,WAAkBD,EC/BY,GD+BWA,EAAAE,EAAAR,EACzCS,oBAAAA,WAAmBD,EClCqB,EDkCYA,EAAAE,EAAAV,EACpDW,+BAAAA,WAA8BD,EClCc,EDkCuBA,EAGrEX,KAAKa,eATUZ,EAAba,cAUFd,KAAKe,gBAAkBX,EACvBJ,KAAKgB,SAAWd,EAChBF,KAAKiB,aAAed,EACpBH,KAAKkB,oBAAsBV,EAC3BR,KAAKmB,qBAAuBT,EAC5BV,KAAKoB,gCAAkCR,EACvCN,EAAce,SAAQ,SAACC,GAAI,OAAKC,EAAKC,UAAUF,MAChD,QAAAG,EAAA3B,EAAA4B,UAYA,OAZAD,EAcDE,WAAA,WACE,OAAO3B,KAAK4B,OAAOC,QACjB,SAACC,EAAKC,GAAG,OAAKD,EAAIE,OAAOD,EAAIJ,gBAC7B,KAEHF,EAEDD,UAAA,SAAUF,GACR,IAAKA,EAAM,OAAO,KAClB,IAAMW,EAAQjC,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AAKC,IAAIQ,EAAGG,OAE7CA,KACRhE,OAAAiE,YAAAC,IA3FD,WACE,OAAOhE,KAAK4B,UACbmC,0BAAAC,IAED,WACE,OAAOhE,KAAKmB,wBACb4C,qCAAAC,IAED,WACE,OAAOhE,KAAKoB,kiBACbtB"}
@@ -1 +1 @@
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 { OnRecyclerProcess, RecyclerProps, SafeRange, ItemMeta } 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';\nexport { OnRecyclerProcess, RecyclerProps };\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 private _getMetaType: (meta: ItemMeta) => string;\n\n constructor(props?: RecyclerProps) {\n const {\n getType,\n metaExtractor,\n getMetaType,\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._getMetaType = getMetaType;\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 getMetaType: this._getMetaType,\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: SafeRange;\n startIndex: number;\n maxCount: number;\n step?: number;\n onProcess?: OnRecyclerProcess;\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","getMetaType","indexExtractor","_ref$recyclerTypes","recyclerTypes","_ref$recyclerBufferSi","recyclerBufferSize","_ref$thresholdIndexVa","thresholdIndexValue","_ref$recyclerReserved","recyclerReservedBufferPerBatch","_metaExtractor","_indexExtractor","_getType","_getMetaType","_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,IAGZC,QAAQ;EAiBZ,SAAAA,SAAYC,KAAqB;;IAhBzB,WAAM,GAA4B,EAAE;IAKpC,yBAAoB,GAAG,CAAC;IAY9B,IAAAC,IAAA,GASID,KAAK,IAAI,EAAE;MARbE,OAAO,GAAAD,IAAA,CAAPC,OAAO;MACPC,aAAa,GAAAF,IAAA,CAAbE,aAAa;MACbC,WAAW,GAAAH,IAAA,CAAXG,WAAW;MACXC,cAAc,GAAAJ,IAAA,CAAdI,cA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AO,IAAI,CAAC9C,oBAAoB;;;IACjC6C,GAAA;IAAAC,GAAA,EAED,SAAAA;MACE,OAAO,IAAI,CAAC7C,+BAA+B;;;EAC5C,OAAArB,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, { IndicesItem } from '@x-oasis/integer-buffer-set';\nimport { OnRecyclerProcess, RecyclerProps, SafeRange } 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';\nexport { OnRecyclerProcess, RecyclerProps };\n\nclass Recycler<ItemMeta = any> {\n private _queue: IntegerBufferSet<ItemMeta>[] = [];\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) => ItemMeta;\n private _indexExtractor: (meta: ItemMeta) => number;\n private _getType: (index: number) => string;\n private _getMetaType: (meta: ItemMeta) => string;\n\n constructor(props?: RecyclerProps) {\n const {\n getType,\n metaExtractor,\n getMetaType,\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._getMetaType = getMetaType;\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<IndicesItem<ItemMeta>[]>(\n (acc, cur) => acc.concat(cur.getIndices()),\n []\n );\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<ItemMeta>({\n type,\n getMetaType: this._getMetaType,\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 /**\n * should be invoked after getIndices...\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: SafeRange;\n startIndex: number;\n maxCount: number;\n step?: number;\n onProcess?: OnRecyclerProcess;\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","getMetaType","indexExtractor","_ref$recyclerTypes","recyclerTypes","_ref$recyclerBufferSi","recyclerBufferSize","_ref$thresholdIndexVa","thresholdIndexValue","_ref$recyclerReserved","recyclerReservedBufferPerBatch","_metaExtractor","_indexExtractor","_getType","_getMetaType","_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,IAGZC,QAAQ;EAiBZ,SAAAA,SAAYC,KAAqB;;IAhBzB,WAAM,GAAiC,EAAE;IAKzC,yBAAoB,GAAG,CAAC;IAY9B,IAAAC,IAAA,GASID,KAAK,IAAI,EAAE;MARbE,OAAO,GAAAD,IAAA,CAAPC,OAAO;MACPC,aAAa,GAAAF,IAAA,CAAbE,aAAa;MACbC,WAAW,GAAAH,IAAA,CAAX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ACnBoC,GAAA;IAAAC,GAAA,EAED,SAAAA;MACE,OAAO,IAAI,CAAC9C,oBAAoB;;;IACjC6C,GAAA;IAAAC,GAAA,EAED,SAAAA;MACE,OAAO,IAAI,CAAC7C,+BAA+B;;;EAC5C,OAAArB,QAAA;AAAA;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-oasis/recycler",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
4
4
  "description": "IntegerBufferSet function",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -15,8 +15,11 @@
15
15
  "devDependencies": {
16
16
  "tsdx": "^0.14.1"
17
17
  },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
18
21
  "dependencies": {
19
- "@x-oasis/integer-buffer-set": "0.1.35"
22
+ "@x-oasis/integer-buffer-set": "0.1.36"
20
23
  },
21
24
  "scripts": {
22
25
  "build": "tsdx build --tsconfig tsconfig.build.json",
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- import IntegerBufferSet from '@x-oasis/integer-buffer-set';
2
- import { OnRecyclerProcess, RecyclerProps, SafeRange, ItemMeta } from './types';
1
+ import IntegerBufferSet, { IndicesItem } from '@x-oasis/integer-buffer-set';
2
+ import { OnRecyclerProcess, RecyclerProps, SafeRange } from './types';
3
3
  import {
4
4
  DEFAULT_RECYCLER_TYPE,
5
5
  RECYCLER_BUFFER_SIZE,
@@ -8,8 +8,8 @@ import {
8
8
  } from './common';
9
9
  export { OnRecyclerProcess, RecyclerProps };
10
10
 
11
- class Recycler {
12
- private _queue: Array<IntegerBufferSet> = [];
11
+ class Recycler<ItemMeta = any> {
12
+ private _queue: IntegerBufferSet<ItemMeta>[] = [];
13
13
 
14
14
  /**
15
15
  * start index
@@ -20,8 +20,8 @@ class Recycler {
20
20
  * buffer size, the oversize node will run into recycle strategy
21
21
  */
22
22
  private _recyclerBufferSize: number;
23
- private _metaExtractor: (index: number) => any;
24
- private _indexExtractor: (meta: any) => number;
23
+ private _metaExtractor: (index: number) => ItemMeta;
24
+ private _indexExtractor: (meta: ItemMeta) => number;
25
25
  private _getType: (index: number) => string;
26
26
  private _getMetaType: (meta: ItemMeta) => string;
27
27
 
@@ -60,14 +60,17 @@ class Recycler {
60
60
  }
61
61
 
62
62
  getIndices() {
63
- return this._queue.reduce((acc, cur) => acc.concat(cur.getIndices()), []);
63
+ return this._queue.reduce<IndicesItem<ItemMeta>[]>(
64
+ (acc, cur) => acc.concat(cur.getIndices()),
65
+ []
66
+ );
64
67
  }
65
68
 
66
69
  addBuffer(type: string) {
67
70
  if (!type) return null;
68
71
  const index = this._queue.findIndex((buffer) => buffer.getType() === type);
69
72
  if (index !== -1) return this._queue[index];
70
- const buffer = new IntegerBufferSet({
73
+ const buffer = new IntegerBufferSet<ItemMeta>({
71
74
  type,
72
75
  getMetaType: this._getMetaType,
73
76
  metaExtractor: this._metaExtractor,
@@ -82,6 +85,9 @@ class Recycler {
82
85
  return this.addBuffer(type || DEFAULT_RECYCLER_TYPE);
83
86
  }
84
87
 
88
+ /**
89
+ * should be invoked after getIndices...
90
+ */
85
91
  reset() {
86
92
  this.queue.forEach((buffer) => buffer.reset());
87
93
  }