BrianHung / fractional-indexing

Fractional Indexing in JavaScript

Home Page:https://npmjs.com/fractional-indexing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fractional Indexing

This is based on Implementing Fractional Indexing by David Greenspan .

Fractional indexing is a technique to create an ordering that can be used for Realtime Editing of Ordered Sequences.

This implementation includes variable-length integers, and the prepend/append optimization described in David's article.

Usage

import { generateKeyBetween } from 'fractional-indexing';

const first = generateKeyBetween(null, null); // "a0"

// Insert after 1st
const second = generateKeyBetween(first, null); // "a1"

// Insert after 2nd
const third = generateKeyBetween(second, null); // "a2"

// Insert before 1st
const zeroth = generateKeyBetween(null, first); // "Zz"

// Insert in between 2nd and 3rd. Midpoint
const secondAndHalf = generateKeyBetween(second, third); // "a1V"

Other Languages

These should be byte-for-byte compatible.

Language Repo
Go https://github.com/rocicorp/fracdex
Python https://github.com/httpie/fractional-indexing-python

About

Fractional Indexing in JavaScript

https://npmjs.com/fractional-indexing

License:Creative Commons Zero v1.0 Universal


Languages

Language:JavaScript 100.0%