# fast-linked-list

> General purpose, but clean doubly Linked List implementation for the web.

Latest version **3.2.3** (published 2023-05-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install fast-linked-list
pnpm add fast-linked-list
yarn add fast-linked-list
bun add fast-linked-list
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.3 |
| Published | 2023-05-25 |
| First published | 2020-11-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 206 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maximilian Mairinger |
| Maintainers | zzrv |
| Keywords | fast, linked, list, double, doubly, o(1), remove, es6, es2015, typescript, ts |

## Links

- npm: https://www.npmjs.com/package/fast-linked-list
- Repository: https://github.com/maximilianMairinger/fastLinkedList
- Homepage: https://github.com/maximilianMairinger/fastLinkedList#readme
- Issues: https://github.com/maximilianMairinger/fastLinkedList/issues
- npm.io page: https://npm.io/package/fast-linked-list

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 3.2.3 (latest) — 2023-05-25
- 3.2.2 — 2023-05-25
- 3.2.1 — 2023-05-08
- 3.2.0 — 2022-11-21
- 3.1.2 — 2022-11-20
- 3.1.1 — 2022-01-30
- 3.1.0 — 2022-01-30
- 3.0.4 — 2021-12-12
- 3.0.3 — 2021-12-12
- 3.0.2 — 2021-12-12
- 3.0.1 — 2021-12-04
- 3.0.0 — 2021-12-04
- 2.0.1 — 2021-12-02
- 2.0.0 — 2021-12-02
- 1.0.5 — 2021-11-04
- … 6 more at https://npm.io/package/fast-linked-list/versions

## README

# Fast linked list

General purpose, but clean doubly Linked List implementation for the web ([3.4kB](https://bundlephobia.com/package/fast-linked-list)), performing decently well in benchmarks.

> Please note that the length of the list is intentionally (by default) not being computed. `Token#remove()` has no way of mutating the length of the list, as it does not have a reference to it's parent list, only it's siblings. If you need this, use the `LengthLinkedList` export, that functions analog, but provides a length attribute. This is a tradeoff between performance and functionality.

## Installation

```shell
 $ npm i fast-linked-list
```

## Usage

For simple usage, the Token architecture is abstracted away.

```ts
import LinkedList from "fast-linked-list"

const ls = new LinkedList("b", "c")
const dElem = ls.push("a")
ls.toArray() // ["b", "c", "a"]

dElem.remove() // true (meaning successfully removed)
dElem.remove() // false

const dElem2 = ls.unshift(dElem.value)

for (const elem of ls) {
  console.log(elem) // "a", "b", "c"
}

ls.reverse()

const addedElems = ls.pushBulk(["x", "y", "z"])
ls.toArray() // ["c", "b", "a", "x", "y", "z"]

addedElems[1].remove()
ls.toArray() // ["c", "b", "a", "x", "z"]

ls.pop() // "z"
ls.shift() // "c"
ls.first // "b"
ls.last // "x"

ls.reverse().forEach((e) => {
  console.log(e) // "x", "a", "b"
})

const clone = new LinkedList(ls)
ls.clear()
```

Note that `reverse()` does not mutate the list, but only inverts all basic i/o functions of the list. E.g.: `push()` becomes `unshift()` and `first` becomes `last`. Hence the `reverse()` call performs with a time complexity of O(1).

### Working with Tokens

A Token can only exsist within one LinkedList. Appending it somewhere else will remove it from the current list.

```ts
import LinkedList, { Token } from "fast-linked-list"

const ls1 = new LinkedList("ls", "1")
const ls2 = new LinkedList("ls", "2")
const token = new Token("added")

ls1.pushToken(token); ls1.toArray() // ["ls", "1", "added"]
ls2.pushToken(token); ls2.toArray() // ["ls", "2", "added"]
ls1.toArray() // ["ls", "1"]


token.insertBefore("before")
ls2.toArray() // ["ls", "1", "before", "added"] 


// Search for a value whose Token is unknown and remove it. Preferably keep a reference to the token if you plan to remove it (as this is O(n)).
ls2.forEach((val, tok) => {
  if (val === "ls") tok.remove()
})
```

## Contribute

All feedback is appreciated. Create a pull request or write an issue.

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