All Projects → mafintosh → Value Sort

mafintosh / Value Sort

Licence: mit
Fast and iterable data structure for sorting bounded values

Programming Languages

javascript
184084 projects - #8 most used programming language

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].