New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@x-oasis/integer-buffer-set

Package Overview
Dependencies
Maintainers
3
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@x-oasis/integer-buffer-set - npm Package Compare versions

Comparing version 0.1.12 to 0.1.13

12

dist/index.d.ts

@@ -18,3 +18,13 @@ import Heap from '@x-oasis/heap';

getMaxValue(): number;
replaceFurthestValuePosition(lowValue: number, highValue: number, newValue: number): null | number;
replaceFurthestValuePosition(lowValue: number, highValue: number, newValue: number, useMinValueFn?: (options: {
safeRange: {
lowValue: number;
highValue: number;
};
bufferSetRange: {
maxValue: number;
minValue: number;
};
currentIndex: number;
}) => boolean): null | number;
_pushToHeaps(position: number, value: number): void;

@@ -21,0 +31,0 @@ _cleanHeaps(): void;

@@ -41,2 +41,11 @@ 'use strict';

var defaultUseMinValueFn = function defaultUseMinValueFn(options) {
var safeRange = options.safeRange,
bufferSetRange = options.bufferSetRange;
var lowValue = safeRange.lowValue,
highValue = safeRange.highValue;
var maxValue = bufferSetRange.maxValue,
minValue = bufferSetRange.minValue;
return lowValue - minValue > maxValue - highValue;
};
var IntegerBufferSet = /*#__PURE__*/function () {

@@ -81,3 +90,6 @@ function IntegerBufferSet() {

};
_proto.replaceFurthestValuePosition = function replaceFurthestValuePosition(lowValue, highValue, newValue) {
_proto.replaceFurthestValuePosition = function replaceFurthestValuePosition(lowValue, highValue, newValue, useMinValueFn) {
if (useMinValueFn === void 0) {
useMinValueFn = defaultUseMinValueFn;
}
if (this._valueToPositionMap[newValue] !== undefined) {

@@ -96,3 +108,13 @@ console.warn("Shouldn't try to replace values with value already stored value in " + 'BufferSet');

var valueToReplace;
if (lowValue - minValue > maxValue - highValue) {
if (useMinValueFn({
safeRange: {
lowValue: lowValue,
highValue: highValue
},
bufferSetRange: {
minValue: minValue,
maxValue: maxValue
},
currentIndex: newValue
})) {
valueToReplace = minValue;

@@ -99,0 +121,0 @@ this._smallValues.pop();

2

dist/integer-buffer-set.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("@x-oasis/heap"))&&"object"==typeof e&&"default"in e?e.default:e;exports.default=function(){function e(){this._valueToPositionMap={},this._size=0,this._smallValues=new t([],this._smallerComparator),this._largeValues=new t([],this._greaterComparator),this.getNewPositionForValue=this.getNewPositionForValue.bind(this),this.getValuePosition=this.getValuePosition.bind(this),this.getSize=this.getSize.bind(this),this.replaceFurthestValuePosition=this.replaceFurthestValuePosition.bind(this)}var i,a,s=e.prototype;return s.getSize=function(){return this._size},s.getValuePosition=function(e){return void 0===this._valueToPositionMap[e]?null:this._valueToPositionMap[e]},s.getNewPositionForValue=function(e){void 0!==this._valueToPositionMap[e]&&console.warn("Shouldn't try to find new position for value already stored in BufferSet");var t=this._size;return this._size++,this._pushToHeaps(t,e),this._valueToPositionMap[e]=t,t},s.getMinValue=function(){var e;return null==(e=this._smallValues.peek())?void 0:e.value},s.getMaxValue=function(){var e;return null==(e=this._largeValues.peek())?void 0:e.value},s.replaceFurthestValuePosition=function(e,t,i){if(void 0!==this._valueToPositionMap[i]&&console.warn("Shouldn't try to replace values with value already stored value in BufferSet"),this._cleanHeaps(),this._smallValues.empty()||this._largeValues.empty())return null;var a,s=this._smallValues.peek().value,l=this._largeValues.peek().value;if(s>=e&&l<=t)return null;e-s>l-t?(a=s,this._smallValues.pop()):(a=l,this._largeValues.pop());var o=this._valueToPositionMap[a];return delete this._valueToPositionMap[a],this._valueToPositionMap[i]=o,this._pushToHeaps(o,i),o},s._pushToHeaps=function(e,t){var i={position:e,value:t};this._smallValues.push(i),this._largeValues.push(i)},s._cleanHeaps=function(){this._cleanHeap(this._smallValues),this._cleanHeap(this._largeValues);var e=Math.min(this._smallValues.size(),this._largeValues.size());Math.max(this._smallValues.size(),this._largeValues.size())>10*e&&this._recreateHeaps()},s._recreateHeaps=function(){for(var e=this._smallValues.size()<this._largeValues.size()?this._smallValues:this._largeValues,i=new t([],this._smallerComparator),a=new t([],this._greaterComparator);!e.empty();){var s=e.pop();void 0!==this._valueToPositionMap[s.value]&&(i.push(s),a.push(s))}this._smallValues=i,this._largeValues=a},s._cleanHeap=function(e){for(;!e.empty()&&void 0===this._valueToPositionMap[e.peek().value];)e.pop()},s._smallerComparator=function(e,t){return e.value<t.value},s._greaterComparator=function(e,t){return e.value>t.value},i=e,(a=[{key:"indices",get:function(){var e=[];for(var t in this._valueToPositionMap)e[this._valueToPositionMap[t]]=t;return e}}])&&function(e,t){for(var i=0;i<t.length;i++){var a=t[i];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,"symbol"==typeof(s=function(e,t){if("object"!=typeof e||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var a=i.call(e,"string");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(a.key))?s:String(s),a)}var s}(i.prototype,a),Object.defineProperty(i,"prototype",{writable:!1}),e}();
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("@x-oasis/heap"))&&"object"==typeof e&&"default"in e?e.default:e,a=function(e){var t=e.safeRange,a=e.bufferSetRange;return t.lowValue-a.minValue>a.maxValue-t.highValue};exports.default=function(){function e(){this._valueToPositionMap={},this._size=0,this._smallValues=new t([],this._smallerComparator),this._largeValues=new t([],this._greaterComparator),this.getNewPositionForValue=this.getNewPositionForValue.bind(this),this.getValuePosition=this.getValuePosition.bind(this),this.getSize=this.getSize.bind(this),this.replaceFurthestValuePosition=this.replaceFurthestValuePosition.bind(this)}var i,s,l=e.prototype;return l.getSize=function(){return this._size},l.getValuePosition=function(e){return void 0===this._valueToPositionMap[e]?null:this._valueToPositionMap[e]},l.getNewPositionForValue=function(e){void 0!==this._valueToPositionMap[e]&&console.warn("Shouldn't try to find new position for value already stored in BufferSet");var t=this._size;return this._size++,this._pushToHeaps(t,e),this._valueToPositionMap[e]=t,t},l.getMinValue=function(){var e;return null==(e=this._smallValues.peek())?void 0:e.value},l.getMaxValue=function(){var e;return null==(e=this._largeValues.peek())?void 0:e.value},l.replaceFurthestValuePosition=function(e,t,i,s){if(void 0===s&&(s=a),void 0!==this._valueToPositionMap[i]&&console.warn("Shouldn't try to replace values with value already stored value in BufferSet"),this._cleanHeaps(),this._smallValues.empty()||this._largeValues.empty())return null;var l,o=this._smallValues.peek().value,r=this._largeValues.peek().value;if(o>=e&&r<=t)return null;s({safeRange:{lowValue:e,highValue:t},bufferSetRange:{minValue:o,maxValue:r},currentIndex:i})?(l=o,this._smallValues.pop()):(l=r,this._largeValues.pop());var u=this._valueToPositionMap[l];return delete this._valueToPositionMap[l],this._valueToPositionMap[i]=u,this._pushToHeaps(u,i),u},l._pushToHeaps=function(e,t){var a={position:e,value:t};this._smallValues.push(a),this._largeValues.push(a)},l._cleanHeaps=function(){this._cleanHeap(this._smallValues),this._cleanHeap(this._largeValues);var e=Math.min(this._smallValues.size(),this._largeValues.size());Math.max(this._smallValues.size(),this._largeValues.size())>10*e&&this._recreateHeaps()},l._recreateHeaps=function(){for(var e=this._smallValues.size()<this._largeValues.size()?this._smallValues:this._largeValues,a=new t([],this._smallerComparator),i=new t([],this._greaterComparator);!e.empty();){var s=e.pop();void 0!==this._valueToPositionMap[s.value]&&(a.push(s),i.push(s))}this._smallValues=a,this._largeValues=i},l._cleanHeap=function(e){for(;!e.empty()&&void 0===this._valueToPositionMap[e.peek().value];)e.pop()},l._smallerComparator=function(e,t){return e.value<t.value},l._greaterComparator=function(e,t){return e.value>t.value},i=e,(s=[{key:"indices",get:function(){var e=[];for(var t in this._valueToPositionMap)e[this._valueToPositionMap[t]]=t;return e}}])&&function(e,t){for(var a=0;a<t.length;a++){var i=t[a];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,"symbol"==typeof(s=function(e,t){if("object"!=typeof e||null===e)return e;var a=e[Symbol.toPrimitive];if(void 0!==a){var i=a.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(i.key))?s:String(s),i)}var s}(i.prototype,s),Object.defineProperty(i,"prototype",{writable:!1}),e}();
//# sourceMappingURL=integer-buffer-set.cjs.production.min.js.map

@@ -35,2 +35,11 @@ import Heap from '@x-oasis/heap';

var defaultUseMinValueFn = function defaultUseMinValueFn(options) {
var safeRange = options.safeRange,
bufferSetRange = options.bufferSetRange;
var lowValue = safeRange.lowValue,
highValue = safeRange.highValue;
var maxValue = bufferSetRange.maxValue,
minValue = bufferSetRange.minValue;
return lowValue - minValue > maxValue - highValue;
};
var IntegerBufferSet = /*#__PURE__*/function () {

@@ -75,3 +84,6 @@ function IntegerBufferSet() {

};
_proto.replaceFurthestValuePosition = function replaceFurthestValuePosition(lowValue, highValue, newValue) {
_proto.replaceFurthestValuePosition = function replaceFurthestValuePosition(lowValue, highValue, newValue, useMinValueFn) {
if (useMinValueFn === void 0) {
useMinValueFn = defaultUseMinValueFn;
}
if (this._valueToPositionMap[newValue] !== undefined) {

@@ -90,3 +102,13 @@ console.warn("Shouldn't try to replace values with value already stored value in " + 'BufferSet');

var valueToReplace;
if (lowValue - minValue > maxValue - highValue) {
if (useMinValueFn({
safeRange: {
lowValue: lowValue,
highValue: highValue
},
bufferSetRange: {
minValue: minValue,
maxValue: maxValue
},
currentIndex: newValue
})) {
valueToReplace = minValue;

@@ -93,0 +115,0 @@ this._smallValues.pop();

{
"name": "@x-oasis/integer-buffer-set",
"version": "0.1.12",
"version": "0.1.13",
"description": "IntegerBufferSet function",

@@ -19,3 +19,3 @@ "main": "dist/index.js",

"dependencies": {
"@x-oasis/heap": "0.1.12"
"@x-oasis/heap": "0.1.13"
},

@@ -22,0 +22,0 @@ "scripts": {

@@ -9,2 +9,19 @@ // import invariant from 'invariant';

const defaultUseMinValueFn = (options: {
safeRange: {
lowValue: number;
highValue: number;
};
bufferSetRange: {
maxValue: number;
minValue: number;
};
currentIndex: number;
}) => {
const { safeRange, bufferSetRange } = options;
const { lowValue, highValue } = safeRange;
const { maxValue, minValue } = bufferSetRange;
return lowValue - minValue > maxValue - highValue;
};
// Data structure that allows to store values and assign positions to them

@@ -90,3 +107,14 @@ // in a way to minimize changing positions of stored values when new ones are

highValue: number,
newValue: number
newValue: number,
useMinValueFn: (options: {
safeRange: {
lowValue: number;
highValue: number;
};
bufferSetRange: {
maxValue: number;
minValue: number;
};
currentIndex: number;
}) => boolean = defaultUseMinValueFn
): null | number {

@@ -120,3 +148,16 @@ if (this._valueToPositionMap[newValue] !== undefined) {

let valueToReplace;
if (lowValue - minValue > maxValue - highValue) {
if (
useMinValueFn({
safeRange: {
lowValue,
highValue,
},
bufferSetRange: {
minValue,
maxValue,
},
currentIndex: newValue,
})
) {
// if (lowValue - minValue > maxValue - highValue) {
// minValue is further from provided range. We will reuse it's position.

@@ -123,0 +164,0 @@ valueToReplace = minValue;

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc