Skip to main content

Provides functions for generating ordering strings

Project description

Fractional Indexing

This is a Python port of the original JavaScript implementation by @rocicorp: https://github.com/rocicorp/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.

This should be byte-for-byte compatible with rocicorp/fractional-indexing (JavaScript) and rocicorp/fracdex (Go).

Installation

$ pip install fractional-indexing

Usage

from fractional_indexing import generate_key_between


first = generate_key_between(None, None)
assert first == 'a0'

# Insert after 1st
second = generate_key_between(first, None)
assert second == 'a1'

# Insert after 2nd
third = generate_key_between(second, None)
assert third == 'a2'

# Insert before 1st
zeroth = generate_key_between(None, first)
assert zeroth == 'Zz'

# Insert in between 2nd and 3rd. Midpoint
second_and_half = generate_key_between(second, third)
assert second_and_half == 'a1V'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fractional-indexing-0.1.1.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distribution

fractional_indexing-0.1.1-py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page