You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

fast-unique-numbers

Package Overview
Dependencies
Maintainers
1
Versions
141
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-unique-numbers

A module to create a set of unique numbers as fast as possible.


Version published
Weekly downloads
224K
decreased by-4.21%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

fast-unique-numbers

A module to create a set of unique numbers as fast as possible.

version

This module is meant to create unique numbers within a given Map or Set. To achieve that as fast as possible the resulting set of numbers will only contain integers. Additionally only small integers will be used for as long as possible. Small integers can be stored more efficiently by JavaScript engines like SpiderMonkey or V8.

To verify the expected perfomance benefit an expectation test is used to make sure small integers do actually perform better in Chromium based browsers, Firefox and when using Node.js.

Usage

This module is available on npm and can be installed by running the following command:

npm install fast-unique-numbers

This module exports two functions.

addUniqueNumber()

This function takes a Set of numbers as argument and appends a new unique number to it. It also returns that number.

import { addUniqueNumber } from 'fast-unique-numbers';

const set = new Set([1, 4, 8]);
const uniqueNumber = addUniqueNumber(set);

console.log(uniqueNumber); // 3
console.log(set); // Set(4) { 1, 4, 8, 3 }

generateUniqueNumber()

This function can be used to generate a unique number which is not yet present in the given Set or is no key in the given Map. The resulting number gets not appended. It only gets returned.

import { generateUniqueNumber } from 'fast-unique-numbers';

const map = new Map([
    [1, 'something'],
    [4, 'something else']
]);

const uniqueNumber = generateUniqueNumber(map);

console.log(uniqueNumber); // 2

Keywords

FAQs

Package last updated on 08 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc