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

fast-list

v1.0.3

Published

A fast linked list (good for queues, stacks, etc.)

Downloads

71,005

Readme

The Problem

You've got some thing where you need to push a bunch of stuff into a queue and then shift it out. Or, maybe, you need to pop it out stack-like, but it's not clear at the outset which way it's going to go.

Arrays work for this, but are a bit costly performance-wise in the mixed case. In the pure-stack case (or, as of recent V8 versions, the pure-queue case as well), Arrays are best.

In cases where it's mixed, a linked list implementation can be significantly faster. See the benchmark scripts in bench/*.js to measure the differences.

This lacks a lot of features that arrays have:

  1. You can't specify the size at the outset.
  2. It's not indexable.
  3. There's no join, concat, etc.

If any of this matters for your use case, you're probably better off using an Array object.

If you know that you'll be using it as a stack or a queue exclusively, then you're better off using an Array object.

If you know the eventual size at the offset, then you're definitely better off using an Array.

Installing

npm install fast-list

API

var FastList = require("fast-list")
var list = new FastList()
list.push("foo")
list.unshift("bar")
list.push("baz")
console.log(list.length) // 2
console.log(list.pop()) // baz
console.log(list.shift()) // bar
console.log(list.shift()) // foo

Methods

  • push: Just like Array.push, but only can take a single entry
  • pop: Just like Array.pop. Note: if you're only using push and pop, then you have a stack, and Arrays are better for that.
  • shift: Just like Array.shift. Note: if you're only using push and shift, then you have a queue, and Arrays are better for that.
  • unshift: Just like Array.unshift, but only can take a single entry.
  • drop: Drop all entries
  • item(n): Retrieve the nth item in the list. This involves a walk every time. It's very slow. If you find yourself using this, consider using a normal Array instead.
  • map(fn, thisp): Like Array.prototype.map. Returns a new FastList.
  • reduce(fn, startValue, thisp): Like Array.prototype.reduce
  • forEach(fn, this): Like Array.prototype.forEach
  • filter(fn, thisp): Like Array.prototype.filter. Returns a new FastList.
  • slice(start, end): Retrieve an array of the items at this position. This involves a walk every time. It's very slow. If you find yourself using this, consider using a normal Array instead.

Members

  • length: The number of things in the list. Note that, unlike Array.length, this is not a getter/setter, but rather a counter that is internally managed. Setting it can only cause harm.