@x-oasis/integer-buffer-set
Advanced tools
Comparing version 0.1.26 to 0.1.27
@@ -184,3 +184,3 @@ 'use strict'; | ||
position = this.getFliedPosition(newIndex, safeRange); | ||
} else if ((indexMeta = this._indexToMetaMap.get(newIndex)) && this._metaToPositionMap.get(indexMeta)) { | ||
} else if ((indexMeta = this._indexToMetaMap.get(newIndex)) && this._metaToPositionMap.get(indexMeta) != null) { | ||
position = this.commitPosition({ | ||
@@ -443,3 +443,2 @@ newIndex: newIndex, | ||
} | ||
this._largeValues.peek().value; | ||
this._smallValues = smallValues; | ||
@@ -446,0 +445,0 @@ this._largeValues = largeValues; |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("@x-oasis/heap")),i=t(require("@x-oasis/is-clamped")),s=t(require("@x-oasis/invariant")),n=t(require("@x-oasis/return-hook")),a=function(t){return t},o=Number.MAX_SAFE_INTEGER-1e5;exports.default=function(){function t(t){void 0===t&&(t={});var i=t.name,s=void 0===i?"default_buffer":i,o=t.indexExtractor,r=t.bufferSize,l=void 0===r?10:r,h=t.metaExtractor;this._metaExtractor=void 0===h?a:h,this._indexExtractor=o,this._name=s,this._indexToMetaMap=new Map,this._metaToPositionMap=new Map,this._positionToMetaList=[],this._metaToIndexMap=new Map,this._onTheFlyIndices=[],this._bufferSize=l,this._smallValues=new e([],this._smallerComparator),this._largeValues=new e([],this._greaterComparator),this.getNewPositionForIndex=this.getNewPositionForIndex.bind(this),this.getIndexPosition=this.getIndexPosition.bind(this),this.replaceFurthestIndexPosition=this.replaceFurthestIndexPosition.bind(this),this._isOnTheFlyFullReturnHook=n(this.setIsOnTheFlyFull.bind(this)),this._loopMS=Date.now(),this._lastUpdatedMS=this._loopMS}var r,l,h=t.prototype;return h.isThresholdMeta=function(t){return"number"==typeof t&&t>o},h.setIsOnTheFlyFull=function(t){if(null!=t){var e=this._onTheFlyIndices.filter((function(t){return null!=t}));this._isOnTheFlyFull=e.length===this._bufferSize}},h.resetOnTheFlies=function(){this._isOnTheFlyFull=!1,this._onTheFlyIndices=[]},h.getOnTheFlyUncriticalPosition=function(t){for(var e=t.startIndex,s=t.endIndex,n=0;n<this._onTheFlyIndices.length;n++){var a=this.getMetaIndex(this._onTheFlyIndices[n]);if(!i(e,a,s))return n}return null},h.initialize=function(){return{smallValues:new e([],this._smallerComparator),largeValues:new e([],this._greaterComparator)}},h.getIndexMeta=function(t){return null==t||t<0?null:this._metaExtractor(t)},h.getMetaIndex=function(t){return null==t||this.isThresholdMeta(t)?-1:this._indexExtractor?this._indexExtractor(t):this._metaToIndexMap.get(t)},h.setMetaIndex=function(t,e){return!this._indexExtractor&&this._metaToIndexMap.set(t,e)},h.deleteMetaIndex=function(t){return this._metaToIndexMap.delete(t)},h.replaceMetaToIndexMap=function(t){return!this._indexExtractor&&(this._metaToIndexMap=t)},h.getIndexPosition=function(t){return this.getMetaIndex(this.getIndexMeta(t))},h.getNewPositionForIndex=function(t){var e=this.getIndexMeta(t);void 0!==this._metaToPositionMap.get(e)&&s(!1);var i=this._positionToMetaList.length;return this._pushToHeaps(i,t),this._setMetaIndex(e,t),this._setMetaPosition(e,i),i},h.getMinValue=function(){var t;return null==(t=this._smallValues.peek())?void 0:t.value},h.getMaxValue=function(){var t;return null==(t=this._largeValues.peek())?void 0:t.value},h.getFliedPosition=function(t,e){return this._isOnTheFlyFull&&e&&i(e.startIndex,t,e.endIndex)?this.getOnTheFlyUncriticalPosition(e):null},h.getPosition=function(t,e){this.prepare();var i,s,n=this.getIndexMeta(t),a=this._metaToPositionMap.get(n);return void 0!==a?i=this.commitPosition({newIndex:t,meta:n,safeRange:e,position:a}):this.isBufferFull?this._isOnTheFlyFull?i=this.getFliedPosition(t,e):(s=this._indexToMetaMap.get(t))&&this._metaToPositionMap.get(s)?i=this.commitPosition({newIndex:t,meta:n,safeRange:e,position:this._metaToPositionMap.get(s)}):(this._cleanHeaps(),i=this.commitPosition({newIndex:t,meta:n,safeRange:e,position:this._replaceFurthestIndexPosition(t,e)})):i=this.getNewPositionForIndex(t),null!=i?(this._onTheFlyIndices[i]=n,this._setMetaIndex(n,t),this._metaToPositionMap.set(n,i),this._isOnTheFlyFullReturnHook(i)):null},h.replaceFurthestIndexPosition=function(t,e){return this.isBufferFull?this._replaceFurthestIndexPosition(t,e):this._isOnTheFlyFullReturnHook(this.getNewPositionForIndex(t))},h._replaceFurthestIndexPosition=function(t,e){if(this._largeValues.empty()||this._smallValues.empty())return this._isOnTheFlyFullReturnHook(this.getNewPositionForIndex(t));var s,n=this._smallValues.peek().value,a=this._largeValues.peek().value;if(a>o){s=a,this._largeValues.pop();var r=this._indexToMetaMap.get(s);return this._metaToPositionMap.get(r)}if(!e){Math.abs(t-n)>Math.abs(t-a)?(s=n,this._smallValues.pop()):(s=a,this._largeValues.pop());var l=this._indexToMetaMap.get(s);return this._metaToPositionMap.get(l)}var h=e.startIndex,u=e.endIndex;if(i(h,n,u)&&i(h,a,u))return null;i(h,n,u)&&!i(h,a,u)?(s=a,this._largeValues.pop()):!i(h,n,u)&&i(h,a,u)||h-n>a-u?(s=n,this._smallValues.pop()):(s=a,this._largeValues.pop());var p=this._indexToMetaMap.get(s);return this._metaToPositionMap.get(p)},h.shuffle=function(){for(var t=this,e=new Array(this.bufferSize),i=0;i<e.length;i++){var s=this.getMetaIndex(this._onTheFlyIndices[i]||this._positionToMetaList[i]);e[i]=s}for(var n=new Array(e.length),a=[],o=new Map,r=new Map,l=function(){var i=e[h],s=t._metaExtractor(i);if(null==s)return"continue";if(o.set(i,s),r.set(s,i),s===t._positionToMetaList[h])return n[h]=s,"continue";var l=t._positionToMetaList.findIndex((function(t){return t===s}));if(-1!==l)return n[l]=s,"continue";a.push(s)},h=0;h<e.length;h++)l();var u=[];this._indexToMetaMap=o,this.replaceMetaToIndexMap(r);for(var p=0;p<e.length;p++)if(null==n[p]){var _=a.shift();null!=_&&(u[p]=_)}else u[p]=n[p];return this._positionToMetaList=u,this.getIndices()},h.getIndices=function(){var t=this.initialize(),e=t.smallValues,i=t.largeValues;try{for(var s=new Array(this._positionToMetaList.length),n=new Map,a=new Map,o=new Map,r=0;r<s.length;r++){var l=this._onTheFlyIndices[r]||this._positionToMetaList[r],h=this.getMetaIndex(l);if(!this.isThresholdMeta(l)&&l!=this.getIndexMeta(h))return this.shuffle();if(null!=l&&!this.isThresholdMeta(l)){var u={position:r,value:h};e.push(u),i.push(u),n.set(l,r),a.set(h,l),o.set(l,h),s[r]={meta:l,targetIndex:h,recyclerKey:this._name+"_"+r}}}return this._smallValues=e,this._largeValues=i,this._metaToPositionMap=n,this._positionToMetaList=s.map((function(t){return null==t?void 0:t.meta})),this.resetOnTheFlies(),this._indexToMetaMap=a,this.replaceMetaToIndexMap(o),s}catch(t){return console.log("err ",t),this._positionToMetaList}finally{this.readyToStartNextLoop()}},h._pushToHeaps=function(t,e){var i={position:t,value:e};this._smallValues.push(i),this._largeValues.push(i)},h._setMetaPosition=function(t,e){this._positionToMetaList[e]=t,this._metaToPositionMap.set(t,e)},h.commitPosition=function(t){var e=t.newIndex,i=t.safeRange,s=t.position,n=this._onTheFlyIndices[s],a=s;if(n){if(n===t.meta)return s;if(this._isOnTheFlyFull)return this.getFliedPosition(e,i);for(a=this._replaceFurthestIndexPosition(e,i);this._onTheFlyIndices[a];)a=this._replaceFurthestIndexPosition(e,i)}return a},h._setMetaIndex=function(t,e){var i=this.getMetaIndex(t);return void 0!==i&&this._indexToMetaMap.delete(i),this.setMetaIndex(t,e),this._indexToMetaMap.set(e,t),!1},h.readyToStartNextLoop=function(){this._lastUpdatedMS=Date.now()},h.prepare=function(){this._loopMS!==this._lastUpdatedMS&&(this._loopMS=this._lastUpdatedMS,this._onTheFlyIndices=[],this._isOnTheFlyFull=!1)},h._cleanHeaps=function(){for(var t=0;t<this._positionToMetaList.length;t++)if(null==this._positionToMetaList[t])return void this._recreateHeaps();var e=Math.min(this._smallValues.size(),this._largeValues.size());Math.max(this._smallValues.size(),this._largeValues.size())>10*e&&this._recreateHeaps()},h._recreateHeaps=function(){for(var t=this.initialize(),e=t.smallValues,i=t.largeValues,s=0;s<this._positionToMetaList.length;s++){var n=this._positionToMetaList[s],a=this.getMetaIndex(n);n&&-1!==a&&null!=a||(a=Number.MAX_SAFE_INTEGER-s);var r={position:s,value:a};e.push(r),i.push(r),a>o&&(this._setMetaPosition(a,s),this._setMetaIndex(a,a))}this._largeValues.peek(),this._smallValues=e,this._largeValues=i},h._smallerComparator=function(t,e){return t.value<e.value},h._greaterComparator=function(t,e){return t.value>e.value},r=t,(l=[{key:"bufferSize",get:function(){return this._bufferSize}},{key:"isBufferFull",get:function(){return this._positionToMetaList.length>=this._bufferSize}}])&&function(t,e){for(var i=0;i<e.length;i++){var s=e[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,"symbol"==typeof(n=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var s=i.call(t,"string");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(s.key))?n:String(n),s)}var n}(r.prototype,l),Object.defineProperty(r,"prototype",{writable:!1}),t}(),exports.defaultBufferSize=10; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("@x-oasis/heap")),i=t(require("@x-oasis/is-clamped")),s=t(require("@x-oasis/invariant")),n=t(require("@x-oasis/return-hook")),a=function(t){return t},o=Number.MAX_SAFE_INTEGER-1e5;exports.default=function(){function t(t){void 0===t&&(t={});var i=t.name,s=void 0===i?"default_buffer":i,o=t.indexExtractor,r=t.bufferSize,l=void 0===r?10:r,h=t.metaExtractor;this._metaExtractor=void 0===h?a:h,this._indexExtractor=o,this._name=s,this._indexToMetaMap=new Map,this._metaToPositionMap=new Map,this._positionToMetaList=[],this._metaToIndexMap=new Map,this._onTheFlyIndices=[],this._bufferSize=l,this._smallValues=new e([],this._smallerComparator),this._largeValues=new e([],this._greaterComparator),this.getNewPositionForIndex=this.getNewPositionForIndex.bind(this),this.getIndexPosition=this.getIndexPosition.bind(this),this.replaceFurthestIndexPosition=this.replaceFurthestIndexPosition.bind(this),this._isOnTheFlyFullReturnHook=n(this.setIsOnTheFlyFull.bind(this)),this._loopMS=Date.now(),this._lastUpdatedMS=this._loopMS}var r,l,h=t.prototype;return h.isThresholdMeta=function(t){return"number"==typeof t&&t>o},h.setIsOnTheFlyFull=function(t){if(null!=t){var e=this._onTheFlyIndices.filter((function(t){return null!=t}));this._isOnTheFlyFull=e.length===this._bufferSize}},h.resetOnTheFlies=function(){this._isOnTheFlyFull=!1,this._onTheFlyIndices=[]},h.getOnTheFlyUncriticalPosition=function(t){for(var e=t.startIndex,s=t.endIndex,n=0;n<this._onTheFlyIndices.length;n++){var a=this.getMetaIndex(this._onTheFlyIndices[n]);if(!i(e,a,s))return n}return null},h.initialize=function(){return{smallValues:new e([],this._smallerComparator),largeValues:new e([],this._greaterComparator)}},h.getIndexMeta=function(t){return null==t||t<0?null:this._metaExtractor(t)},h.getMetaIndex=function(t){return null==t||this.isThresholdMeta(t)?-1:this._indexExtractor?this._indexExtractor(t):this._metaToIndexMap.get(t)},h.setMetaIndex=function(t,e){return!this._indexExtractor&&this._metaToIndexMap.set(t,e)},h.deleteMetaIndex=function(t){return this._metaToIndexMap.delete(t)},h.replaceMetaToIndexMap=function(t){return!this._indexExtractor&&(this._metaToIndexMap=t)},h.getIndexPosition=function(t){return this.getMetaIndex(this.getIndexMeta(t))},h.getNewPositionForIndex=function(t){var e=this.getIndexMeta(t);void 0!==this._metaToPositionMap.get(e)&&s(!1);var i=this._positionToMetaList.length;return this._pushToHeaps(i,t),this._setMetaIndex(e,t),this._setMetaPosition(e,i),i},h.getMinValue=function(){var t;return null==(t=this._smallValues.peek())?void 0:t.value},h.getMaxValue=function(){var t;return null==(t=this._largeValues.peek())?void 0:t.value},h.getFliedPosition=function(t,e){return this._isOnTheFlyFull&&e&&i(e.startIndex,t,e.endIndex)?this.getOnTheFlyUncriticalPosition(e):null},h.getPosition=function(t,e){this.prepare();var i,s,n=this.getIndexMeta(t),a=this._metaToPositionMap.get(n);return void 0!==a?i=this.commitPosition({newIndex:t,meta:n,safeRange:e,position:a}):this.isBufferFull?this._isOnTheFlyFull?i=this.getFliedPosition(t,e):(s=this._indexToMetaMap.get(t))&&null!=this._metaToPositionMap.get(s)?i=this.commitPosition({newIndex:t,meta:n,safeRange:e,position:this._metaToPositionMap.get(s)}):(this._cleanHeaps(),i=this.commitPosition({newIndex:t,meta:n,safeRange:e,position:this._replaceFurthestIndexPosition(t,e)})):i=this.getNewPositionForIndex(t),null!=i?(this._onTheFlyIndices[i]=n,this._setMetaIndex(n,t),this._metaToPositionMap.set(n,i),this._isOnTheFlyFullReturnHook(i)):null},h.replaceFurthestIndexPosition=function(t,e){return this.isBufferFull?this._replaceFurthestIndexPosition(t,e):this._isOnTheFlyFullReturnHook(this.getNewPositionForIndex(t))},h._replaceFurthestIndexPosition=function(t,e){if(this._largeValues.empty()||this._smallValues.empty())return this._isOnTheFlyFullReturnHook(this.getNewPositionForIndex(t));var s,n=this._smallValues.peek().value,a=this._largeValues.peek().value;if(a>o){s=a,this._largeValues.pop();var r=this._indexToMetaMap.get(s);return this._metaToPositionMap.get(r)}if(!e){Math.abs(t-n)>Math.abs(t-a)?(s=n,this._smallValues.pop()):(s=a,this._largeValues.pop());var l=this._indexToMetaMap.get(s);return this._metaToPositionMap.get(l)}var h=e.startIndex,u=e.endIndex;if(i(h,n,u)&&i(h,a,u))return null;i(h,n,u)&&!i(h,a,u)?(s=a,this._largeValues.pop()):!i(h,n,u)&&i(h,a,u)||h-n>a-u?(s=n,this._smallValues.pop()):(s=a,this._largeValues.pop());var p=this._indexToMetaMap.get(s);return this._metaToPositionMap.get(p)},h.shuffle=function(){for(var t=this,e=new Array(this.bufferSize),i=0;i<e.length;i++){var s=this.getMetaIndex(this._onTheFlyIndices[i]||this._positionToMetaList[i]);e[i]=s}for(var n=new Array(e.length),a=[],o=new Map,r=new Map,l=function(){var i=e[h],s=t._metaExtractor(i);if(null==s)return"continue";if(o.set(i,s),r.set(s,i),s===t._positionToMetaList[h])return n[h]=s,"continue";var l=t._positionToMetaList.findIndex((function(t){return t===s}));if(-1!==l)return n[l]=s,"continue";a.push(s)},h=0;h<e.length;h++)l();var u=[];this._indexToMetaMap=o,this.replaceMetaToIndexMap(r);for(var p=0;p<e.length;p++)if(null==n[p]){var _=a.shift();null!=_&&(u[p]=_)}else u[p]=n[p];return this._positionToMetaList=u,this.getIndices()},h.getIndices=function(){var t=this.initialize(),e=t.smallValues,i=t.largeValues;try{for(var s=new Array(this._positionToMetaList.length),n=new Map,a=new Map,o=new Map,r=0;r<s.length;r++){var l=this._onTheFlyIndices[r]||this._positionToMetaList[r],h=this.getMetaIndex(l);if(!this.isThresholdMeta(l)&&l!=this.getIndexMeta(h))return this.shuffle();if(null!=l&&!this.isThresholdMeta(l)){var u={position:r,value:h};e.push(u),i.push(u),n.set(l,r),a.set(h,l),o.set(l,h),s[r]={meta:l,targetIndex:h,recyclerKey:this._name+"_"+r}}}return this._smallValues=e,this._largeValues=i,this._metaToPositionMap=n,this._positionToMetaList=s.map((function(t){return null==t?void 0:t.meta})),this.resetOnTheFlies(),this._indexToMetaMap=a,this.replaceMetaToIndexMap(o),s}catch(t){return console.log("err ",t),this._positionToMetaList}finally{this.readyToStartNextLoop()}},h._pushToHeaps=function(t,e){var i={position:t,value:e};this._smallValues.push(i),this._largeValues.push(i)},h._setMetaPosition=function(t,e){this._positionToMetaList[e]=t,this._metaToPositionMap.set(t,e)},h.commitPosition=function(t){var e=t.newIndex,i=t.safeRange,s=t.position,n=this._onTheFlyIndices[s],a=s;if(n){if(n===t.meta)return s;if(this._isOnTheFlyFull)return this.getFliedPosition(e,i);for(a=this._replaceFurthestIndexPosition(e,i);this._onTheFlyIndices[a];)a=this._replaceFurthestIndexPosition(e,i)}return a},h._setMetaIndex=function(t,e){var i=this.getMetaIndex(t);return void 0!==i&&this._indexToMetaMap.delete(i),this.setMetaIndex(t,e),this._indexToMetaMap.set(e,t),!1},h.readyToStartNextLoop=function(){this._lastUpdatedMS=Date.now()},h.prepare=function(){this._loopMS!==this._lastUpdatedMS&&(this._loopMS=this._lastUpdatedMS,this._onTheFlyIndices=[],this._isOnTheFlyFull=!1)},h._cleanHeaps=function(){for(var t=0;t<this._positionToMetaList.length;t++)if(null==this._positionToMetaList[t])return void this._recreateHeaps();var e=Math.min(this._smallValues.size(),this._largeValues.size());Math.max(this._smallValues.size(),this._largeValues.size())>10*e&&this._recreateHeaps()},h._recreateHeaps=function(){for(var t=this.initialize(),e=t.smallValues,i=t.largeValues,s=0;s<this._positionToMetaList.length;s++){var n=this._positionToMetaList[s],a=this.getMetaIndex(n);n&&-1!==a&&null!=a||(a=Number.MAX_SAFE_INTEGER-s);var r={position:s,value:a};e.push(r),i.push(r),a>o&&(this._setMetaPosition(a,s),this._setMetaIndex(a,a))}this._smallValues=e,this._largeValues=i},h._smallerComparator=function(t,e){return t.value<e.value},h._greaterComparator=function(t,e){return t.value>e.value},r=t,(l=[{key:"bufferSize",get:function(){return this._bufferSize}},{key:"isBufferFull",get:function(){return this._positionToMetaList.length>=this._bufferSize}}])&&function(t,e){for(var i=0;i<e.length;i++){var s=e[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,"symbol"==typeof(n=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var s=i.call(t,"string");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(s.key))?n:String(n),s)}var n}(r.prototype,l),Object.defineProperty(r,"prototype",{writable:!1}),t}(),exports.defaultBufferSize=10; | ||
//# sourceMappingURL=integer-buffer-set.cjs.production.min.js.map |
@@ -178,3 +178,3 @@ import Heap from '@x-oasis/heap'; | ||
position = this.getFliedPosition(newIndex, safeRange); | ||
} else if ((indexMeta = this._indexToMetaMap.get(newIndex)) && this._metaToPositionMap.get(indexMeta)) { | ||
} else if ((indexMeta = this._indexToMetaMap.get(newIndex)) && this._metaToPositionMap.get(indexMeta) != null) { | ||
position = this.commitPosition({ | ||
@@ -437,3 +437,2 @@ newIndex: newIndex, | ||
} | ||
this._largeValues.peek().value; | ||
this._smallValues = smallValues; | ||
@@ -440,0 +439,0 @@ this._largeValues = largeValues; |
{ | ||
"name": "@x-oasis/integer-buffer-set", | ||
"version": "0.1.26", | ||
"version": "0.1.27", | ||
"description": "IntegerBufferSet function", | ||
@@ -19,3 +19,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@x-oasis/heap": "0.1.26", | ||
"@x-oasis/heap": "0.1.27", | ||
"@x-oasis/invariant": "^0.1.19", | ||
@@ -22,0 +22,0 @@ "@x-oasis/is-clamped": "^0.1.19", |
@@ -256,3 +256,3 @@ import Heap from '@x-oasis/heap'; | ||
(indexMeta = this._indexToMetaMap.get(newIndex)) && | ||
this._metaToPositionMap.get(indexMeta) | ||
this._metaToPositionMap.get(indexMeta) != null | ||
) { | ||
@@ -636,3 +636,3 @@ /** | ||
this._largeValues.peek().value; | ||
// this._largeValues.peek().value; | ||
@@ -639,0 +639,0 @@ this._smallValues = smallValues; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
175451
1655
+ Added@x-oasis/heap@0.1.27(transitive)
- Removed@x-oasis/heap@0.1.26(transitive)
Updated@x-oasis/heap@0.1.27