npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

circle-ds

v2.1.1

Published

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

Downloads

40

Readme

Circle DS

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

Version Maintenance License codecov npm bundle size

Circle-ds is a modern, flexible library offering a unique collection of circular data structures tailored for efficient data management and manipulation. These data structures behave dynamically but can be bounded to a given capacity, allowing for flexible data storage solutions.

Getting Started

Install

Using npm:

npm install circle-ds

Using yarn:

yarn add circle-ds

Usage

Here's an example using a circular queue, showcasing various capabilities:

import { CircularQueue } from "circle-ds";

// Create a queue with capacity 4
const queue = new CircularQueue(4);

// Listen for overflow
queue.on("overflow", discarded => console.log("Discarded:", discarded));

// Add incoming values
queue.push(1, 2, 3);
console.log(Array.from(queue.values())); // Output: [1, 2, 3]
queue.push(4, 5, 6); // Discards [1, 2]
console.log(Array.from(queue.values())); // Output: [3, 4, 5, 6]

// Resize queue
queue.capacity = 2; // Discards [3, 4]
console.log(Array.from(queue.values())); // Output: [5, 6]

// Remove bounds
queue.capacity = Infinity;
queue.push(7, 8, 9);
console.log(Array.from(queue.values())); // Output: [5, 6, 7, 8, 9]

Features

  • Capacity Management: Switch seamlessly between unbounded and bounded behaviors.
  • Efficient Data Management: Optimized for performance, even with large datasets.
  • Flexible and Reusable: Designed for ease of use in a wide variety of applications.

By default, data structures are unbounded, ensuring they can accommodate incoming data with the performance and behavior expected from standard implementations. When given a capacity, they become bounded containers, limiting their size to the predefined capacity. When necessary, older values are emitted to make room for the new, adhering to its circular nature.

This feature is useful for applications requiring fixed-size collections, such as caching mechanisms, real-time data processing, and streaming analytics, where the most recent data is prioritized, and older data is systematically discarded. With circle-ds, developers can seamlessly toggle between unbounded and bounded behaviors, offering flexibility in managing collection sizes and data lifecycles, while also preserving the expected functionality of classic data structures.

Compatibility

This library is compatible with modern JavaScript environments, including Node.js and browsers supporting ES6+.

Community and Support

We welcome contributions, feedback, and bug reports. Please feel free to submit an issue or a pull request.

For support, you can reach out via GitHub discussions.

API

Common API Elements

All circle-ds data structures share common API elements, outlined in the Collection interface. Here's a brief overview:

  • Capacity Control: Manage collection size with dynamic or fixed capacities.
  • Iterable Interface: Access keys, values, and entries directly using iterators.
  • Event-Driven: Listen to overflow events when capacity limits are reached.

Properties

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

  • 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. Event listeners should expect an array of discarded elements. Event listeners may be called multiple times per overflow.

Methods

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

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

  • 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 of the values in the collection. If the collection is a map, returns an iterator of [key, value] pairs.

Deque

Implementations

Constructor

  • new ()
  • new (capacity: number)
  • new (items: Iterable<T>)

Methods

  • first(): T | undefined

  • front(): T | undefined

  • has(value: T): boolean

  • last(): T | undefined

  • pop(): T | undefined

  • push(...items: T[]): number

  • shift(): T | undefined

  • top(): T | undefined

  • unshift(...items: T[]): number

List

Implementations

Constructor

  • new ()
  • new (capacity: number)
  • new (items: Iterable<T>)

Methods

  • at(index: number): V | undefined

  • delete(index: number): boolean

  • fill(value: V, start?: number, end?: number): this

  • has(value: T): boolean

  • pop(): T | undefined

  • push(...items: T[]): number

  • set(index: number, value: V): V | undefined

  • shift(): T | undefined

  • slice(start?: number, end?: number): CircularLinkedList<V>

  • splice(start: number, deleteCount?: number, ...items: V[]): CircularLinkedList<V>

  • unshift(...items: T[]): number

Map

Implementations

Constructor

  • new ()
  • new (capacity: number)
  • new (items: Iterable<[K, V]>)

Methods

  • delete(key: K): boolean

  • has(key: K): boolean

  • set(key: K, value: V): this

Queue

A Queue is a FIFO (First In, First Out) data structure.

Implementations

Constructor

  • new ()
  • new (capacity: number)
  • new (items: Iterable<T>)

Methods

  • first(): T | undefined

  • front(): T | undefined

  • has(value: T): boolean

  • push(...items: T[]): number

  • shift(): T | undefined

Set

Implementations

Constructor

  • new ()
  • new (capacity: number)
  • new (items: Iterable<T>)

Methods

  • add(value: T): this

  • delete(value: T): boolean

  • has(value: T): boolean

Stack

A Stack is a LIFO (Last In, First Out) data structure.

Implementations

Constructor

  • new ()
  • new (capacity: number)
  • new (items: Iterable<T>)

Methods

  • has(value: T): boolean

  • last(): T | undefined

  • pop(): T | undefined

  • push(...items: T[]): number

  • top(): T | undefined

Build

  1. Clone the project from github
git clone [email protected]:havelessbemore/circle-ds.git
cd circle-ds
  1. Install dependencies
npm install
  1. Build the project
npm run build

This will build ESM and CommonJS outputs in the dist/ folder.

Format

To run the code linter:

npm run lint

To automatically fix linting issue, run:

npm run format

Test

  1. Install dependencies
npm install
  1. Execute tests
npm test

Test coverage can be measured via:

npm run test:coverage

A coverage report is generated at ./coverage/index.html.


Made with ❤️ by Michael Rojas