An unreliable and overall unusable sorting library for numbers with a global cache on the edge.

Overview

unsort

unsort

An unreliable and overall unusable sorting library for numbers with a global cache on the edge.

the algorithm

This library implements a number sorting algorithm which is based on time.

Let's say we have an array with three numbers: 200, 100 and 300.

const unsorted = [200, 100, 300]

First, a new, empty array is created.

const sorted = []

Second, the array with the unsorted numbers gets iterated over and a new timeout is created with the number of the current number as its timeout value.

for (const value of unsorted) {
  setTimeout(() => {
    sorted.push(value)
  }, value)
}

The lowest number gets put into the sorted array first, after that the second-lowest number and so on and on till the sorted array is filled with all numbers in the correct order.

global cache on the edge

If the option useGlobalEdgeCache is set to true (which is default), a global cache on the edge will be used to increase the performance of this algorithm.

After the unsort method is called, a request will be made to a supabase edge function which then checks its database, if the unsorted array is already sorted in the database. If this is the case, the sorted value from the database will be returned instead of sorting the whole array again.

If the array couldn't be found in the database, it will be sorted in the edge function and saved to the cache database to be available for future sorting requests.

If, for whatever reason, the request to the global cache on the edge fails, the array will be sorted locally, without saving it anywhere to a cache.

performance

The performance depends mostly on the highest number of the array which will be sorted. If you want to sort the following array: [1, 2, 3000] the sorting will take approximately 3000ms, except it was found in the global cache on the edge. Then it would take approximately 500ms.

drawbacks

Because of the spec of setTimeout, values beneath 4 will, at least sometimes, not be correctly sorted. Node.js 18 will do its best to handle these cases, but it will fail sometimes.

requirements

This library requires Node.js Version >= 18.0.0

usage

Don't. But if you really want, here you go.

basic

  1. Install it with pnpm: pnpm i unsort
  2. Import it import { unsort } from 'unsort'
  3. Profit.
const sorted = await unsort([300, 100, 200]) // results in [100, 200, 300] - hopefully

options

set global options

import { updateGlobalUnsortConfiguration } from 'unsort'

updateGlobalUnsortConfiguration({
  useGlobalEdgeCache: false
})

set options for single call

const sorted = await unsort([300, 100, 200], {
  useGlobalEdgeCache: false
})
You might also like...

There can be more than Notion and Miro. Affine is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

There can be more than Notion and Miro. Affine is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

AFFiNE.PRO The Next-Gen Knowledge Base to Replace Notion & Miro. Planning, Sorting and Creating all Together. Open-source, Privacy-First, and Free to

Jan 9, 2023

A table component for your Mantine data-rich applications, supporting asynchronous data loading, column sorting, custom cell data rendering, row context menus, dark theme, and more.

A table component for your Mantine data-rich applications, supporting asynchronous data loading, column sorting, custom cell data rendering, row context menus, dark theme, and more.

Mantine DataTable A "dark-theme aware" table component for your Mantine UI data-rich applications, featuring asynchronous data loading support, pagina

Jan 4, 2023

A jQuery-free general purpose library for building credit card forms, validating inputs and formatting numbers.

A jQuery-free general purpose library for building credit card forms, validating inputs and formatting numbers.

Dec 30, 2022

front.phone is a Javascript library that identifies, validates and formats phone numbers.

front.phone front.phone is a Javascript library that identifies, validates and formats phone numbers. Demo The main goal of this project is to create

Oct 27, 2022

Sorting Arrays as simple as it gets.

Sort Sorting Arrays as simple as it gets. This module is published at: https://deno.land/x/sort. Simple Usage Example import { SortService, Direction

May 12, 2022

Trying to re-create sorting alghorithms with js.

The initial idea was to re-create sorting mechanisms from scratch using low time complexity sort algorithms. Bubble, Radix and Lexographical was the

Dec 19, 2021

Path-finding & Sorting algorithms Visualizer

Update - Changelog 📋 09.05.2022 AlgoVision is now fully mobile-responsive for all its features ! On mobile, the 'Mouse Chase' option in Dynamic Mode

Dec 18, 2022

jQuery plugin to sorting lists also the tree structures.

jquery-sortable-lists jQuery plugin to sorting lists also the tree structures. $('#myList').sortableLists( options ); You can sort an items of html li

Dec 13, 2022

Implementing various sorting algorithms in Typescript's type system

Implementing various sorting algorithms in Typescript's type system

Sorta Cool I was on a 10 hour flight with no WiFi, and, bored out of my mind, I thought it would be fun to implement some sorting algorithms in the Ty

Nov 10, 2022
Comments
  • Browser support

    Browser support

    Support using unsort in the browser. Have a look on how to use supabase edge functions with cors: https://github.com/supabase/supabase/blob/master/examples/edge-functions/supabase/functions/browser-with-cors/index.ts

    enhancement 
    opened by jwanner83 1
  • Improve cache hit rate

    Improve cache hit rate

    Instead of matching only exact matches:

    cached: [2,1,3] = [1,2,3]
    
    input: [2,1,3] // <- hit
    input: [3,2,1] // <- no hit, even though the sorted array would look the same
    

    we could match all inputs which contain all numbers of an already cached entry:

    cached: [2,1,3] = [1,2,3]
    
    input: [2,1,3] // <- hit
    input: [3,2,1] // <- hit
    

    this would improve the cache hit rate by a lot and would prevent the database to be flooded by entries with the same result.

    enhancement 
    opened by jwanner83 0
Releases(1.0.0-rc3)
Owner
Jonas Wanner
Software Developer - I truly admire deno and Rollup.
Jonas Wanner
Sorting visualizer to introduce students to different sorting algorithms, how they work, and how to apply them

sorting-visualizer Sorting visualizer to introduce students to different sorting algorithms, how they work, and how to apply them Iteration 1 Demo: ht

Aditya Malik 1 Nov 14, 2022
Lightweight (< 2.3kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode characters, numbers, dates, etc.

fast-natural-order-by Lightweight (< 2.3kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode charac

Shelf 5 Nov 14, 2022
Full stack app to journal and keep track of your overall mood each day of the year, inspired by GitHub's contribution graph.

Mood Tracker Mood tracker to journal and keep track of your overall mood each day of the year. How It's Made: Tech used: EJS, CSS, JavaScript, Node.js

Bianca Togonon 44 Dec 14, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
JavaScript client-side HTML table sorting library with no dependencies required.

TABLE-SORT-JS. Description: A JavaScript client-side HTML table sorting library with no dependencies required. Demo Documentation. (work in progress)

Lee Wannacott 32 Dec 14, 2022
Solid.js library adding a services layer for global shared state.

Solid Services Services are "global" objects useful for features that require shared state or persistent connections. Example uses of services might i

Maciej Kwaśniak 55 Dec 30, 2022
This experimental library patches the global custom elements registry to allow re-defining or reload a custom element.

Redefine Custom Elements This experimental library patches the global custom elements registry to allow re-defining a custom element. Based on the spe

Caridy Patiño 21 Dec 11, 2022