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

@omts/heap

v0.0.1

Published

A lightweight TypeScript package that provides implementations of **MaxHeap** and **MinHeap** data structures. These heaps allow you to efficiently manage and retrieve the largest or smallest element in a dynamic dataset.

Downloads

2

Readme

@omts/heap 🚀

A lightweight TypeScript package that provides implementations of MaxHeap and MinHeap data structures. These heaps allow you to efficiently manage and retrieve the largest or smallest element in a dynamic dataset.

Installation 📦

You can install the package via npm or pnpm:

npm install @omts/heap

or

pnpm add @omts/heap

Usage ✨

This package exports two main classes: MaxHeap and MinHeap. Each heap supports common heap operations such as insertion, extraction of the maximum or minimum value, and peeking at the top value.

MaxHeap Example

The MaxHeap ensures that the largest value is always at the top of the heap.

import { MaxHeap } from '@omts/heap';

// Create a new MaxHeap
const maxHeap = new MaxHeap();

// Insert elements into the heap
maxHeap.insert(10);
maxHeap.insert(15);
maxHeap.insert(20);

// Peek at the maximum element
console.log(maxHeap.peek()); // Output: 20

// Extract the maximum element
console.log(maxHeap.extractMax()); // Output: 20
console.log(maxHeap.extractMax()); // Output: 15

// Check the size of the heap
console.log(maxHeap.size()); // Output: 1

MinHeap Example

The MinHeap ensures that the smallest value is always at the top of the heap.

import { MinHeap } from '@omts/heap';

// Create a new MinHeap
const minHeap = new MinHeap();

// Insert elements into the heap
minHeap.insert(10);
minHeap.insert(5);
minHeap.insert(8);

// Peek at the minimum element
console.log(minHeap.peek()); // Output: 5

// Extract the minimum element
console.log(minHeap.extractMin()); // Output: 5
console.log(minHeap.extractMin()); // Output: 8

// Check the size of the heap
console.log(minHeap.size()); // Output: 1

API Documentation 📚

MaxHeap

  • insert(value: number): void: Inserts a value into the heap while maintaining the max-heap property.
  • extractMax(): number | null: Removes and returns the maximum value from the heap.
  • peek(): number | undefined: Returns the maximum value without removing it.
  • size(): number: Returns the number of elements in the heap.

MinHeap

  • insert(value: number): void: Inserts a value into the heap while maintaining the min-heap property.
  • extractMin(): number | null: Removes and returns the minimum value from the heap.
  • peek(): number | undefined: Returns the minimum value without removing it.
  • size(): number: Returns the number of elements in the heap.

Complexity 📊

  • Time Complexity:
    • Insertion: O(log n)
    • Extraction: O(log n)
    • Peek: O(1)
  • Space Complexity: O(n), where n is the number of elements in the heap.

Development 🛠️

Commands

Development 🛠️

To develop this package, we use Bun as the runtime environment. The following scripts are available to streamline the development and build process.

Available Commands

  • clean: Cleans the dist directory to prepare for a fresh build.

    bun run clean
  • build: Cleans and builds the package by running a build script located in ../../scripts/build-all.js.

    bun run build
  • test: Runs all test cases using the Bun test runner.

    bun run test
  • tdd: Runs the tests in watch mode for Test-Driven Development (TDD).

    bun run tdd
  • prepublishOnly: Automatically runs the build command before publishing the package to ensure everything is up to date.

    bun run prepublishOnly

These commands help ensure that your development workflow remains efficient and that all necessary steps are executed properly before publishing the package.

Contributing 🤝

Contributions are welcome! If you have any improvements or suggestions, feel free to open an issue or submit a pull request.

License ⚖️

This project is licensed under the MIT License - see the LICENSE file for details.


Happy sorting with @omts/heap! 🎉