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

array-go-brrr

v1.0.7

Published

Fast javascript array implementation

Downloads

19

Readme

array go brrr

Instant array operations

insert O(1)
remove O(1)
access O(1)
memory O(N)

Elegant API (Entire algorithms can be expressed in few lines of code)

// validate matching parens
Brrr.from('((()))()()(())()')
  .to((stack, paren) =>
    paren === '('
      ? stack.prepend(paren)
      : stack.first === '('
      ? stack.tail()
      : stack.append(paren)
  )
  .isEmpty()

Unoptimal array solutions are as efficient as optimal ones

Try it out at the playground

Structure

const array = new Brrr().insertLeft(-2, -1).insertRight(0, 1, 2, 3, 4);
{
  left: [ -1, -1, -2 ],
  right: [ 0, 1, 2, 3, 4 ]
}
array.items => [-2, -1, 0, 1, 2, 3, 4]

Indexing is guaranteed without the need of reordering thanks to simple arithmetics:

1_CJHj_FVbZ61iWSIevvMrsw

 -  [Symbol(-0), 3, 2, 1, 0] // left
 +  [4, 5, 6, 7, 8]          // right

[0] -> 0 - 4 = -4 => 0 // -
[1] -> 1 - 4 = -3 => 1 // -
[2] -> 2 - 4 = -2 => 2 // -
[3] -> 3 - 4 = -1 -> 3 // -
[4] -> 4 - 4 =  0 => 4 // +
[5] -> 5 - 4 =  1 => 5 // +
[6] -> 6 - 4 =  2 => 6 // +
[7] -> 7 - 4 =  3 => 7 // +
[8] -> 8 - 4 =  4 => 8 // +

[0, 1, 2, 3, 4, 5, 6, 7, 8]

Comparison for N = 200 000 (runned on MacBook Pro M1 chip laptop)

Benchmark

N = 200 000

brrrArray.get middle (once)
ok ~118 μs (0 s + 118333 ns)

regularArray.get middle (once)
ok ~54 μs (0 s + 54292 ns)

brrrArray.get random
ok ~7.49 ms (0 s + 7489583 ns)

regularArray.get random
ok ~7.45 ms (0 s + 7449834 ns)

brrrArray.push
ok ~7.96 ms (0 s + 7960417 ns)

regularArray.push
ok ~5.28 ms (0 s + 5283917 ns)

brrrArray.pop
ok ~8.93 ms (0 s + 8927333 ns)

regularArray.pop
ok ~2.15 ms (0 s + 2145750 ns)

brrrArray.shift 🚀
ok ~72 ms (0 s + 72263500 ns)

regularArray.shift 🐌
ok ~4.97 s (4 s + 973667083 ns)

brrrArray.unshift 🚀
ok ~5.53 ms (0 s + 5534333 ns)

regularArray.unshift 🐌
ok ~4.59 s (4 s + 588392875 ns)

all benchmarks completed
ok ~9.68 s (9 s + 679287250 ns)