acadea / lexorank

A pure Javascript simple implementation of LexoRank

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lexorank

A simple implementation of LexoRank

LexoRank is a ranking system introduced by Atlassian JIRA.

Background

What is the best representation of an ordered list in a database? With a dumb order number based ranking system, re-ordering a row of a list may require updating all rows of the list in a transaction, which is O(n).

LexoRank makes it O(1). All you need to do is updating the re-ordered row's order field.

Installation

Copy Lexorank.js to your project :)

Usage

import {Lexorank} from "./Lexorank";

const lexorank = new Lexorank();

// eg. currently we have 2 items with the following rank:
// item1Rank = "a"
// item2Rank = "b"

// if we want to insert a new item between item1 and item2
// ok is a boolean, whether the operation has successfully completed
let [rank, ok] = lexorank.insert(item1Rank, item2Rank)

About

A pure Javascript simple implementation of LexoRank

License:MIT License


Languages

Language:JavaScript 57.9%Language:TypeScript 42.1%