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

priority-deque

v1.1.0

Published

A double-ended priority queue based on min-max heaps.

Downloads

12

Readme

priority-deque

This package implements a double-ended priority queue, or priority deque, with optional size limits, based on an underlying min-max heap structure. This data structure provides efficient Insert, FindMin, FindMax, DeleteMin, and DeleteMax operations. The package has a single non-default export { PriorityDeque }.

API

  • new PriorityDeque<T>(opts?: { compare?: (a: T, b: T) => number, limit?: number, items?: Iterable<T> }) Constructs a new PriorityDeque. By default, there are no size limits, numbers will be compared numerically, and all other objects will be compared by converting to strings and calling String.localeCompare(). If a finite non-negative limit is provided, the deque will automatically prune maximal elements to keep the total size of the structure less than or equal to limit.
  • clone(): PriorityDeque<T> Creates a shallow copy of the deque with the same size limits and comparison function in O(n) time.
  • set(elements: Iterable<T>) Replaces the contents of the deque with the smallest members, up to the size limit, of a new element set.
  • append(elements: T[]) Adds new elements to the deque.
  • clear() Empties the deque.

Array-Like Methods

  • [Symbol.iterator](): IterableIterator<T> Returns an iterator over all of the currently-stored values in the deque, suitable for use with for(... of ...) loops. No particular iteration order is guaranteed.
  • readonly length: number Indicates how many total items are currently stored in the deque.
  • push(...elements: T[]) Adds new elements to the deque.
  • pop(): T | undefined Removes and returns the minimum element from the deque, or undefined if length is zero.
  • shift(): T | undefined Removes and returns the maximum element from the deque, or undefined if lengt is zero.
  • unshift(...elements: T[]) Synonym for push().
  • map<U>(fn: (e: T) => U, compare?: (a: U, b: U) => number): PriorityDeque<U> Creates a new PriorityDeque with the same limits as the current one by applying a mapping function to each element of the current deque. If an explicit comparison function is not provided for the new deque, the default numeric / string comparator will be used.
  • filter(fn: (e: T) => boolean): PriorityDeque<T> Creates a new PriorityDeque with the same limits and comparison function as the current one but containing only a subset of the current deque's elements which satisfy the provided filtering predicate.
  • collect<U>(fn: (e: T) => Iterable<U>, compare?: (a: U, b: U) => number): PriorityDeque<U> Creates a new PriorityDeque with the same limits as the current one by applying a collection function return 0 or more mapped elements to each element of the current deque. This is more efficient than calling filter() and map() in sequence. If an explicit comparison function is not provided for the new deque, the default numeric / string comparator will be used.
  • contains(e: T): boolean Determines whether or not the deque contains a specific element, via === comparison.
  • some(fn: (e: T) => boolean): boolean Determines whether or not any element of the deque satisfies the given predicate.
  • every(fn: (e: T) => boolean): boolean Determines whether or not all elements of the deque satisfy the given predicate.
  • find(fn: (e: T) => boolean): T | undefined Returns an element of the deque which satisfies the given predicate, or undefined if there is no such element.
  • forEach(fn: (e: T) => void) Executes the given callback function once for each element of the deque; no specific ordering is guaranteed.

Heap-Specific Methods

  • findMin(): T | undefined Returns the minimum element of the deque, or undefined if length is zero.
  • findMax(): T | undefined Returns the maximum element of the deque, or undefined if length is zero.
  • replaceMin(e: T): T | undefined Removes and returns the minimum element of the deque, or undefined if length is zero, and inserts the new element e. This is more efficient than calling pop() and push(e) separately.
  • replaceMax(e: T): T | undefined Removes and returns the maximum element of the deque, or undefined if length is zero, and inserts the new element e. This is more efficient than calling shift() and push(e) separately.
  • remove(e: T): boolean Removes the element e from the deque and returns true if e is in the deque; returns false otherwise.
  • replace(a: T, b: T): boolean Removes the element a from the deque, inserts the element b, and returns true if a is in the deque. If a is not in the deque, b is not inserted, and false is returned. This is more efficient than calling remove(a) and push(b) separately.