Socket
Socket
Sign inDemoInstall

fast-unique-numbers

Package Overview
Dependencies
Maintainers
1
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-unique-numbers - npm Package Compare versions

Comparing version 5.0.1 to 5.0.2

20

build/es2019/factories/generate-unique-number.js

@@ -6,2 +6,4 @@ /*

const MAX_SAFE_INTEGER = (Number.MAX_SAFE_INTEGER === undefined) ? 9007199254740991 : Number.MAX_SAFE_INTEGER;
const TWO_TO_THE_POWER_OF_TWENTY_NINE = 536870912;
const TWO_TO_THE_POWER_OF_THIRTY = TWO_TO_THE_POWER_OF_TWENTY_NINE * 2;
export const createGenerateUniqueNumber = (cache, lastNumberWeakMap) => {

@@ -18,7 +20,7 @@ return (collection) => {

*/
let nextNumber = (lastNumber === undefined) ?
collection.size :
(lastNumber > 2147483646) ?
0 :
lastNumber + 1;
let nextNumber = (lastNumber === undefined)
? collection.size
: (lastNumber < TWO_TO_THE_POWER_OF_THIRTY)
? lastNumber + 1
: 0;
if (!collection.has(nextNumber)) {

@@ -28,10 +30,10 @@ return cache(collection, nextNumber);

/*
* If there are less than half of 2 ** 31 numbers stored in the collection,
* the chance to generate a new random number in the range from 0 to 2 ** 31
* If there are less than half of 2 ** 30 numbers stored in the collection,
* the chance to generate a new random number in the range from 0 to 2 ** 30
* is at least 50%. It's benifitial to use only SMIs because they perform
* much better in any environment based on V8.
*/
if (collection.size < 1073741824) {
if (collection.size < TWO_TO_THE_POWER_OF_TWENTY_NINE) {
while (collection.has(nextNumber)) {
nextNumber = Math.floor(Math.random() * 2147483648);
nextNumber = Math.floor(Math.random() * TWO_TO_THE_POWER_OF_THIRTY);
}

@@ -38,0 +40,0 @@ return cache(collection, nextNumber);

@@ -27,2 +27,4 @@ (function (global, factory) {

var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER === undefined ? 9007199254740991 : Number.MAX_SAFE_INTEGER;
var TWO_TO_THE_POWER_OF_TWENTY_NINE = 536870912;
var TWO_TO_THE_POWER_OF_THIRTY = TWO_TO_THE_POWER_OF_TWENTY_NINE * 2;
var createGenerateUniqueNumber = function createGenerateUniqueNumber(cache, lastNumberWeakMap) {

@@ -40,3 +42,3 @@ return function (collection) {

var nextNumber = lastNumber === undefined ? collection.size : lastNumber > 2147483646 ? 0 : lastNumber + 1;
var nextNumber = lastNumber === undefined ? collection.size : lastNumber < TWO_TO_THE_POWER_OF_THIRTY ? lastNumber + 1 : 0;

@@ -47,4 +49,4 @@ if (!collection.has(nextNumber)) {

/*
* If there are less than half of 2 ** 31 numbers stored in the collection,
* the chance to generate a new random number in the range from 0 to 2 ** 31
* If there are less than half of 2 ** 30 numbers stored in the collection,
* the chance to generate a new random number in the range from 0 to 2 ** 30
* is at least 50%. It's benifitial to use only SMIs because they perform

@@ -55,5 +57,5 @@ * much better in any environment based on V8.

if (collection.size < 1073741824) {
if (collection.size < TWO_TO_THE_POWER_OF_TWENTY_NINE) {
while (collection.has(nextNumber)) {
nextNumber = Math.floor(Math.random() * 2147483648);
nextNumber = Math.floor(Math.random() * TWO_TO_THE_POWER_OF_THIRTY);
}

@@ -60,0 +62,0 @@

@@ -13,2 +13,4 @@ "use strict";

const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER === undefined ? 9007199254740991 : Number.MAX_SAFE_INTEGER;
const TWO_TO_THE_POWER_OF_TWENTY_NINE = 536870912;
const TWO_TO_THE_POWER_OF_THIRTY = TWO_TO_THE_POWER_OF_TWENTY_NINE * 2;

@@ -27,3 +29,3 @@ const createGenerateUniqueNumber = (cache, lastNumberWeakMap) => {

let nextNumber = lastNumber === undefined ? collection.size : lastNumber > 2147483646 ? 0 : lastNumber + 1;
let nextNumber = lastNumber === undefined ? collection.size : lastNumber < TWO_TO_THE_POWER_OF_THIRTY ? lastNumber + 1 : 0;

@@ -34,4 +36,4 @@ if (!collection.has(nextNumber)) {

/*
* If there are less than half of 2 ** 31 numbers stored in the collection,
* the chance to generate a new random number in the range from 0 to 2 ** 31
* If there are less than half of 2 ** 30 numbers stored in the collection,
* the chance to generate a new random number in the range from 0 to 2 ** 30
* is at least 50%. It's benifitial to use only SMIs because they perform

@@ -42,5 +44,5 @@ * much better in any environment based on V8.

if (collection.size < 1073741824) {
if (collection.size < TWO_TO_THE_POWER_OF_TWENTY_NINE) {
while (collection.has(nextNumber)) {
nextNumber = Math.floor(Math.random() * 2147483648);
nextNumber = Math.floor(Math.random() * TWO_TO_THE_POWER_OF_THIRTY);
}

@@ -47,0 +49,0 @@

@@ -14,11 +14,11 @@ {

"@babel/runtime": "^7.8.4",
"tslib": "^1.11.0"
"tslib": "^1.11.1"
},
"description": "A module to create a set of unique numbers as fast as possible.",
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/core": "^7.8.6",
"@babel/plugin-external-helpers": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/register": "^7.8.3",
"@babel/preset-env": "^7.8.6",
"@babel/register": "^7.8.6",
"@commitlint/cli": "^8.3.5",

@@ -49,4 +49,4 @@ "@commitlint/config-angular": "^8.3.4",

"load-grunt-config": "^3.0.1",
"mocha": "^7.0.1",
"rollup": "^1.31.1",
"mocha": "^7.1.0",
"rollup": "^1.32.0",
"rollup-plugin-babel": "^4.3.3",

@@ -58,4 +58,4 @@ "sinon": "^9.0.0",

"tslint": "^6.0.0",
"tslint-config-holy-grail": "^48.0.0",
"typescript": "^3.8.2",
"tslint-config-holy-grail": "^48.0.1",
"typescript": "^3.8.3",
"webpack": "^4.41.6"

@@ -96,3 +96,3 @@ },

"types": "build/es2019/module.d.ts",
"version": "5.0.1"
"version": "5.0.2"
}

@@ -8,2 +8,4 @@ import { TGenerateUniqueNumberFactory } from '../types';

const MAX_SAFE_INTEGER = (Number.MAX_SAFE_INTEGER === undefined) ? 9007199254740991 : Number.MAX_SAFE_INTEGER;
const TWO_TO_THE_POWER_OF_TWENTY_NINE = 536870912;
const TWO_TO_THE_POWER_OF_THIRTY = TWO_TO_THE_POWER_OF_TWENTY_NINE * 2;

@@ -22,7 +24,7 @@ export const createGenerateUniqueNumber: TGenerateUniqueNumberFactory = (cache, lastNumberWeakMap) => {

*/
let nextNumber = (lastNumber === undefined) ?
collection.size :
(lastNumber > 2147483646) ?
0 :
lastNumber + 1;
let nextNumber = (lastNumber === undefined)
? collection.size
: (lastNumber < TWO_TO_THE_POWER_OF_THIRTY)
? lastNumber + 1
: 0;

@@ -34,10 +36,10 @@ if (!collection.has(nextNumber)) {

/*
* If there are less than half of 2 ** 31 numbers stored in the collection,
* the chance to generate a new random number in the range from 0 to 2 ** 31
* If there are less than half of 2 ** 30 numbers stored in the collection,
* the chance to generate a new random number in the range from 0 to 2 ** 30
* is at least 50%. It's benifitial to use only SMIs because they perform
* much better in any environment based on V8.
*/
if (collection.size < 1073741824) {
if (collection.size < TWO_TO_THE_POWER_OF_TWENTY_NINE) {
while (collection.has(nextNumber)) {
nextNumber = Math.floor(Math.random() * 2147483648);
nextNumber = Math.floor(Math.random() * TWO_TO_THE_POWER_OF_THIRTY);
}

@@ -44,0 +46,0 @@

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