Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unordered-set

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unordered-set

A couple of functions that make it easy to maintain an unordered set as an array in an efficient way

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.4K
decreased by-56.15%
Maintainers
1
Weekly downloads
 
Created
Source

unordered-set

A couple of functions that make it easy to maintain an unordered set as an array in an efficient way

npm install unordered-set

build status

Usage

var set = require('unordered-set')
var list = []

var a = {hello: 'world'}
var b = {hej: 'verden'}

set.add(list, a)
set.add(list, b)

console.log(list) // prints a and b

set.remove(list, a)

console.log(list) // prints b

Items are removed and added using the same technique as in unordered-array-remove making the removal/additions run in O(1).

API

set.add(list, item)

Add an item. Notes that this sets the property ._index to a number. If you control the items you insert and this is performance critical it might be benefitial to set item._index = 0 in the item constructor as v8 tends to like that.

set.remove(list, item)

Remove an item from the set. Might change the order of the list as well.

bool = set.has(list, item)

Returns true if the item is in the list and false otherwise

set.swap(list, a, b)

Swap the positions of two elements in the set

License

MIT

FAQs

Package last updated on 30 Jun 2016

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc