# @algorithm.ts/circular-queue

> Circular queue in Typescript

Latest version **2.0.14** (published 2022-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @algorithm.ts/circular-queue
pnpm add @algorithm.ts/circular-queue
yarn add @algorithm.ts/circular-queue
bun add @algorithm.ts/circular-queue
```

## Health

**Score 45/100 (D)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.14 |
| Published | 2022-08-27 |
| First published | 2021-08-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 14.15.0 |
| Dependencies | 0 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 115 |
| Author | guanghechen |
| Maintainers | lemonclown |
| Keywords | queue, circular queue |

## Links

- npm: https://www.npmjs.com/package/@algorithm.ts/circular-queue
- Repository: https://github.com/guanghechen/algorithm.ts.git#release-2.x.x
- Homepage: https://github.com/guanghechen/algorithm.ts/tree/release-2.x.x/packages/circular-queue#readme
- Issues: https://github.com/guanghechen/algorithm.ts/issues
- npm.io page: https://npm.io/package/@algorithm.ts/circular-queue

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 2.0.14 (latest) — 2022-08-27
- 2.0.13 — 2022-06-26
- 2.0.12 — 2022-06-07
- 2.0.11 — 2022-04-19
- 2.0.10 — 2022-04-12
- 2.0.9 — 2022-04-10
- 2.0.8 — 2022-04-10
- 2.0.8-alpha.0 — 2022-04-05
- 2.0.7 — 2022-04-03
- 2.0.7-alpha.1 — 2022-04-03
- 2.0.7-alpha.0 — 2022-03-27
- 2.0.6 — 2022-03-26
- 2.0.5 — 2022-03-23
- 2.0.4 — 2022-03-20
- 2.0.3 — 2022-02-24
- … 22 more at https://npm.io/package/@algorithm.ts/circular-queue/versions

## README

<header>
  <h1 align="center">
    <a href="https://github.com/guanghechen/algorithm.ts/tree/release-2.x.x/packages/circular-queue#readme">@algorithm.ts/circular-queue</a>
  </h1>
  <div align="center">
    <a href="https://www.npmjs.com/package/@algorithm.ts/circular-queue">
      <img
        alt="Npm Version"
        src="https://img.shields.io/npm/v/@algorithm.ts/circular-queue.svg"
      />
    </a>
    <a href="https://www.npmjs.com/package/@algorithm.ts/circular-queue">
      <img
        alt="Npm Download"
        src="https://img.shields.io/npm/dm/@algorithm.ts/circular-queue.svg"
      />
    </a>
    <a href="https://www.npmjs.com/package/@algorithm.ts/circular-queue">
      <img
        alt="Npm License"
        src="https://img.shields.io/npm/l/@algorithm.ts/circular-queue.svg"
      />
    </a>
    <a href="#install">
      <img
        alt="Module Formats: cjs, esm"
        src="https://img.shields.io/badge/module_formats-cjs%2C%20esm-green.svg"
      />
    </a>
    <a href="https://github.com/nodejs/node">
      <img
        alt="Node.js Version"
        src="https://img.shields.io/node/v/@algorithm.ts/circular-queue"
      />
    </a>
    <a href="https://github.com/facebook/jest">
      <img
        alt="Tested with Jest"
        src="https://img.shields.io/badge/tested_with-jest-9c465e.svg"
      />
    </a>
    <a href="https://github.com/prettier/prettier">
      <img
        alt="Code Style: prettier"
        src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square"
      />
    </a>
  </div>
</header>
<br/>


A typescript implementation of the **Circular Queue** data structure.

Circular queue is a queue structure, the main purpose of its design is to
reuse space as much as possible on the basis of ordinary queues. Circular
queues usually need to specify the maximum volume C of the collector. If the
number of elements in the queue exceeds C, only the most recent C elements
are kept in the queue. Other operations are the same as ordinary queues.


## Install

* npm

  ```bash
  npm install --save @algorithm.ts/circular-queue
  ```

* yarn

  ```bash
  yarn add @algorithm.ts/circular-queue
  ```

* deno

  ```typescript
  import { createCircularQueue } from 'https://raw.githubusercontent.com/guanghechen/algorithm.ts/main/packages/circular-queue/src/index.ts'
  ```


## Usage

* Basic:

  ```typescript
  import { createCircularQueue } from '@algorithm.ts/circular-queue'

  const queue = createCircularQueue<{ name: string }>()

  // Initialize the circular-queue with the maximum number of elements it can
  // be managed.
  queue.init(100)

  // Append a element to the end of the queue.
  queue.enqueue({ name: 'alice' })  // => 0
  queue.enqueue({ name: 'bob' }) // => 1
  queue.size()   // => 2

  // Get the front element of the queue.
  queue.front()       // => { name: 'alice' }

  // Get the last element of the queue.
  queue.end()         // => { name: 'bob' }

  // Take off the first element of the queue.
  queue.dequeue()     // => { name: 'alice' }
  queue.size()        // => 1

  // Test if the queue is empty.
  queue.isEmpty()     // => false

  queue.get(0)        // undefined
  queue.get(0, true)  // undefined
  queue.get(0, false) // { name: 'alice' }

  queue.get(1)        // => { name: 'bob' }
  queue.get(1, true)  // => { name: 'bob' }
  queue.get(1, false) // => { name: 'bob' }
  ```


## Related


[homepage]: https://github.com/guanghechen/algorithm.ts/tree/release-2.x.x/packages/circular-queue#readme

---
_Source: https://npm.io/package/@algorithm.ts/circular-queue · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
