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

placespace

v1.0.3

Published

Multi-level spatial scheduling algorithm.

Downloads

3

Readme

placespace

Multi-level spatial scheduling algorithm.

Scene

SQL Database

  • a order list and have a field for order.
  • list supports inserting a or more element to any position.
  • list supports removing a or more element to any position.
  • list supports changing position of any one element exist to any position.
  • support pagination.

Idea

Because of pagination, we can't adopt linked list. So we need adopt order index.

If we adopt self-increasing order index when we insert element and change position of element it will always trigger full adjustment(reset order index of all elements). It is inefficient.

We leave some space between two neighber elements for inserting. For example, we set the order field of first element to 2**6(0~2**16 also should be blank space), the second is 2**6*2 and so on.

But because of Scene 2, inserting variable number of elements will have a high probability to trigger full adjustment. So we need do something else. We set the blank space in multi-level. These levels distinguish with amount of element. For example, we set the order field of first element to 2**6, the second is 2**6*2. This is the frist level for expandation. But the No.2**6+1 is 2**6*2**6*2+2**6 not 2**6*2**6+2**6. Where is the difference? After the No.2**6, we set the blank space with length of 2**6*2**6. This space is set for expandation of the previous 2**6 elements. This is the second level. And so on. There will be third, forth, fifith,...level with different size space for expandation.

Action abstract

  1. add new elements to any position

    input: new elements, order index of previous element, order index of next element

    output: order indexs of new elements, if need full adjustment, range of full adjustment

  2. remove elements

    Don't need calculate

  3. move one element to any position

    like add new elements

Add new elements to any position

input: new elements, order index of previous element, order index of next element

  1. calculate the space of this position(level 1), judge whether there are enough space to place new elements
  2. if there are enough space goto 3 else goto 4
  3. calculate the order index of new elements with maximal sparsity
  4. calculate the space of higher leveljudge whether there are enough space to place new elements and exist elements
  5. if there are enough space goto 6 else goto 4
  6. calculate the order index of new elements and exist elements with maximal sparsity

something else we need: the range(spaces) of current level, the amount of exist elements of current level, the range of next level

Programmatic

Variables:

  • ic: the amount of new elements
  • ir: the initial range
  • l: level
  • c: the amount of elements
  • r: the range of current level

Pseudocode:

// ic = xxx
// ir = xxx

r = ir
c = ic
l = 0

while() {
  if (r > c) {
    // higher level
    l += 1
    // get range of next/higher level
    r = getNextLevelRange(r, l)
    // get amount of exist elements of next/higher level
    c = getNextLevelAmount(l) + ic
  } else {
    // success
    calculateOrderIndex(r, ir, c)
    break
  }
}

TODO

  • expand forward