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

@fgiova/sorted-array

v1.0.0

Published

permanent sorted array

Downloads

4

Readme

SortedArray

NPM version CI workflow TypeScript

Description

This simple module provides an array implementation, with a sorting feature using binary search algorithm.

Each time an element is inserted, it is placed in the correct position, so that the array is always sorted. The sorting is implemented using binary search algorithm, so the complexity is O(log n). All the elements are compared using the comparator function assigned on constructor or by default sort function. The array as implemented using a native array, so it is not a linked list. The array is mutable, but you cannot change the length of the array or remove elements except from the starting or ending array. Methods that change the sort order are not implemented; the array is always sorted according to the default order of the comparison function.

Installation

npm install @fgiova/sorted-array

Usage

import { SortedArray } from "@fgiova/sorted-array";

const array = new SortedArray<number>();

array.push(1, 3);
array.insert(2);

console.log(array); // [1, 2, 3]

Constructor

new SortedArray<T>(items?: T[] comparator?: (a: T, b: T) => number);

default comparator is:

function comparatorFunction(a, b) {
    if (a < b) return -1;
    if (a >= b) return 1;
    return 0;
}

Not implemented methods

  • splice
  • sort
  • reverse
  • copyWithin
  • fill

Benchmark

I have made a simple benchmark using Benchmark.js, comparing the performance of the push + sort methods of the native array and the insert method of this module. The benchmark is available in the benchmark folder. The results are the following:

| Function | | | |-------------------|----------------|-----------| | Simple Sort Array | 228 ops/sec | ±91.75% | | Sorted Array | 3,340 ops/sec | ±46.99% |