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

@data-structs/skip-list

v1.0.2

Published

A generalized self-balancing skip list implemented in Javascript. You can insert any value types you wish so long as you provide your own comparator function. The default comparator is `(a, b) => a - b` which only allows for numeric comparisons. As you mi

Downloads

74

Readme

@data-structs/skip-list

A generalized self-balancing skip list implemented in Javascript. You can insert any value types you wish so long as you provide your own comparator function. The default comparator is (a, b) => a - b which only allows for numeric comparisons. As you might guess, values are considered equal when the comparator function returns 0.

The algorithm for height-selection is more predictably balanced than a traditional coin-flip model while maintaining an element of randomness in selections. This is accomplished by randomly selecting levels where the expected number of elements is fewer than the actual number of elements in that level. The expected number of elements for a level is calculated using Math.floor((2**(-1 * level)) * n) which ensures each subsequent level has half as many elements as its predecessor, providing O(log n) insertions and searches with high probability.

Installation

yarn add @data-structs/skip-list

Usage

import skipList from '@data-structs/skip-list'

const mySkipList = skipList(
  Array.from(Array(16), () => Math.floor(Math.random() * (16 * 2)))
)

skipList.size        // 16
skipList.insert(196) // 17
skipList.has(196)    // true
skipList.remove(196) // 16
skipList.forEach(console.log)

Implementation details

[3] Sentinel ->                                                948
[2] Sentinel ->                    545 <>                      948
[1] Sentinel ->             302 <> 545 <>               926 <> 948 
[0]            32 <> 218 <> 302 <> 545 <> 840 <> 855 <> 926 <> 948
  • All levels are implemented using doubly-linked lists
  • O(1) insert at head + tail
    • Ultra-fast inserts when the inserted value is certainly less than or equal to the head or certainly greater than or equal to the tail
  • O(log(n)) insert at mid with high probability
  • O(1) remove at head + tail
    • Ultra-fast inserts when the removed value is certainly the head or certainly the tail
  • O(log(n)) remove at mid with high probability
  • O(log(n)) search with high probability
  • O(1) search bailout when value is certainly less than the head value or certainly greater than the tail value
  • O(n log(n)) space complexity