JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 15
  • Score
    100M100P100Q54501F
  • License MIT

A suite of circular data structures, including CircleStack, CircleQueue, and CircleDeque. Use circular buffers with ease and supported by a variety of operations.

Package Exports

  • circle-ds

Readme

Circle DS

A suite of circular data structures, including deques, lists, maps, queues, sets and stacks. Use circular buffers with ease.

Version Maintenance License codecov npm bundle size

Features

Install

Using npm:

npm install circle-ds

Using yarn:

yarn install circle-ds

API

Common

The following is common across all collections. See the Collection interface for more details.

Constructor

  • new (): Initialize an empty collection of infinite capacity.
  • new (capacity: number): Initialize an empty collection with the given capacity.

Properties

  • capacity: number: A positive integer that represents the maximum size of the collection. Can be updated to grow or shrink the collection. Can also be set to Infinity.

  • get size(): number: The number of items in the collection.

  • get [Symbol.toStringTag](): string: A string that represents the type of the object. See Symbol.toStringTag for more details.

Events

  • BoundedEvent.Overflow: Triggered when existing elements are discarded from the collection. This happens when the collection's capacity is reduced below its size or when new values are added while at capacity.

Methods

  • clear(): void: Remove all items from the collection.

  • entries(): IterableIterator<K, V>: Returns an iterator of [key/index, value] pairs through the collection.

  • forEach(callbackFn: (value: V, index: K, collection: Collection<K, V>) => void, thisArg?: unknown): void: Executes the provided callbackFn function once for each element.

  • keys(): IterableIterator<K>: Returns an iterator for the keys / indices in the collection.

  • values(): IterableIterator<V>: Returns an iterator for the values in the collection.

  • [Symbol.iterator](): IterableIterator: Returns an iterator for the values or key-value pairs in the collection.

CircularDeque & CircularLinkedDeque

CircularDeque is a double-ended queue that combines the features of stacks and queues, allowing insertion and removal at both ends.

Constructor

  • new <T>(items: Iterable<T>): Initialize a full deque with the given items.

Methods

CircularLinkedList & CircularDoublyLinkedList

CircularLinkedList is a list of elements allowing for indexed access, modification, and iteration.

Constructor

  • new <T>(items: Iterable<T>): Initialize a full list with the given items.

Methods

CircularMap

Constructor

  • new <K, V>(items: Iterable<[K, V]>): Initialize a full map with the given items. Capacity will be the number of unique keys given.

Methods

CircularQueue & CircularLinkedQueue

CircularQueue is a FIFO (First In, First Out) data structure with a fixed capacity.

Constructor

  • new <T>(items: Iterable<T>): Initialize a full queue with the given items.

Methods

CircularSet

Constructor

  • new <T>(items: Iterable<T>): Initialize a full set with the given items. Capacity will be the number of unique items given.

Methods

CircularStack & CircularLinkedStack

CircularStack is a LIFO (Last In, First Out) data structure with a fixed capacity.

Constructor

  • new <T>(items: Iterable<T>): Initialize a full stack with the given items.

Methods

Build

First clone the project from github:

git clone git@github.com:havelessbemore/circle-ds.git
cd circle-ds

Install the project dependencies:

npm install

Then, the project can be build by executing the build script via npm:

npm run build

This will build ESM and CommonJS outputs from the source files and put them in the dist/ folder.

Test

To execute tests for the library, install the project dependencies once:

npm install

Then, the tests can be executed:

npm test

You can separately run the code linter:

npm run lint

To automatically fix linting issue, run:

npm run format

To test code coverage of the tests:

npm run test:coverage

To see the coverage results, open the generated report in your browser:

./coverage/index.html

Made with ❤️ by Michael Rojas