# unordered-set

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

Latest version **2.0.1** (published 2018-06-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install unordered-set
pnpm add unordered-set
yarn add unordered-set
bun add unordered-set
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2018-06-11 |
| First published | 2016-02-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 20 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/unordered-set
- Repository: https://github.com/mafintosh/unordered-set
- Issues: https://github.com/mafintosh/unordered-set/issues
- npm.io page: https://npm.io/package/unordered-set

## Recent versions

- 2.0.1 (latest) — 2018-06-11
- 2.0.0 — 2016-06-30
- 1.1.0 — 2016-02-08
- 1.0.1 — 2016-02-08
- 1.0.0 — 2016-02-08

## README

# 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](https://travis-ci.org/mafintosh/unordered-set.svg?branch=master)](https://travis-ci.org/mafintosh/unordered-set)

## Usage

``` js
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](https://github.com/mafintosh/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

---
_Source: https://npm.io/package/unordered-set · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
