🚀 Launch Week Day 5:Introducing Immutable Scans.Learn More →
Socket
Book a DemoInstallSign in
Socket

value-sort

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

value-sort

Fast and iterable data structure for sorting bounded values

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

value-sort

Fast and iterable data structure for sorting bounded values

npm install value-sort

Uses a fixed size array to store values and a indexed-bitfield to iterate them.

Usage

const valueSort = require('value-sort')

// all values are between [0, 65536[
const vs = valueSort(65536)

vs.add(55)
vs.add(1004)
vs.add(0)
vs.add(9999)
vs.add(66)

// the valueSort instance if iterable
for (const v of vs) {
  console.log(v)
}

Running the above prints

0
55
66
1004
9999

If you want the values as a sorted array instead use

const arr = vs.toArray()

If you pass an object as the 2nd arg to add that object will show up in the iteration instead of the value

// the object on the right is returned instead of 42 on iteration
vs.add(42, {index: 42, hello: 'world'})

License

MIT

FAQs

Package last updated on 14 Aug 2018

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